Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get latest file SHA given filename of changed files in push

Hello I’m a little confused if it is possible via Github Actions to get the latest SHA of a file with only its file’s name.

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
          
      - name: Get specific changed files
        id: changed-files-specific
        uses: tj-actions/changed-files@v15.1
        with:
          files: |
            *.groovy
          files_ignore: |
            *.yml
            
        # Runs a set of commands using the runners shell
      - name: echo changed files
        run: |
          echo modified files ---
          echo ${{steps.changed-files-specific.outputs.modified_files}}

As you can see with the combination of action changed-files-specific and echo changed files I am able to get the filename. I looked at the documentation of the tj-actions/changed-files library and it does not provide file info support.

Is there an easy way to do this? I tried searching for another action library but it does not seem to be a very common use case.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Many Thanks,
Morgan Morningstar

>Solution :

You are on the right track.

Now when you have all the modified files and their paths – you can just easily do whatever you want with those files.

You can iterate over those files and calculate SHA for each of them using those paths.

Something like this:

for file in ${{ steps. changed-files-specific.outputs.modified_files }}; do
    sha=`sha1sum $file | cut -d ' ' -f 1`
    echo "sha for $file: $sha"
done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading