From b194d5ce4460a843ba40cfc48d0073a455905711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 27 Apr 2024 12:09:18 +0200 Subject: [PATCH] Output `run_type` from the matrix calculation job --- .github/workflows/ci.yml | 9 +++++---- src/ci/github-actions/calculate-job-matrix.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f63bdce0aa..a2769a2c274 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,7 @@ jobs: runs-on: ubuntu-latest outputs: jobs: ${{ steps.jobs.outputs.jobs }} + run_type: ${{ steps.jobs.outputs.run_type }} steps: - name: Checkout the source code uses: actions/checkout@v4 @@ -116,7 +117,7 @@ jobs: run: echo "[CI_PR_NUMBER=$num]" env: num: ${{ github.event.number }} - if: github.event_name == 'pull_request' + if: needs.calculate_matrix.outputs.run_type == 'pr' - name: add extra environment variables run: src/ci/scripts/setup-environment.sh @@ -226,9 +227,9 @@ jobs: outcome: name: bors build finished runs-on: ubuntu-latest - needs: [ job ] + needs: [ calculate_matrix, job ] # !cancelled() executes the job regardless of whether the previous jobs passed or failed - if: "!cancelled() && github.event_name == 'push'" + if: ${{ !cancelled() && contains(fromJSON('["auto", "try"]'), needs.calculate_matrix.outputs.run_type) }} steps: - name: checkout the source code uses: actions/checkout@v4 @@ -243,6 +244,6 @@ jobs: - name: publish toolstate run: src/ci/publish_toolstate.sh shell: bash - if: github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust' + if: needs.calculate_matrix.outputs.run_type == 'auto' env: TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }} diff --git a/src/ci/github-actions/calculate-job-matrix.py b/src/ci/github-actions/calculate-job-matrix.py index 62cc867fac7..68565f489c9 100755 --- a/src/ci/github-actions/calculate-job-matrix.py +++ b/src/ci/github-actions/calculate-job-matrix.py @@ -106,6 +106,17 @@ def get_github_ctx() -> GitHubCtx: ) +def format_run_type(run_type: WorkflowRunType) -> str: + if run_type == WorkflowRunType.PR: + return "pr" + elif run_type == WorkflowRunType.Auto: + return "auto" + elif run_type == WorkflowRunType.Try: + return "try" + else: + raise AssertionError() + + if __name__ == "__main__": logging.basicConfig(level=logging.INFO) @@ -124,6 +135,8 @@ if __name__ == "__main__": if run_type is not None: jobs = calculate_jobs(run_type, data) jobs = skip_jobs(jobs, channel) + run_type = format_run_type(run_type) - logging.info(f"Output:\n{yaml.dump(jobs, indent=4)}") + logging.info(f"Output:\n{yaml.dump(dict(jobs=jobs, run_type=run_type), indent=4)}") print(f"jobs={json.dumps(jobs)}") + print(f"run_type={run_type}")