From 7584af4e44913f714fa09f00db4b3a05df5820a4 Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 14 May 2025 14:47:00 +0200 Subject: [PATCH] ci: don't duplicate push & PR --- .github/workflows/check_pr.yml | 27 +++++++++++++++++++++++++++ .github/workflows/ci.yml | 11 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/check_pr.yml diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml new file mode 100644 index 00000000..3e644cf0 --- /dev/null +++ b/.github/workflows/check_pr.yml @@ -0,0 +1,27 @@ +on: + workflow_call: + outputs: + branch-pr: + description: The PR number if the branch is in one + value: ${{ jobs.pr.outputs.branch-pr }} + +jobs: + pr: + runs-on: "ubuntu-latest" + outputs: + branch-pr: ${{ steps.script.outputs.result }} + steps: + - uses: actions/github-script@v7 + id: script + if: github.event_name == 'push' + with: + script: | + const prs = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + head: context.repo.owner + ':${{ github.ref_name }}' + }) + if (prs.data.length) { + console.log(`::notice ::Skipping CI on branch push as it is already run in PR #${prs.data[0]["number"]}`) + return prs.data[0]["number"] + } \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 700513b6..e8068401 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,16 +5,27 @@ permissions: pull-requests: write jobs: + check_pr_status: + uses: ./.github/workflows/check_pr.yml + formatter: + needs: check_pr_status + if: needs.check_pr_status.outputs.branch-pr == '' uses: ./.github/workflows/formatter.yml unit-test: + needs: check_pr_status + if: needs.check_pr_status.outputs.branch-pr == '' uses: ./.github/workflows/pytest.yml secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} unit-test-matrix: + needs: check_pr_status + if: needs.check_pr_status.outputs.branch-pr == '' uses: ./.github/workflows/pytest-matrix.yml end2end-test: + needs: check_pr_status + if: needs.check_pr_status.outputs.branch-pr == '' uses: ./.github/workflows/end2end-conda.yml \ No newline at end of file