From 663e0448a3f3cec9e95f21da48ff7cfdd56324b1 Mon Sep 17 00:00:00 2001 From: "lf-releng-code-monkey-bot[bot]" <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:41:25 +0000 Subject: [PATCH] Fix: Build Python projects by declared type Pin python-build-action to the release that passes the declared project type into build metadata. Add a mixed-marker fixture leg and assert that its build artefact uses the Python project name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com> --- .github/workflows/build-test-multiarch.yaml | 2 +- .../build-test-release-multiarch.yaml | 2 +- .github/workflows/build-test-release.yaml | 2 +- .github/workflows/build-test.yaml | 2 +- .github/workflows/testing.yaml | 102 +++++++++++++++++- 5 files changed, 103 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-test-multiarch.yaml b/.github/workflows/build-test-multiarch.yaml index 5e8a27d..c065a4b 100644 --- a/.github/workflows/build-test-multiarch.yaml +++ b/.github/workflows/build-test-multiarch.yaml @@ -940,7 +940,7 @@ jobs: - name: 'Build Python project ${{ matrix.python-version }}' id: python-build # yamllint disable-line rule:line-length - uses: lfreleng-actions/python-build-action@cb2041b440894cd2af2b3e90c2f14ff75f0fccbe # v2.1.3 + uses: lfreleng-actions/python-build-action@91bd8e8fd793b7e4b1743dab8493eb1b893c8c34 # v2.1.5 with: # yamllint disable-line rule:line-length artefact_name: dist-${{ matrix.target.arch }}-py${{ matrix.python-version }} diff --git a/.github/workflows/build-test-release-multiarch.yaml b/.github/workflows/build-test-release-multiarch.yaml index f30ed58..d40bc0e 100644 --- a/.github/workflows/build-test-release-multiarch.yaml +++ b/.github/workflows/build-test-release-multiarch.yaml @@ -1030,7 +1030,7 @@ jobs: - name: 'Build Python project ${{ matrix.python-version }}' id: python-build # yamllint disable-line rule:line-length - uses: lfreleng-actions/python-build-action@cb2041b440894cd2af2b3e90c2f14ff75f0fccbe # v2.1.3 + uses: lfreleng-actions/python-build-action@91bd8e8fd793b7e4b1743dab8493eb1b893c8c34 # v2.1.5 with: # yamllint disable-line rule:line-length artefact_name: dist-${{ matrix.target.arch }}-py${{ matrix.python-version }} diff --git a/.github/workflows/build-test-release.yaml b/.github/workflows/build-test-release.yaml index d6d2f94..dbbb5a9 100644 --- a/.github/workflows/build-test-release.yaml +++ b/.github/workflows/build-test-release.yaml @@ -899,7 +899,7 @@ jobs: - name: 'Build Python project' id: python-build # yamllint disable-line rule:line-length - uses: lfreleng-actions/python-build-action@cb2041b440894cd2af2b3e90c2f14ff75f0fccbe # v2.1.3 + uses: lfreleng-actions/python-build-action@91bd8e8fd793b7e4b1743dab8493eb1b893c8c34 # v2.1.5 with: path_prefix: ${{ inputs.path_prefix }} # The newest version in the matrix python-metadata resolved diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 1455e22..69e3394 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -854,7 +854,7 @@ jobs: - name: 'Build Python project' id: python-build # yamllint disable-line rule:line-length - uses: lfreleng-actions/python-build-action@cb2041b440894cd2af2b3e90c2f14ff75f0fccbe # v2.1.3 + uses: lfreleng-actions/python-build-action@91bd8e8fd793b7e4b1743dab8493eb1b893c8c34 # v2.1.5 with: path_prefix: ${{ inputs.path_prefix }} # The newest version in the matrix python-metadata resolved diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index c7ecde5..ba945cb 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -9,6 +9,7 @@ # * lftools-uv (standard single-arch) -> build-test.yaml # * python-nss-ng (multi-arch C build) -> build-test-multiarch.yaml # * tests/fixtures/grype-gate (fixture) -> build-test.yaml +# * tests/fixtures/mixed-markers (fixture) -> build-test.yaml # # The reusable workflows are referenced with the self-repository form # ('$/'), which resolves this repository at the commit already @@ -125,6 +126,23 @@ jobs: grype_gate_when: 'dependencies-changed' grype_dependency_ecosystems: 'docker' + # A whole-workflow build of a Python project beside a package.json. + # The build, audit and metadata jobs must all resolve the same project. + mixed-markers: + name: 'Fixture (mixed-markers)' + permissions: + contents: read + pull-requests: read # Reusable workflow reads PR metadata + uses: $/.github/workflows/build-test.yaml + with: + path_prefix: 'tests/fixtures/mixed-markers' + artifact_suffix: '-mixed-markers-fixture' + tests_enabled: false + audit_enabled: true + sbom_enabled: false + grype_enabled: false + cbom_enabled: false + # The dependencies-changed gate trusts the verdict the # repository-metadata job computes and hands grype-scan-action as # dependencies-changed. The action's own suite proves the verdict; @@ -208,9 +226,9 @@ jobs: # beside a higher-ranked marker file (here a package.json) still # reads as itself. This job runs their metadata step on such a # fixture; tests/test-python-metadata.sh holds the step to the - # workflows' pin and with: block, bar path_prefix. A whole-workflow - # leg on the fixture waits for python-build-action, which makes the - # same call inside itself. + # workflows' pin and with: block, bar path_prefix. The + # mixed-markers fixture leg below runs the whole workflow and proves + # python-build-action makes the same declared-type call. python-metadata-fixture: name: 'Test: Declared Python project type' runs-on: ubuntu-latest @@ -276,6 +294,84 @@ jobs: echo "Declared Python project type honoured ✅" \ >> "$GITHUB_STEP_SUMMARY" + mixed-markers-assert: + name: 'Test: Mixed markers build artefact name' + runs-on: ubuntu-latest + needs: ['mixed-markers'] + if: ${{ !cancelled() }} + permissions: + actions: read # List this run's artefacts + timeout-minutes: 10 + steps: + - name: 'Load egress allow-list' + # yamllint disable-line rule:line-length + uses: lfreleng-actions/harden-runner-block-action@65ff87957e1cac2de3203a85dbb07c31810321cb # v0.16.4 + - name: 'Harden runner' + # yamllint disable-line rule:line-length + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: 'block' + allowed-endpoints: > + ${{ env.CONNECTION_ALLOW_LIST }} + + - name: 'Define gh_api retry helper' + shell: bash + run: | + # Define gh_api retry helper + set -euo pipefail + cat > "${RUNNER_TEMP}/gh-api.sh" << 'EOF' + gh_api() { + local attempt delay out + for attempt in 1 2 3; do + if out="$(gh api "$@")"; then + printf '%s\n' "${out}" + return 0 + fi + if [ "${attempt}" -eq 3 ]; then + return 1 + fi + delay="$((attempt * 5))" + echo "::warning::gh api failed, attempt ${attempt} of 3;" \ + "retrying in ${delay}s" >&2 + sleep "${delay}" + done + } + EOF + + - name: 'Assert the build artefact name' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + REPOSITORY: ${{ github.repository }} + RUN_ID: ${{ github.run_id }} + LEG_RESULT: ${{ needs.mixed-markers.result }} + run: | + # Assert the build artefact name + set -euo pipefail + status=0 + if [ "${LEG_RESULT}" != 'success' ]; then + echo "::error::Mixed-markers leg ${LEG_RESULT}, expected success" + status=1 + fi + # shellcheck source=/dev/null + . "${RUNNER_TEMP}/gh-api.sh" + api="repos/${REPOSITORY}/actions/runs/${RUN_ID}" + names="$(gh_api --paginate "${api}/artifacts" \ + --jq '.artifacts[].name')" + if ! grep -Fxq 'mixed-markers-fixture' <<< "${names}"; then + echo "::error::No artifact named mixed-markers-fixture" + status=1 + fi + if grep -Fxq 'mixed-markers-node-side' <<< "${names}"; then + echo "::error::Unexpected artifact named mixed-markers-node-side" + status=1 + fi + if [ "${status}" -eq 0 ]; then + echo "Mixed-markers build artefact name is correct ✅" \ + >> "$GITHUB_STEP_SUMMARY" + fi + exit "${status}" + # Proves the gate verdicts from the run itself, not just that the job # graph went green. Each consumer dependencies-changed leg builds # another repository, which the repository-metadata job cannot