From f2c8062f2082bd1875754377c8b39940849e3b0c Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 11 Apr 2025 14:00:47 +0200 Subject: [PATCH 1/4] Add a workflow to run auto updates for pre-commit This replaces the pre-commit.ci app's autoupdate. The one caveat with this is that it doesn't check for PRs that are already opened on that branch. I did that to keep it as simple as possible. It's not a real issue as github will detect that and close the previous PR and then open a new one but it might be a bit spammy if we don't merge those PRs --- .github/workflows/pre-commit-autoupdate.yml | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/pre-commit-autoupdate.yml diff --git a/.github/workflows/pre-commit-autoupdate.yml b/.github/workflows/pre-commit-autoupdate.yml new file mode 100644 index 000000000..d3395b588 --- /dev/null +++ b/.github/workflows/pre-commit-autoupdate.yml @@ -0,0 +1,36 @@ +name: Autoupdate +on: + schedule: + - cron: '0 0 1 * *' +jobs: + pre-commit: + name: Pre-commit + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + - name: Setup git + run: | + git config --global user.name "Pre-commit automation" + git config --global user.email "releng+pre-commit-autoupdate@mozilla.com" + - uses: actions/setup-python@v5 + - run: python -m pip install pre-commit + shell: bash + - name: Update files + run: | + git checkout -B pre-commit-update + pre-commit autoupdate -j4 + git add .pre-commit-config.yaml + git commit -am "Update pre-commit" + git push -f origin pre-commit-update + - name: Create PR if necessary + run: | + curl -sL \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos${{ github.reository_owner }}/${{ github.repository }}/pulls \ + -d '{"title":"Update pre-commit","body":"","head":"pre-commit-update","base":"${{ github.event.repository.default_branch }}"}' From 4636b8539c7b9d8eef9670b1bece1a806ba3e0e7 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 11 Apr 2025 15:29:27 +0200 Subject: [PATCH 2/4] Use `autofix_commit_msg` and remove now useless fields --- .github/workflows/pre-commit-autoupdate.yml | 2 +- .pre-commit-config.yaml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pre-commit-autoupdate.yml b/.github/workflows/pre-commit-autoupdate.yml index d3395b588..3e7ecc478 100644 --- a/.github/workflows/pre-commit-autoupdate.yml +++ b/.github/workflows/pre-commit-autoupdate.yml @@ -23,7 +23,7 @@ jobs: git checkout -B pre-commit-update pre-commit autoupdate -j4 git add .pre-commit-config.yaml - git commit -am "Update pre-commit" + git commit -m "$(cat .pre-commit-config.yaml | yq -r '.ci.autoupdate_commit_msg // "Update pre-commit config"')" git push -f origin pre-commit-update - name: Create PR if necessary run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 31480c104..a5de02b69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,9 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks --- ci: - autofix_commit_msg: "style: pre-commit.ci auto fixes [...]" autoupdate_commit_msg: "chore: pre-commit autoupdate" - autoupdate_schedule: monthly repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 From fc3bcbda3c14c58170820c48ece08ccb952075b9 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 11 Apr 2025 15:42:03 +0200 Subject: [PATCH 3/4] Use the commit msg as the PR title too --- .github/workflows/pre-commit-autoupdate.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit-autoupdate.yml b/.github/workflows/pre-commit-autoupdate.yml index 3e7ecc478..93e993345 100644 --- a/.github/workflows/pre-commit-autoupdate.yml +++ b/.github/workflows/pre-commit-autoupdate.yml @@ -18,12 +18,15 @@ jobs: - uses: actions/setup-python@v5 - run: python -m pip install pre-commit shell: bash + - name: Get commit message + run: | + echo "COMMIT_MSG=$(cat .pre-commit-config.yaml | yq -r '.ci.autoupdate_commit_msg // "Update pre-commit config"')" >> $GITHUB_ENV - name: Update files run: | git checkout -B pre-commit-update pre-commit autoupdate -j4 git add .pre-commit-config.yaml - git commit -m "$(cat .pre-commit-config.yaml | yq -r '.ci.autoupdate_commit_msg // "Update pre-commit config"')" + git commit -m "${COMMIT_MSG}" git push -f origin pre-commit-update - name: Create PR if necessary run: | @@ -33,4 +36,4 @@ jobs: -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos${{ github.reository_owner }}/${{ github.repository }}/pulls \ - -d '{"title":"Update pre-commit","body":"","head":"pre-commit-update","base":"${{ github.event.repository.default_branch }}"}' + -d "{\"title\":\"${COMMIT_MSG}\",\"body\":\"\",\"head\":\"pre-commit-update\",\"base\":\"${{ github.event.repository.default_branch }}\"}" From 98ee84ac6e960a23e55d986133ce4da2f44153fc Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Wed, 16 Apr 2025 15:05:31 +0200 Subject: [PATCH 4/4] Switch to our releng/actions repo --- .github/workflows/pre-commit-autoupdate.yml | 32 +++------------------ 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/.github/workflows/pre-commit-autoupdate.yml b/.github/workflows/pre-commit-autoupdate.yml index 93e993345..c7eaa262c 100644 --- a/.github/workflows/pre-commit-autoupdate.yml +++ b/.github/workflows/pre-commit-autoupdate.yml @@ -1,4 +1,4 @@ -name: Autoupdate +name: Auto update pre-commit hooks every month on: schedule: - cron: '0 0 1 * *' @@ -10,30 +10,6 @@ jobs: contents: write pull-requests: write steps: - - uses: actions/checkout@v4 - - name: Setup git - run: | - git config --global user.name "Pre-commit automation" - git config --global user.email "releng+pre-commit-autoupdate@mozilla.com" - - uses: actions/setup-python@v5 - - run: python -m pip install pre-commit - shell: bash - - name: Get commit message - run: | - echo "COMMIT_MSG=$(cat .pre-commit-config.yaml | yq -r '.ci.autoupdate_commit_msg // "Update pre-commit config"')" >> $GITHUB_ENV - - name: Update files - run: | - git checkout -B pre-commit-update - pre-commit autoupdate -j4 - git add .pre-commit-config.yaml - git commit -m "${COMMIT_MSG}" - git push -f origin pre-commit-update - - name: Create PR if necessary - run: | - curl -sL \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos${{ github.reository_owner }}/${{ github.repository }}/pulls \ - -d "{\"title\":\"${COMMIT_MSG}\",\"body\":\"\",\"head\":\"pre-commit-update\",\"base\":\"${{ github.event.repository.default_branch }}\"}" + - uses: mozilla-releng/actions/pre-commit-autoupdate@main + with: + token: ${{ secrets.GITHUB_TOKEN }}