From 19f9fecb33c164b1f500dca2023e0c8a4a10ce1c Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Fri, 17 Jul 2020 14:14:12 +0100 Subject: [PATCH 1/2] dev-cmd/update-license-data: fail if not changed rather than on change --- Library/Homebrew/dev-cmd/update-license-data.rb | 6 +++--- docs/Manpage.md | 4 ++-- manpages/brew.1 | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/dev-cmd/update-license-data.rb b/Library/Homebrew/dev-cmd/update-license-data.rb index 952a46ee27..456a7b38ec 100644 --- a/Library/Homebrew/dev-cmd/update-license-data.rb +++ b/Library/Homebrew/dev-cmd/update-license-data.rb @@ -16,8 +16,8 @@ module Homebrew Update SPDX license data in the Homebrew repository. EOS - switch "--fail-if-changed", - description: "Return a failing status code if current license data's version is different from " \ + switch "--fail-if-not-changed", + description: "Return a failing status code if current license data's version is the same as " \ "the upstream. This can be used to notify CI when the SPDX license data is out of date." switch "--commit", description: "Commit changes to the SPDX license data." @@ -33,7 +33,7 @@ module Homebrew data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/licenses.json" curl_download(data_url, to: SPDX_PATH, partial: false) - Homebrew.failed = !system("git", "diff", "--stat", "--exit-code", SPDX_PATH) if args.fail_if_changed? + Homebrew.failed = system("git", "diff", "--stat", "--exit-code", SPDX_PATH) if args.fail_if_not_changed? return unless args.commit? diff --git a/docs/Manpage.md b/docs/Manpage.md index a41eb26a2f..192e877410 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1052,8 +1052,8 @@ directory. Update SPDX license data in the Homebrew repository. -* `--fail-if-changed`: - Return a failing status code if current license data's version is different from the upstream. This can be used to notify CI when the SPDX license data is out of date. +* `--fail-if-not-changed`: + Return a failing status code if current license data's version is the same as the upstream. This can be used to notify CI when the SPDX license data is out of date. * `--commit`: Commit changes to the SPDX license data. diff --git a/manpages/brew.1 b/manpages/brew.1 index 25e5ce2cc4..d0e45e813a 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1361,8 +1361,8 @@ Initialise a Git repository in the unpacked source\. This is useful for creating Update SPDX license data in the Homebrew repository\. . .TP -\fB\-\-fail\-if\-changed\fR -Return a failing status code if current license data\'s version is different from the upstream\. This can be used to notify CI when the SPDX license data is out of date\. +\fB\-\-fail\-if\-not\-changed\fR +Return a failing status code if current license data\'s version is the same as the upstream\. This can be used to notify CI when the SPDX license data is out of date\. . .TP \fB\-\-commit\fR From 4a167d79434f7d4498f6243f3cfbb0faa2b9daba Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Fri, 17 Jul 2020 02:34:23 +0100 Subject: [PATCH 2/2] workflows: auto create PRs for license data updates --- .github/workflows/spdx.yml | 41 +++++++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 5 ----- 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/spdx.yml diff --git a/.github/workflows/spdx.yml b/.github/workflows/spdx.yml new file mode 100644 index 0000000000..c371eb64af --- /dev/null +++ b/.github/workflows/spdx.yml @@ -0,0 +1,41 @@ +name: Update license data + +on: + schedule: + - cron: '* */12 * * *' + +jobs: + spdx: + runs-on: ubuntu-latest + env: + HOMEBREW_NO_ANALYTICS: 1 + HOMEBREW_NO_AUTO_UPDATE: 1 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure Git + uses: Homebrew/actions/git-user-config@master + with: + username: BrewTestBot + + - name: Setup Homebrew + run: | + HOMEBREW_REPOSITORY="$(brew --repo)" + rm -rf "$HOMEBREW_REPOSITORY" + ln -s "$GITHUB_WORKSPACE" "$HOMEBREW_REPOSITORY" + + - name: Update license data + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd "$GITHUB_WORKSPACE/Library/Homebrew" + if brew update-license-data --commit --fail-if-not-changed; then + SPDX_VERSION=$(jq -er .licenseListVersion data/spdx.json) + if ! git ls-remote --exit-code --heads origin "spdx-$SPDX_VERSION"; then + git checkout -b "spdx-$SPDX_VERSION" + git push origin "spdx-$SPDX_VERSION" + hub pull-request -m "$(git log -1 --format='%s')" + fi + fi diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b335d0330f..2ee3d3d130 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -114,11 +114,6 @@ jobs: - name: Run brew man run: brew man --fail-if-changed - - name: Check for outdated license data - run: brew update-license-data --fail-if-changed - env: - HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Run brew tests run: | # brew tests doesn't like world writable directories