skip to Main Content
name: If files in folder_path were changed

on:
  push:

jobs:
  if-file-changed:
    name: Check if files changed
    runs-on: ubuntu-latest
    steps:
      - name: Get files changed on push
        run: |
          echo ${{ github.sha }} - commit sha that triggered this workflow
          echo ${{ github.event.before }} - previous sha
          git --no-pager diff --name-only ${{ github.sha }} ${{ github.event.before }}

I get error – error: Could not access 'oaisjdoiasjdoaijsd12319023'
I am trying to get diff between 2 commit SHA’s

The same command works fine when I run from local machine :

git --no-pager diff --name-only aosdiasodi oaisdoaisjd

2

Answers


  1. Chosen as BEST ANSWER

    order of sha's in question is wrong . correct order is -

    git --no-pager diff --name-only ${{ github.event.before }} ${{ github.sha }}
    

    But this wont work if you force push a commit because in that case the previous commit was overwritten hence rendered invalid.

    Refer to gha-files-changed Github repo that implements this functionality


  2. I think you should clone the repo bifore exec some local git command, so try this:

    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Get files changed on push
        run: |
          echo ${{ github.sha }} - commit sha that triggered this workflow
          echo ${{ github.event.before }} - previous sha
          git --no-pager diff --name-only ${{ github.sha }} ${{ github.event.before }}
    

    See https://github.com/actions/checkout

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search