Skip to content

Commit fd9f68f

Browse files
committed
update Fetch Licenses workflow to only create a PR if the generated files changed
Also adding the ability to force tests to run. They get stuck sometimes in PRs. This avoids the need to do a minor change like adding whitespace to a file just to get the tests to run.
1 parent 59ab544 commit fd9f68f

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

.github/workflows/fetch-licenses.yaml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,51 @@ jobs:
4141
id: date
4242
run: echo "DT_STAMP"=$(date +'%Y-%m-%d %H:%M UTC') >> $GITHUB_ENV
4343

44-
- name: Check for changes
45-
id: changes
44+
- name: Check for changes in SPDX json files
45+
id: src-changes
4646
run: |
47-
has_changes=true
47+
src_changed=true
4848
# --quiet: Exits with 1 if there are changes; otherwise, exits with 0
49-
# exiting with anything other than 0 implies the command failed and the command following && will not execute leaving has_changes set to true
50-
# exiting with 0 implies the command was successful and the command following && will be executed setting has_changes to false
51-
git diff --quiet -- cmd/licenses.json cmd/exceptions.json && has_changes=false
52-
if [ $has_changes != 'true' ]; then
49+
git diff --quiet -- cmd/licenses.json cmd/exceptions.json && src_changed=false
50+
if [ $src_changed != 'true' ]; then
5351
if [ ${{ github.event.inputs.force_run }} == 'true' ]; then
54-
echo -e '***************\nNo changes, but skipping abort due to force run\n***************'
52+
echo -e '***************\nNo changes in spdx json, but skipping abort due to force run\n***************'
5553
else
56-
echo -e '***************\nABORTING: No changes to license data\n***************'
54+
echo -e '***************\nABORTING: No changes to spdx json data\n***************'
55+
exit 0
5756
fi
5857
fi
59-
echo "HAS_CHANGES"=$has_changes >> $GITHUB_ENV
58+
echo "src_changed"=$src_changed >> $GITHUB_ENV
6059
6160
- name: Run license extraction
62-
if: ${{ env.HAS_CHANGES == 'true' || github.event.inputs.force_run == 'true' }}
61+
if: ${{ env.src_changed == 'true' || github.event.inputs.force_run == 'true' }}
6362
run: |
6463
cd cmd
6564
echo "Current branch: $(git branch)"
6665
go run . extract -l -e
6766
cd ..
6867
git log --oneline -n 5
6968
69+
- name: Check for changes in generated files
70+
id: genfiles-changes
71+
run: |
72+
genfiles_changed=true
73+
# --quiet: Exits with 1 if there are changes; otherwise, exits with 0
74+
git diff --quiet -- spdxexp/spdxlicenses/*.go && genfiles_changed=false
75+
if [ $genfiles_changed != 'true' ]; then
76+
if [ ${{ github.event.inputs.force_run }} == 'true' ]; then
77+
echo -e '***************\nNo changes to generated files, but skipping abort due to force run\n***************'
78+
else
79+
# This happens when the generated files are already up to date
80+
# or the only changes in the source json are data not included in the generated files (e.g. IDs)
81+
echo -e '***************\nABORTING: No changes to license data in generated files\n***************'
82+
exit 0
83+
fi
84+
fi
85+
echo "genfiles_changed"=$genfiles_changed >> $GITHUB_ENV
86+
7087
- name: Create Pull Request
71-
if: ${{ env.HAS_CHANGES == 'true' || github.event.inputs.force_run == 'true' }}
88+
if: ${{ env.genfiles_changed == 'true' || github.event.inputs.force_run == 'true' }}
7289
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
7390
with:
7491
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches: [main]
66
pull_request: {}
7+
workflow_dispatch: # Sometimes tests get stuck in PRs; This allows them to be rerun manually
78

89
permissions:
910
contents: read

0 commit comments

Comments
 (0)