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.
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