Skip to content

Commit 848f7ad

Browse files
authored
Merge pull request #78 from elrayle/main
update peter-evans/create-pull-request to v6 & general workflow cleanup
2 parents 4b8dcc0 + 04069df commit 848f7ad

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

.github/workflows/fetch-licenses.yaml

+24-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
git config --global user.name "GitHub Actions"
2121
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2222
23-
- name: Checkout this repository's auto-update-licenses branch
23+
- name: Checkout this repository
2424
uses: actions/checkout@v4
2525

2626
- name: Checkout official SPDX Repository
@@ -34,11 +34,29 @@ jobs:
3434
cp official-spdx-licenses/json/licenses.json cmd/licenses.json
3535
cp official-spdx-licenses/json/exceptions.json cmd/exceptions.json
3636
37+
- name: Get date
38+
id: date
39+
run: echo "DT_STAMP"=$(date +'%Y-%m-%d %H:%M UTC') >> $GITHUB_ENV
40+
3741
- name: Check for changes
42+
id: changes
3843
run: |
39-
git diff --exit-code -- cmd/licenses.json cmd/exceptions.json || exit 0
44+
has_changes=true
45+
# --quiet: Exits with 1 if there are changes; otherwise, exits with 0
46+
# exiting with anything other than 0 implies the command failed and the command following && will not execute leaving has_changes set to true
47+
# exiting with 0 implies the command was successful and the command following && will be executed setting has_changes to false
48+
git diff --quiet -- cmd/licenses.json cmd/exceptions.json && has_changes=false
49+
if [ $has_changes != 'true' ]; then
50+
if [ ${{ github.event.inputs.force_run }} == 'true' ]; then
51+
echo -e '***************\nNo changes, but skipping abort due to force run\n***************'
52+
else
53+
echo -e '***************\nABORTING: No changes to license data\n***************'
54+
fi
55+
fi
56+
echo "HAS_CHANGES"=$has_changes >> $GITHUB_ENV
4057
4158
- name: Run license extraction
59+
if: ${{ env.HAS_CHANGES == 'true' || github.event.inputs.force_run == 'true' }}
4260
run: |
4361
cd cmd
4462
echo "Current branch: $(git branch)"
@@ -47,12 +65,13 @@ jobs:
4765
git log --oneline -n 5
4866
4967
- name: Create Pull Request
50-
uses: peter-evans/create-pull-request@v3
68+
if: ${{ env.HAS_CHANGES == 'true' || github.event.inputs.force_run == 'true' }}
69+
uses: peter-evans/create-pull-request@v6
5170
with:
5271
token: ${{ secrets.GITHUB_TOKEN }}
5372
commit-message: Add updated license files
5473
branch: auto-update-licenses
5574
base: main
56-
title: "Update SPDX license files"
57-
body: "The files in this PR are auto-generated by the [fetch-licenses](./.git/workflows/fetch-license.yaml) workflow when it runs the `cmd/extract` script. It updates SPDX licenses based on the latest released set in the [spdx/license-list-data](https://github.com/spdx/license-list-data) repository maintained by [SPDX](https://spdx.org/licenses/). \n\nTODO: [spdxexp/spdxlicenses/license_ranges.go](./spdxexp/spdxlicenses/license_range.go) has to be updated manually."
75+
title: "Update SPDX license files (${{ env.DT_STAMP }})"
76+
body: "The files in this PR are auto-generated by the [fetch-licenses](./.git/workflows/fetch-license.yaml) workflow when it runs the `extract` command defined in [cmd/main.go](./cmd/main.go). It updates SPDX licenses based on the latest released set in the [spdx/license-list-data](https://github.com/spdx/license-list-data) repository maintained by [SPDX](https://spdx.org/licenses/). \n\nTODO: [spdxexp/spdxlicenses/license_ranges.go](./spdxexp/spdxlicenses/license_range.go) has to be updated manually."
5877
labels: 'auto-update,licenses'

0 commit comments

Comments
 (0)