workflows: run release artifact build checks from ci.yaml (#4398) Release workflows should not trigger directly on pull request or push events; CI checks belong in the CI workflow. Remove the `pull_request` trigger from `release_build_artifacts.yaml`, make its `workflow_call` `ref` input optional, and invoke it as a reusable workflow job from `ci.yaml`.
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7990f65..48bb5a1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml
@@ -30,3 +30,8 @@ with: version: 0.15.14 args: format --check --exclude testdata + + build_release_artifacts: + name: Build release artifacts + uses: ./.github/workflows/release_build_artifacts.yaml + secrets: inherit
diff --git a/.github/workflows/release_build_artifacts.yaml b/.github/workflows/release_build_artifacts.yaml index 32a9680..b4ea7fd 100644 --- a/.github/workflows/release_build_artifacts.yaml +++ b/.github/workflows/release_build_artifacts.yaml
@@ -12,12 +12,11 @@ name: "Release: Build Artifacts" on: - pull_request: workflow_call: inputs: ref: - description: "The git ref (e.g. release tag) to build" - required: true + description: "The git ref (e.g. release tag) to build. Defaults to the selected ref." + required: false type: string workflow_dispatch: inputs: @@ -132,7 +131,7 @@ env: INPUT_REF: ${{ inputs.ref }} # ${INPUT_REF:+...} expands to the --stamp and --embed_label flags only - # when INPUT_REF is non-empty (release builds, not pull_request builds). + # when INPUT_REF is non-empty (release builds, not CI builds). run: >- bazel build ${INPUT_REF:+--stamp "--embed_label=$INPUT_REF"}
diff --git a/tests/workflows/release_build_artifacts_test.py b/tests/workflows/release_build_artifacts_test.py index ad933a1..d0a7279 100644 --- a/tests/workflows/release_build_artifacts_test.py +++ b/tests/workflows/release_build_artifacts_test.py
@@ -49,12 +49,23 @@ def test_workflow_is_safe_for_presubmit(): - """Verifies that release_build_artifacts.yaml is read-only and never publishes.""" + """Verifies that release_build_artifacts.yaml is read-only, never publishes, + and is called by ci.yaml. + """ workflow = _load_workflow() # PyYAML parses unquoted `on:` as boolean True in YAML 1.1. triggers = workflow.get("on") or workflow.get(True, {}) - assert "pull_request" in triggers + assert set(triggers.keys()) == {"workflow_call", "workflow_dispatch"} + assert not triggers["workflow_call"]["inputs"]["ref"].get("required", False) + + ci_workflow = _load_workflow("ci.yaml") + ci_triggers = ci_workflow.get("on") or ci_workflow.get(True, {}) + assert "pull_request" in ci_triggers + assert "push" in ci_triggers + ci_job = ci_workflow["jobs"]["build_release_artifacts"] + assert ci_job["uses"] == "./.github/workflows/release_build_artifacts.yaml" + assert ci_job.get("secrets") == "inherit" assert workflow.get("permissions") == {"contents": "read"}