Skip to content

Commit

Permalink
Output run_type from the matrix calculation job
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Apr 27, 2024
1 parent fd21399 commit 47767ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
# Calculate the exit status of the whole CI workflow.
# If all dependent jobs were successful, this exits with 0 (and the outcome job continues successfully).
Expand All @@ -239,6 +240,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 }}
15 changes: 14 additions & 1 deletion src/ci/github-actions/calculate-job-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -124,6 +135,8 @@ def get_github_ctx() -> GitHubCtx:
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}")

0 comments on commit 47767ac

Please sign in to comment.