I need to read file zip file name in GitHub actions. But in following code, both Artifact and Artifact1 are returning blank values. What is wrong with the code?
name: SCR Initial
on:
push:
branches:
- main
paths:
- 'test/**zip'
jobs:
SCR:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Artifact zip name
run: |
echo "Commit text = ${{ github.event.head_commit.message }}"
echo "Artifact name= ${{ github.event.head_commit.added }}"
echo "Artifact1 name = ${{ github.event.head_commit.added[0] }}"
I have checked in workflow logs and able to see blank.
2
Answers
In a
push
event triggering a github actions workflow, thehead_commit
object payload doesn’t contain thosemessage
andadded
fields.This head_commit object is filled as follow (example from a personal repository):
Here is an example of a full
push
event JSON if you want to check its structure.To access the last push commit message for example, you would need to use
${{ github.event.commits.[0].message }}
${{ github.event.head_commit.added }}
does not exist any more, see this blog post for more information.In addition to what GuiFalourd already said, you can do something like this:
This will list only the files that were added (
=A
) in the latest commit.