From 54cf7d97e470f8f6f0ec75533795b8284f66b63b Mon Sep 17 00:00:00 2001 From: Chris Novakovic Date: Mon, 13 Oct 2025 11:54:28 +0100 Subject: [PATCH 1/2] CI: separate tools and plugin release steps Currently, tools releases (which include please_pex) are blocked if the tests fail when built by the stable please_pex release, which prevents new versions of please_pex from being released in the event that external factors (e.g. changes on the CI platform) cause please_pex to stop working. Break this cyclic dependency by only making tools releases contingent on the tests passing when built by the in-repo version of please_pex, and only make plugin releases contingent on the tests passing when built by the version of please_pex downloaded by `//tools:please_pex`. This allows us to fix problems with please_pex, get a new version released, and use that version in the plugin without having to ignore CI test failures at any stage. --- .github/workflows/plugin.yaml | 91 +++++++++++++++--------------- .github/workflows/plugin_test.yaml | 48 ++++++++++++++++ test/BUILD | 6 -- test/ci_test.py | 17 ------ 4 files changed, 95 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/plugin_test.yaml delete mode 100644 test/ci_test.py diff --git a/.github/workflows/plugin.yaml b/.github/workflows/plugin.yaml index 86953d6..0fb8312 100644 --- a/.github/workflows/plugin.yaml +++ b/.github/workflows/plugin.yaml @@ -1,61 +1,51 @@ -name: Python rules -on: [push, pull_request] +name: Plugin +on: + - push + - pull_request jobs: + test-please_pex: + name: Test (Python ${{ matrix.python }}, in-repo please_pex) + uses: ./.github/workflows/plugin_test.yaml + with: + runner: ubuntu-latest + python: ${{ matrix.python }} + please_pex_from_repo: true + strategy: + fail-fast: false + matrix: + python: + - '3.9' + - '3.10' + - '3.11' + - '3.12' + - '3.13' test: - name: Test (Python ${{ matrix.python-version }}, ${{ matrix.pex-tool }} pex tool) - runs-on: ubuntu-latest + name: Test (Python ${{ matrix.python }}, stable please_pex release) + uses: ./.github/workflows/plugin_test.yaml + with: + runner: ubuntu-latest + python: ${{ matrix.python }} + please_pex_from_repo: false strategy: fail-fast: false matrix: - python-version: + python: - '3.9' - '3.10' - '3.11' - '3.12' - '3.13' - pex-tool: - - default - - in-repo - steps: - - name: Checkout code - uses: actions/checkout@v5 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v6 - with: - python-version: ${{ matrix.python-version }} - - name: Use this Python in Please build environments - run: | - echo "CI_PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV - echo "PLZ_ARGS=-o plugin.python.defaultinterpreter:$(which python3) -o build.passenv:CI_PYTHON_VERSION" >> $GITHUB_ENV - - name: Build and use in-repo pex tool - if: matrix.pex-tool == 'in-repo' - run: | - ./pleasew build //tools/please_pex - cp $(./pleasew query outputs //tools/please_pex) $HOME/please_pex - echo "PLZ_ARGS="$(grep ^PLZ_ARGS= $GITHUB_ENV | cut -d= -f2-)" -o plugin.python.pextool:$HOME/please_pex" >> $GITHUB_ENV - - name: Run tests - run: ./pleasew test --log_file plz-out/log/test.log -e e2e - - name: Run e2e test - run: ./pleasew test --log_file plz-out/log/e2e.log -i e2e - - name: Archive logs - if: always() - uses: actions/upload-artifact@v4 - with: - name: logs-${{ matrix.python-version }}-please_pex-${{ matrix.pex-tool }} - path: plz-out/log - release: - needs: [test] + release-tools: + name: Release tools + if: github.ref == 'refs/heads/master' + needs: + - test-please_pex runs-on: ubuntu-latest - if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/v1' steps: - - name: Checkout code + - name: Check out code uses: actions/checkout@v5 - - name: Build + - name: Build tools run: ./pleasew build //package:release_files - - name: Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: thought-machine/release-action@master - name: Release tools env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -65,3 +55,16 @@ jobs: version-file: tools/VERSION change-log-file: tools/ChangeLog release-prefix: tools + release-plugin: + name: Release plugin + if: github.ref == 'refs/heads/master' + needs: + - test + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v5 + - name: Release plugin + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: thought-machine/release-action@master diff --git a/.github/workflows/plugin_test.yaml b/.github/workflows/plugin_test.yaml new file mode 100644 index 0000000..cf15ee0 --- /dev/null +++ b/.github/workflows/plugin_test.yaml @@ -0,0 +1,48 @@ +on: + workflow_call: + inputs: + runner: + description: "The GitHub runner type on which this workflow should run." + required: true + type: string + python: + description: "The Python version to configure the plugin to use. Must be a value of python-version recognised by the actions/setup-python action." + required: true + type: string + please_pex_from_repo: + description: "Whether to build please_pex from source and use that as the plugin's please_pex tool (true), or use the existing binary version of please_pex downloaded by //tools:please_pex (false)." + required: false + type: boolean + default: false +jobs: + test: + name: Run tests + runs-on: ${{ inputs.runner }} + steps: + - name: Install Python in CI environment + id: python + uses: actions/setup-python@v6 + with: + python-version: ${{ inputs.python }} + update-environment: false + - name: Check out code + uses: actions/checkout@v5 + - name: Configure plugin's default Python interpreter + run: | + echo "PLZ_ARGS=-o plugin.python.defaultinterpreter:${{ steps.python.outputs.python-path }}" >> $GITHUB_ENV + - name: Build please_pex + if: inputs.please_pex_from_repo + # This copies the please_pex binary into the runner user's home directory so it persists across steps. + run: | + ./pleasew build //tools/please_pex + cp $(./pleasew query outputs //tools/please_pex) $HOME/please_pex + echo "PLZ_ARGS="$(grep ^PLZ_ARGS= $GITHUB_ENV | cut -d= -f2-)" -o plugin.python.pextool:$HOME/please_pex" >> $GITHUB_ENV + - name: Run tests + run: ./pleasew test --log_file plz-out/log/test.log -e e2e + - name: Run e2e tests + run: ./pleasew test --log_file plz-out/log/e2e.log -i e2e + - name: Archive logs + uses: actions/upload-artifact@v4 + with: + name: logs-python_${{ inputs.python }}-please_pex_${{ inputs.please_pex_from_repo && 'repo' || 'stable' }} + path: plz-out/log diff --git a/test/BUILD b/test/BUILD index db5dd89..c3b7aee 100644 --- a/test/BUILD +++ b/test/BUILD @@ -176,12 +176,6 @@ python_test( ], ) -# This test need only run in the GitHub Actions workflow - it is skipped outside this environment. -python_test( - name = "ci_test", - srcs = ["ci_test.py"], -) - python_test( name = "interpreter_not_included_test", srcs = ["interpreter_not_included_test.py"], diff --git a/test/ci_test.py b/test/ci_test.py deleted file mode 100644 index fbefa24..0000000 --- a/test/ci_test.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Contains tests specific to the CI environment provided by GitHub Actions workflows.""" - -import os -import sys -import unittest - - -@unittest.skipIf(os.getenv("CI_PYTHON_VERSION") is None, "Not running in CI environment") -class CITest(unittest.TestCase): - - def test_use_setup_python_interpreter(self): - """Ensures that python_tests are being run by the Python interpreter installed by - actions/setup-python. - """ - ci_major, _, ci_minor = os.getenv("CI_PYTHON_VERSION").partition(".") - self.assertEqual(int(ci_major), sys.version_info[0]) - self.assertEqual(int(ci_minor), sys.version_info[1]) From 7d3dcb461e37785f24a8c36375b84c97de553cad Mon Sep 17 00:00:00 2001 From: Chris Novakovic Date: Mon, 13 Oct 2025 13:58:46 +0100 Subject: [PATCH 2/2] Don't break out e2es; run as many tests as possible before failing --- .github/workflows/plugin_test.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/plugin_test.yaml b/.github/workflows/plugin_test.yaml index cf15ee0..a82ae99 100644 --- a/.github/workflows/plugin_test.yaml +++ b/.github/workflows/plugin_test.yaml @@ -38,9 +38,7 @@ jobs: cp $(./pleasew query outputs //tools/please_pex) $HOME/please_pex echo "PLZ_ARGS="$(grep ^PLZ_ARGS= $GITHUB_ENV | cut -d= -f2-)" -o plugin.python.pextool:$HOME/please_pex" >> $GITHUB_ENV - name: Run tests - run: ./pleasew test --log_file plz-out/log/test.log -e e2e - - name: Run e2e tests - run: ./pleasew test --log_file plz-out/log/e2e.log -i e2e + run: ./pleasew test --keep_going --log_file plz-out/log/test.log - name: Archive logs uses: actions/upload-artifact@v4 with: