From 8a5b37bc289ca2cd10ce57d0c1f016e630e3567f Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 11 Feb 2024 16:31:27 +0100 Subject: [PATCH 01/16] feat: add CI to detect references --- .github/workflows/check-reference.yml | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/check-reference.yml diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml new file mode 100644 index 00000000..b51eaa42 --- /dev/null +++ b/.github/workflows/check-reference.yml @@ -0,0 +1,34 @@ +name: Check patch references + +on: + push: + branches-ignore: + - dependabot/** + schedule: + # Once every day at midnight UTC + - cron: "0 0 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - name: Checkout patches + uses: actions/checkout@v4 + + - name: Checkout core + uses: actions/checkout@v4 + with: + repository: 'homebrew/homebrew-core' + path: homebrew-core + + - name: Detect references + run: | + patches=$(find -name "*.patch" -printf "%f\n") + status=0 + for patch in $patches; do + if ! git -C "homebrew-core" grep -r "${patch/./}" > /dev/null; then + echo "$patch not needed!" + status=1 + fi + done + exit $status From b642b461a62eba3ad7dc679270f37989433be205 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 11 Feb 2024 17:21:13 +0000 Subject: [PATCH 02/16] Better detection of patches - they don't all end in `.patch` - Check for which patches are in use in `homebrew-core`, trimming the quotes and only getting the last part of the path. - Get all the patches in this repository. - Compare the two and print out the missing ones in the `homebrew-core` repository. - Add a TODO for deleting the unused patches, it might be nice for this workflow to do that once we know it's legit. --- .github/workflows/check-reference.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index b51eaa42..ce7c6841 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -23,11 +23,16 @@ jobs: - name: Detect references run: | - patches=$(find -name "*.patch" -printf "%f\n") + #!/bin/bash + + core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $NF}' | tr -d '"') + all_patches=$(git ls-files | grep -v "LICENSE" | grep -v "README.md" | grep -v ".github/workflows/triage-issues.yml" | grep -v ".github/workflows/check-reference.yml") status=0 - for patch in $patches; do - if ! git -C "homebrew-core" grep -r "${patch/./}" > /dev/null; then - echo "$patch not needed!" + + for patch in $all_patches; do + if ! grep -q "$core_patches" <<< "$patch"; then + echo "Unused patch: $patch." + # TODO: Delete the patch and commit the deletion. status=1 fi done From 7ad1610060694356a2053a03afcbd52a9a6158b8 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 11 Feb 2024 18:16:31 +0000 Subject: [PATCH 03/16] Ignore all top-level files and all of `.github/` Co-authored-by: Bo Anderson --- .github/workflows/check-reference.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index ce7c6841..6b371fb9 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -26,7 +26,7 @@ jobs: #!/bin/bash core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $NF}' | tr -d '"') - all_patches=$(git ls-files | grep -v "LICENSE" | grep -v "README.md" | grep -v ".github/workflows/triage-issues.yml" | grep -v ".github/workflows/check-reference.yml") + all_patches=$(git ls-files -- '*/*' ':^.*/*') status=0 for patch in $all_patches; do From a7639afa5dc9e59e780a40b83815b6ba361c2dcb Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 11 Feb 2024 18:16:51 +0000 Subject: [PATCH 04/16] Better matching Co-authored-by: Bo Anderson --- .github/workflows/check-reference.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 6b371fb9..4c54deab 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -25,12 +25,12 @@ jobs: run: | #!/bin/bash - core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $NF}' | tr -d '"') + core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $(NF-1)"/"$NF}' | tr -d '"') all_patches=$(git ls-files -- '*/*' ':^.*/*') status=0 for patch in $all_patches; do - if ! grep -q "$core_patches" <<< "$patch"; then + if ! grep -qx "$core_patches" <<< "$patch"; then echo "Unused patch: $patch." # TODO: Delete the patch and commit the deletion. status=1 From fb4662f38fbb5d4db46cd771b9155937457a5801 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 11 Feb 2024 18:20:36 +0000 Subject: [PATCH 05/16] Delete the unused patches and push the commits to a branch - Let's see how this goes. --- .github/workflows/check-reference.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 4c54deab..5710ba5f 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -27,13 +27,15 @@ jobs: core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $(NF-1)"/"$NF}' | tr -d '"') all_patches=$(git ls-files -- '*/*' ':^.*/*') - status=0 + + git checkout -b remove-unused-patches for patch in $all_patches; do if ! grep -qx "$core_patches" <<< "$patch"; then - echo "Unused patch: $patch." - # TODO: Delete the patch and commit the deletion. - status=1 + echo "Unused patch: $patch; deleting." + git rm "$patch" + git commit -m "Remove unused patch: $patch" fi done - exit $status + + git push origin remove-unused-patches From 68a6fb0d85601869ce8b9e1f27c29c7c0d6bacbb Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 11 Feb 2024 18:50:12 +0000 Subject: [PATCH 06/16] Configure Git to push as `BrewTestBot` --- .github/workflows/check-reference.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 5710ba5f..dd2aea48 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -21,6 +21,11 @@ jobs: repository: 'homebrew/homebrew-core' path: homebrew-core + - name: Configure Git user + uses: Homebrew/actions/git-user-config@master + with: + username: BrewTestBot + - name: Detect references run: | #!/bin/bash From cb2074571fa35fe88bf979fb4cd6c8bc7bb36334 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 12 Feb 2024 08:51:00 +0100 Subject: [PATCH 07/16] Update check-reference.yml Co-authored-by: Bo Anderson --- .github/workflows/check-reference.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index dd2aea48..8f6cbe89 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -28,8 +28,6 @@ jobs: - name: Detect references run: | - #!/bin/bash - core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $(NF-1)"/"$NF}' | tr -d '"') all_patches=$(git ls-files -- '*/*' ':^.*/*') From e45ec2a9a60b03932295ba1b02a69e1080957361 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 12 Feb 2024 08:51:19 +0100 Subject: [PATCH 08/16] Update check-reference.yml Co-authored-by: Bo Anderson --- .github/workflows/check-reference.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 8f6cbe89..fead78ac 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -37,7 +37,7 @@ jobs: if ! grep -qx "$core_patches" <<< "$patch"; then echo "Unused patch: $patch; deleting." git rm "$patch" - git commit -m "Remove unused patch: $patch" + git commit -m "${patch%%/*}: remove unused ${patch#*/}" fi done From 42a9238fb8fd345eefc341dd6c085a5f2b359858 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 12 Feb 2024 08:52:25 +0100 Subject: [PATCH 09/16] Update check-reference.yml --- .github/workflows/check-reference.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index fead78ac..1d384eae 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -9,7 +9,7 @@ on: - cron: "0 0 * * *" jobs: - stale: + cleanup: runs-on: ubuntu-latest steps: - name: Checkout patches From ba0ee3b2f7c089d7fda455215ed811c2a5c3ebbe Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 12 Feb 2024 10:47:40 +0100 Subject: [PATCH 10/16] fix: declare write permission --- .github/workflows/check-reference.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 1d384eae..e2fb1311 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -8,6 +8,9 @@ on: # Once every day at midnight UTC - cron: "0 0 * * *" +permissions: + contents: write + jobs: cleanup: runs-on: ubuntu-latest From 18ffc54c0a678ad6bc2d28699361bd1015622566 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 4 Mar 2024 03:18:09 +0100 Subject: [PATCH 11/16] Update check-reference.yml --- .github/workflows/check-reference.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index e2fb1311..303c4ca4 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -30,6 +30,7 @@ jobs: username: BrewTestBot - name: Detect references + shell: bash run: | core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $(NF-1)"/"$NF}' | tr -d '"') all_patches=$(git ls-files -- '*/*' ':^.*/*') From 30521bd7e363230ebbdc74d8fdf27db606f77554 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 12 Mar 2024 09:25:47 +0100 Subject: [PATCH 12/16] Update check-reference.yml --- .github/workflows/check-reference.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 303c4ca4..80f3c672 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -10,6 +10,7 @@ on: permissions: contents: write + pull-requests: write jobs: cleanup: @@ -46,3 +47,4 @@ jobs: done git push origin remove-unused-patches + gh pr create --fill --title "Remove unused patches" From 97331712bc496b34f096e8d6fa698a56caeabc65 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 12 Mar 2024 09:27:56 +0100 Subject: [PATCH 13/16] fix: add token --- .github/workflows/check-reference.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 80f3c672..d9320598 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -31,6 +31,8 @@ jobs: username: BrewTestBot - name: Detect references + env: + GH_TOKEN: ${{ github.token }} shell: bash run: | core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $(NF-1)"/"$NF}' | tr -d '"') From 8a22f79e470be728ea19fcb4e09c84929f592963 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 12 Mar 2024 09:36:11 +0100 Subject: [PATCH 14/16] fix: fill PR body --- .github/workflows/check-reference.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index d9320598..4a59845d 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -49,4 +49,4 @@ jobs: done git push origin remove-unused-patches - gh pr create --fill --title "Remove unused patches" + gh pr create --title "Remove unused patches" --body "$(git log --oneline FETCH_HEAD..remove-unused-patches)" From 86431e7894cfd74a8cb3c772e68b2bbf961d591a Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 12 Mar 2024 09:40:15 +0100 Subject: [PATCH 15/16] fix: define upstream branch --- .github/workflows/check-reference.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index 4a59845d..e35e1aa4 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -18,6 +18,8 @@ jobs: steps: - name: Checkout patches uses: actions/checkout@v4 + with: + ref: master - name: Checkout core uses: actions/checkout@v4 @@ -49,4 +51,4 @@ jobs: done git push origin remove-unused-patches - gh pr create --title "Remove unused patches" --body "$(git log --oneline FETCH_HEAD..remove-unused-patches)" + gh pr create --title "Remove unused patches" --body "$(git log --oneline master..remove-unused-patches)" From 679fac6fab58cf2fd880cb4b6ced51890fbb09de Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 12 Mar 2024 14:14:15 +0100 Subject: [PATCH 16/16] feat: add commit signing --- .github/workflows/check-reference.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/check-reference.yml b/.github/workflows/check-reference.yml index e35e1aa4..39d42f00 100644 --- a/.github/workflows/check-reference.yml +++ b/.github/workflows/check-reference.yml @@ -32,9 +32,15 @@ jobs: with: username: BrewTestBot + - name: Set up commit signing + uses: Homebrew/actions/setup-commit-signing@master + with: + signing_key: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY }} + - name: Detect references env: GH_TOKEN: ${{ github.token }} + HOMEBREW_GPG_PASSPHRASE: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY_PASSPHRASE }} shell: bash run: | core_patches=$(git -C homebrew-core grep -h "Homebrew/formula-patches" | awk -F/ '{print $(NF-1)"/"$NF}' | tr -d '"')