From c788630c701933fb9c9369c205eba3ca9173898f Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Sat, 12 Apr 2025 15:09:11 +0100 Subject: [PATCH 1/5] Remove check workflow and filter on branch name --- .github/workflows/_check.yml | 27 ------------------- .github/workflows/ci.yml | 11 ++------ .../workflows/ci.yml.jinja" | 12 --------- 3 files changed, 2 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/_check.yml diff --git a/.github/workflows/_check.yml b/.github/workflows/_check.yml deleted file mode 100644 index a6139c19..00000000 --- a/.github/workflows/_check.yml +++ /dev/null @@ -1,27 +0,0 @@ -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"] - } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f198a244..4c51cb67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,22 +2,17 @@ name: CI on: push: + branches: + - main pull_request: jobs: - check: - uses: ./.github/workflows/_check.yml - lint: - needs: check - if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_tox.yml with: tox: pre-commit test: - needs: check - if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_test.yml with: python-version: dev @@ -26,8 +21,6 @@ jobs: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} docs: - needs: check - if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_docs.yml permissions: contents: write diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" index c6ed106f..04ce4e26 100644 --- "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" +++ "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" @@ -5,19 +5,13 @@ on: pull_request: jobs: - check: - uses: ./.github/workflows/_check.yml lint: - needs: check - if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_tox.yml with: tox: pre-commit,type-checking {% raw %} test: - needs: check - if: needs.check.outputs.branch-pr == '' strategy: matrix: runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest @@ -35,21 +29,15 @@ jobs: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} {% endraw %}{% if docker %} container: - needs: check - if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_container.yml permissions: contents: read packages: write {% endif %}{% if sphinx %} docs: - needs: check - if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_docs.yml {% endif %} dist: - needs: check - if: needs.check.outputs.branch-pr == '' uses: ./.github/workflows/_dist.yml {% if pypi %} pypi: From 75ab0076019eb1adb44311a8b183e5cc72d72e8b Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Sat, 12 Apr 2025 15:17:42 +0100 Subject: [PATCH 2/5] Remove template's check --- .../workflows/_check.yml" | 1 - 1 file changed, 1 deletion(-) delete mode 120000 "template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_check.yml" diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_check.yml" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_check.yml" deleted file mode 120000 index 9c0f79a5..00000000 --- "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_check.yml" +++ /dev/null @@ -1 +0,0 @@ -../../../.github/workflows/_check.yml \ No newline at end of file From 1cbfff07e1bb1d1bb5448b4f7f970e653042108a Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Tue, 6 May 2025 13:12:11 +0000 Subject: [PATCH 3/5] docs: Add ADR for ci on PR only --- .../explanations/decisions/0021-ci-only-pr.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/explanations/decisions/0021-ci-only-pr.md diff --git a/docs/explanations/decisions/0021-ci-only-pr.md b/docs/explanations/decisions/0021-ci-only-pr.md new file mode 100644 index 00000000..f5d555be --- /dev/null +++ b/docs/explanations/decisions/0021-ci-only-pr.md @@ -0,0 +1,24 @@ +# 21. Run CI on pull requests and main branch only + +Date: 2025-05-06 + +## Status + +Accepted + +## Context + +CI has been being run on branches that do not have open pull requests, which has: added spurious jobs to the organisation's compute limit; made workflow definitions more complex; made the results page harder to parse; and allowed known working development branches to become stale or forgotten. + +Running CI only on branches that have open pull requests will: reduce compute jobs created for code that is known to not be working; simplify workflow definitions; simplify the CI results page; encourage early creation of pull requests, adding visibility to development. + +Draft pull requests will still have CI jobs run, ensuring that code quality is maintained while allowing reviewers to ignore changes that are not ready for human review. + +## Decision + +CI will only be run on all PRs when changes are made, and on the main branch when PRs are merged into it: not on branches that do not have open PRs. +Opening a draft PR will allow CI to be run, with the understanding that the PR may not be ready for review. + +## Consequences + +The `check` job will be removed and CI will run on all PRs and on the `main` branch. From 68033796777f57e80ca30faf3f138f9366373942 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Wed, 7 May 2025 09:01:48 +0100 Subject: [PATCH 4/5] fix: Run CI on all tags --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c51cb67..223b73ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,8 @@ on: push: branches: - main + tags: + - '*' pull_request: jobs: From 9f685d0b7c47de66af56f6ac7daa02a0c6226d51 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Wed, 7 May 2025 11:26:02 +0100 Subject: [PATCH 5/5] Split CI and release pipelines --- .github/workflows/ci.yml | 9 ---- .github/workflows/release.yml | 31 ++++++++++++ .../workflows/_test_all.yml" | 20 ++++++++ .../workflows/ci.yml.jinja" | 40 ++++----------- .../workflows/release.yml.jinja" | 49 +++++++++++++++++++ 5 files changed, 109 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 "template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_test_all.yml" create mode 100644 "template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/release.yml.jinja" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 223b73ec..463f2c79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,8 +4,6 @@ on: push: branches: - main - tags: - - '*' pull_request: jobs: @@ -33,10 +31,3 @@ jobs: uses: ./.github/workflows/_example.yml secrets: EXAMPLE_DEPLOY_KEY: ${{ secrets.EXAMPLE_DEPLOY_KEY }} - - release: - if: github.ref_type == 'tag' - needs: docs - uses: ./.github/workflows/_release.yml - permissions: - contents: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..5d22260b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + tags: + - '*' + +jobs: + lint: + uses: ./.github/workflows/_tox.yml + with: + tox: pre-commit + + test: + uses: ./.github/workflows/_test.yml + with: + python-version: dev + runs-on: ubuntu-latest + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + docs: + uses: ./.github/workflows/_docs.yml + permissions: + contents: write + + release: + needs: docs + uses: ./.github/workflows/_release.yml + permissions: + contents: write diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_test_all.yml" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_test_all.yml" new file mode 100644 index 00000000..35e5d8c3 --- /dev/null +++ "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/_test_all.yml" @@ -0,0 +1,20 @@ +on: + workflow_call: + +jobs: + test: + strategy: + matrix: + runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest + python-version: ["3.10", "3.11", "3.12"] + include: + # Include one that runs in the dev environment + - runs-on: "ubuntu-latest" + python-version: "dev" + fail-fast: false + uses: ./.github/workflows/_test.yml + with: + runs-on: ${{ matrix.runs-on }} + python-version: ${{ matrix.python-version }} + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" index 04ce4e26..153b8e60 100644 --- "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" +++ "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/ci.yml.jinja" @@ -2,6 +2,8 @@ name: CI on: push: + branches: + - main pull_request: jobs: @@ -10,46 +12,22 @@ jobs: uses: ./.github/workflows/_tox.yml with: tox: pre-commit,type-checking -{% raw %} + test: - strategy: - matrix: - runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest - python-version: ["3.10", "3.11", "3.12"] - include: - # Include one that runs in the dev environment - - runs-on: "ubuntu-latest" - python-version: "dev" - fail-fast: false - uses: ./.github/workflows/_test.yml - with: - runs-on: ${{ matrix.runs-on }} - python-version: ${{ matrix.python-version }} - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} -{% endraw %}{% if docker %} + uses: ./.github/workflows/_test_all.yml + +{% if docker %} + container: uses: ./.github/workflows/_container.yml permissions: contents: read packages: write {% endif %}{% if sphinx %} + docs: uses: ./.github/workflows/_docs.yml {% endif %} + dist: uses: ./.github/workflows/_dist.yml - {% if pypi %} - pypi: - if: github.ref_type == 'tag' - needs: dist - uses: ./.github/workflows/_pypi.yml - permissions: - id-token: write - {% endif %} - release: - if: github.ref_type == 'tag' - needs: [dist{% if sphinx %}, docs{% endif %}] - uses: ./.github/workflows/_release.yml - permissions: - contents: write diff --git "a/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/release.yml.jinja" "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/release.yml.jinja" new file mode 100644 index 00000000..4a6ffc8f --- /dev/null +++ "b/template/{% if git_platform==\"github.com\" %}.github{% endif %}/workflows/release.yml.jinja" @@ -0,0 +1,49 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +jobs: + + lint: + uses: ./.github/workflows/_tox.yml + with: + tox: pre-commit,type-checking + + test: + uses: ./.github/workflows/_test_all.yml + with: + tox: pre-commit,type-checking +{% if docker %} + + container: + uses: ./.github/workflows/_container.yml + permissions: + contents: read + packages: write +{% endif %}{% if sphinx %} + + docs: + uses: ./.github/workflows/_docs.yml +{% endif %} + + dist: + uses: ./.github/workflows/_dist.yml +{% if pypi %} + + pypi: + if: github.ref_type == 'tag' + needs: dist + uses: ./.github/workflows/_pypi.yml + permissions: + id-token: write +{% endif %} + + release: + needs: [dist{% if sphinx %}, docs{% endif %}] + uses: ./.github/workflows/_release.yml + permissions: + contents: write