Skip to content

Commit 4de6ac6

Browse files
committed
Output run_type from the matrix calculation job
1 parent fd21399 commit 4de6ac6

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
runs-on: ubuntu-latest
4848
outputs:
4949
jobs: ${{ steps.jobs.outputs.jobs }}
50+
run_type: ${{ steps.jobs.outputs.run_type }}
5051
steps:
5152
- name: Checkout the source code
5253
uses: actions/checkout@v4
@@ -116,7 +117,7 @@ jobs:
116117
run: echo "[CI_PR_NUMBER=$num]"
117118
env:
118119
num: ${{ github.event.number }}
119-
if: github.event_name == 'pull_request'
120+
if: needs.calculate_matrix.outputs.run_type == 'pr'
120121

121122
- name: add extra environment variables
122123
run: src/ci/scripts/setup-environment.sh
@@ -226,9 +227,9 @@ jobs:
226227
outcome:
227228
name: bors build finished
228229
runs-on: ubuntu-latest
229-
needs: [ job ]
230+
needs: [ calculate_matrix, job ]
230231
# !cancelled() executes the job regardless of whether the previous jobs passed or failed
231-
if: "!cancelled() && github.event_name == 'push'"
232+
if: ${{ !cancelled() && contains(fromJSON('["auto", "try"]'), needs.calculate_matrix.outputs.run_type) }}
232233
steps:
233234
# Calculate the exit status of the whole CI workflow.
234235
# If all dependent jobs were successful, this exits with 0 (and the outcome job continues successfully).
@@ -239,6 +240,6 @@ jobs:
239240
- name: publish toolstate
240241
run: src/ci/publish_toolstate.sh
241242
shell: bash
242-
if: github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'
243+
if: needs.calculate_matrix.outputs.run_type == 'auto'
243244
env:
244245
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}

src/ci/github-actions/calculate-job-matrix.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ def get_github_ctx() -> GitHubCtx:
106106
)
107107

108108

109+
def format_run_type(run_type: WorkflowRunType) -> str:
110+
if run_type == WorkflowRunType.PR:
111+
return "pr"
112+
elif run_type == WorkflowRunType.Auto:
113+
return "auto"
114+
elif run_type == WorkflowRunType.Try:
115+
return "try"
116+
else:
117+
assert False
118+
119+
109120
if __name__ == "__main__":
110121
logging.basicConfig(level=logging.INFO)
111122

@@ -124,6 +135,8 @@ def get_github_ctx() -> GitHubCtx:
124135
if run_type is not None:
125136
jobs = calculate_jobs(run_type, data)
126137
jobs = skip_jobs(jobs, channel)
138+
run_type = format_run_type(run_type)
127139

128-
logging.info(f"Output:\n{yaml.dump(jobs, indent=4)}")
140+
logging.info(f"Output:\n{yaml.dump(dict(jobs=jobs, run_type=run_type), indent=4)}")
129141
print(f"jobs={json.dumps(jobs)}")
142+
print(f"run_type={run_type}")

0 commit comments

Comments
 (0)