From 04069dfbc12f0f4c16d6c06928990d9483a22955 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Thu, 6 Jun 2024 14:45:35 -0400 Subject: [PATCH] update peter-evans/create-pull-request to v6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additional changes: * add clear ABORT message when there are no diffs * add check of force_run input that runs extract and PR gen even if there are no changes * add date-time stamp to PR title to make scanning PRs easier in the UI _NOTE: If extract and PR gen run when there are no changes, a PR will not be created as there are no changes between the action’s branch and the main branch even when force_run is true._ --- .github/workflows/fetch-licenses.yaml | 29 ++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/fetch-licenses.yaml b/.github/workflows/fetch-licenses.yaml index e67cde1..3dfe62b 100644 --- a/.github/workflows/fetch-licenses.yaml +++ b/.github/workflows/fetch-licenses.yaml @@ -20,7 +20,7 @@ jobs: git config --global user.name "GitHub Actions" git config --global user.email "github-actions[bot]@users.noreply.github.com" - - name: Checkout this repository's auto-update-licenses branch + - name: Checkout this repository uses: actions/checkout@v4 - name: Checkout official SPDX Repository @@ -34,11 +34,29 @@ jobs: cp official-spdx-licenses/json/licenses.json cmd/licenses.json cp official-spdx-licenses/json/exceptions.json cmd/exceptions.json + - name: Get date + id: date + run: echo "DT_STAMP"=$(date +'%Y-%m-%d %H:%M UTC') >> $GITHUB_ENV + - name: Check for changes + id: changes run: | - git diff --exit-code -- cmd/licenses.json cmd/exceptions.json || exit 0 + has_changes=true + # --quiet: Exits with 1 if there are changes; otherwise, exits with 0 + # exiting with anything other than 0 implies the command failed and the command following && will not execute leaving has_changes set to true + # exiting with 0 implies the command was successful and the command following && will be executed setting has_changes to false + git diff --quiet -- cmd/licenses.json cmd/exceptions.json && has_changes=false + if [ $has_changes != 'true' ]; then + if [ ${{ github.event.inputs.force_run }} == 'true' ]; then + echo -e '***************\nNo changes, but skipping abort due to force run\n***************' + else + echo -e '***************\nABORTING: No changes to license data\n***************' + fi + fi + echo "HAS_CHANGES"=$has_changes >> $GITHUB_ENV - name: Run license extraction + if: ${{ env.HAS_CHANGES == 'true' || github.event.inputs.force_run == 'true' }} run: | cd cmd echo "Current branch: $(git branch)" @@ -47,12 +65,13 @@ jobs: git log --oneline -n 5 - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 + if: ${{ env.HAS_CHANGES == 'true' || github.event.inputs.force_run == 'true' }} + uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.GITHUB_TOKEN }} commit-message: Add updated license files branch: auto-update-licenses base: main - title: "Update SPDX license files" - 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." + title: "Update SPDX license files (${{ env.DT_STAMP }})" + 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." labels: 'auto-update,licenses'