From 2a7332ce07493c858a5ccd377491f3c4ac6e0d48 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 17 Apr 2024 09:17:08 -0300 Subject: [PATCH 1/3] ci(pre-commit): Enforce that the pre-commit checks are run before merge --- .github/workflows/pre-commit.yml | 41 +++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 08ae9a0c67c..8882c7b70bd 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -2,7 +2,10 @@ name: Pre-commit check on: pull_request: - types: [opened, reopened, synchronize, labeled] + types: [opened, reopened, synchronize, labeled, unlabeled] + +permissions: + statuses: write jobs: lint: @@ -60,3 +63,39 @@ jobs: if: always() with: msg: "ci(pre-commit): Apply automatic fixes" + + report-run: + name: Check if the PR has run the pre-commit checks + needs: lint + if: always() + runs-on: ubuntu-latest + steps: + - name: Report success + if: | + contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') && + needs.lint.result == 'success' + uses: actions/github-script@v7 + with: + script: | + github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: ${{ github.event.pull_request.head.sha }}, + state: 'success', + context: 'pre-commit-result', + description: 'All pre-commit checks passed', + }); + + - name: Report pending + env: + GH_TOKEN: ${{ github.token }} + if: | + !contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') || + needs.lint.result == 'failure' + run: | + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ github.repository }}/statuses/${{ github.sha }} \ + -f state=pending -f context=pre-commit-result -f description="Pre-commit checks need to pass before merging" From af6ef15c08ba57339028cc0887ab58b042e82534 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:09:30 -0300 Subject: [PATCH 2/3] Test --- .github/workflows/pre-commit.yml | 35 +++++++++++--------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 8882c7b70bd..b2e56010454 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,12 +1,9 @@ name: Pre-commit check on: - pull_request: + pull_request_target: types: [opened, reopened, synchronize, labeled, unlabeled] -permissions: - statuses: write - jobs: lint: if: | @@ -66,6 +63,8 @@ jobs: report-run: name: Check if the PR has run the pre-commit checks + permissions: + statuses: write needs: lint if: always() runs-on: ubuntu-latest @@ -74,28 +73,18 @@ jobs: if: | contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') && needs.lint.result == 'success' - uses: actions/github-script@v7 + uses: conda/actions/set-commit-status with: - script: | - github.rest.repos.createCommitStatus({ - owner: context.repo.owner, - repo: context.repo.repo, - sha: ${{ github.event.pull_request.head.sha }}, - state: 'success', - context: 'pre-commit-result', - description: 'All pre-commit checks passed', - }); + context: pre-commit-result + state: success + description: All pre-commit checks passed - name: Report pending - env: - GH_TOKEN: ${{ github.token }} if: | !contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') || needs.lint.result == 'failure' - run: | - gh api \ - --method POST \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ github.repository }}/statuses/${{ github.sha }} \ - -f state=pending -f context=pre-commit-result -f description="Pre-commit checks need to pass before merging" + uses: conda/actions/set-commit-status + with: + context: pre-commit-result + state: pending + description: The pre-commit checks need to be successful before merging From a5576abdce957e4d796f95a3dcbb03ab601a8377 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:12:13 -0300 Subject: [PATCH 3/3] Fix --- .github/workflows/pre-commit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index b2e56010454..7c9d9b6679f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -73,7 +73,7 @@ jobs: if: | contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') && needs.lint.result == 'success' - uses: conda/actions/set-commit-status + uses: conda/actions/set-commit-status@v24.2.0 with: context: pre-commit-result state: success @@ -83,7 +83,7 @@ jobs: if: | !contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') || needs.lint.result == 'failure' - uses: conda/actions/set-commit-status + uses: conda/actions/set-commit-status@v24.2.0 with: context: pre-commit-result state: pending