diff --git a/.github/workflows/pre-commit-status.yml b/.github/workflows/pre-commit-status.yml index bf55e69665d..d0060668476 100644 --- a/.github/workflows/pre-commit-status.yml +++ b/.github/workflows/pre-commit-status.yml @@ -1,41 +1,64 @@ +# This needs to be in a separate workflow because it requires higher permissions than the calling workflow name: Report Pre-commit Check Status on: - pull_request_target: - types: [opened, reopened, synchronize, labeled, unlabeled] + workflow_run: + workflows: [Pre-commit hooks] + types: + - completed permissions: statuses: write jobs: - report-run: - name: Check if the PR has run the pre-commit checks + report-success: + name: Report pre-commit success + if: github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: - - name: Report pending - uses: conda/actions/set-commit-status@v24.2.0 - with: - context: "Pre-commit checks" - state: pending - description: The pre-commit checks need to be successful before merging - - - name: Wait for pre-commit checks to complete - uses: lucasssvaz/wait-on-workflow@v1 - if: | - contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') - id: wait-on-workflow + - name: Report success + uses: actions/github-script@v7 with: - timeout: 10 - interval: 30 - workflow: pre-commit.yml - sha: ${{ github.event.pull_request.head.sha || github.sha }} + script: | + const owner = '${{ github.repository_owner }}'; + const repo = '${{ github.repository }}'.split('/')[1]; + const sha = '${{ github.event.workflow_run.head_sha }}'; + core.debug(`owner: ${owner}`); + core.debug(`repo: ${repo}`); + core.debug(`sha: ${sha}`); + const { context: name, state } = (await github.rest.repos.createCommitStatus({ + context: 'Pre-commit checks', + description: 'Pre-commit checks successful', + owner: owner, + repo: repo, + sha: sha, + state: 'success', + target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}' + })).data; + core.info(`${name} is ${state}`); - - name: Report success - uses: conda/actions/set-commit-status@v24.2.0 - if: | - contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') && - steps.wait-on-workflow.outputs.conclusion == 'success' + report-pending: + name: Report pre-commit pending + if: github.event.workflow_run.conclusion != 'success' + runs-on: ubuntu-latest + steps: + - name: Report pending + uses: actions/github-script@v7 with: - context: "Pre-commit checks" - state: success - description: All pre-commit checks passed + script: | + const owner = '${{ github.repository_owner }}'; + const repo = '${{ github.repository }}'.split('/')[1]; + const sha = '${{ github.event.workflow_run.head_sha }}'; + core.debug(`owner: ${owner}`); + core.debug(`repo: ${repo}`); + core.debug(`sha: ${sha}`); + const { context: name, state } = (await github.rest.repos.createCommitStatus({ + context: 'Pre-commit checks', + description: 'The pre-commit checks need to be successful before merging', + owner: owner, + repo: repo, + sha: sha, + state: 'pending', + target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}' + })).data; + core.info(`${name} is ${state}`); diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index b01545f2619..56393d46202 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,13 +1,22 @@ name: Pre-commit hooks on: + workflow_dispatch: + push: + branches: + - master pull_request: types: [opened, reopened, synchronize, labeled, unlabeled] +concurrency: + group: pre-commit-${{github.event.pull_request.number || github.ref}} + cancel-in-progress: true + jobs: lint: if: | - contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') + contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') || + github.event_name != 'pull_request' name: Check if fixes are needed runs-on: ubuntu-latest steps: @@ -57,6 +66,7 @@ jobs: - name: Push changes using pre-commit-ci-lite uses: pre-commit-ci/lite-action@v1.0.2 - if: always() + # Only push changes in PRs + if: ${{ always() && github.event_name == 'pull_request' }} with: msg: "ci(pre-commit): Apply automatic fixes"