Unverified Commit 2c398774 authored by Lucas Saavedra Vaz's avatar Lucas Saavedra Vaz Committed by GitHub

ci(pre-commit): Fix PR checks and cache (#9531)

parent 4960d86b
# This needs to be in a separate workflow because it requires higher permissions than the calling workflow
name: Report Pre-commit Check Status name: Report Pre-commit Check Status
on: on:
pull_request_target: workflow_run:
types: [opened, reopened, synchronize, labeled, unlabeled] workflows: [Pre-commit hooks]
types:
- completed
permissions: permissions:
statuses: write statuses: write
jobs: jobs:
report-run: report-success:
name: Check if the PR has run the pre-commit checks name: Report pre-commit success
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Report pending - name: Report success
uses: conda/actions/set-commit-status@v24.2.0 uses: actions/github-script@v7
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
with: with:
timeout: 10 script: |
interval: 30 const owner = '${{ github.repository_owner }}';
workflow: pre-commit.yml const repo = '${{ github.repository }}'.split('/')[1];
sha: ${{ github.event.pull_request.head.sha || github.sha }} 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 report-pending:
uses: conda/actions/set-commit-status@v24.2.0 name: Report pre-commit pending
if: | if: github.event.workflow_run.conclusion != 'success'
contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') && runs-on: ubuntu-latest
steps.wait-on-workflow.outputs.conclusion == 'success' steps:
- name: Report pending
uses: actions/github-script@v7
with: with:
context: "Pre-commit checks" script: |
state: success const owner = '${{ github.repository_owner }}';
description: All pre-commit checks passed 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}`);
name: Pre-commit hooks name: Pre-commit hooks
on: on:
workflow_dispatch:
push:
branches:
- master
pull_request: pull_request:
types: [opened, reopened, synchronize, labeled, unlabeled] types: [opened, reopened, synchronize, labeled, unlabeled]
concurrency:
group: pre-commit-${{github.event.pull_request.number || github.ref}}
cancel-in-progress: true
jobs: jobs:
lint: lint:
if: | 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 name: Check if fixes are needed
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
...@@ -57,6 +66,7 @@ jobs: ...@@ -57,6 +66,7 @@ jobs:
- name: Push changes using pre-commit-ci-lite - name: Push changes using pre-commit-ci-lite
uses: pre-commit-ci/lite-action@v1.0.2 uses: pre-commit-ci/lite-action@v1.0.2
if: always() # Only push changes in PRs
if: ${{ always() && github.event_name == 'pull_request' }}
with: with:
msg: "ci(pre-commit): Apply automatic fixes" msg: "ci(pre-commit): Apply automatic fixes"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment