Skip to content

Commit 936b224

Browse files
authored
Merge pull request #107 from github/elr/limit-pr-autogen
update Fetch Licenses workflow to only create a PR if the generated files changed
2 parents a0f4b0b + 5003b2a commit 936b224

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-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 }}

0 commit comments

Comments
 (0)