PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

[FIXED] How to compare a file changes since last action in github actions

 October 09, 2022     continuous-integration, github, github-actions     No comments   

Issue

In gitlab we have support for CI_COMMIT_BEFORE_SHA and CI_COMMIT_SHA

Whereas in github we only have support for GITHUB_REF which holds SHA of current commit that triggered this action.

My requirement is to find if a particular file changed since last Action execution


Solution

Found a way to solve this using event payload - see push event payload:

in .github/workflows/release.yaml

name: release
on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: deploy
      run: sh deploy.sh
      env:
        CI_COMMIT_BEFORE_SHA: ${{ github.event.before }}
        CI_COMMIT_SHA: ${{ github.event.after }}

in bin/deploy.sh

HAS_DESIRED_CHANGES=`git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep -E 'path/to/file1|path/to/dir2'`
echo $HAS_DESIRED_CHANGES
HAS_DESIRED_CHANGES=`echo ${#HAS_DESIRED_CHANGES}`

if ! [ $HAS_DESIRED_CHANGES -eq 0 ]
then
  echo "Has desired changes, proceed performing necessary actions"
else
  echo "No desired changes. Skipping...."
fi


Answered By - Rohit Reddy Abbadi
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing