Skip to content

Commit b194d5c

Browse files
committed
Output run_type from the matrix calculation job
1 parent adbc84c commit b194d5c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.github/workflows/ci.yml

+5-4
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
- name: checkout the source code
234235
uses: actions/checkout@v4
@@ -243,6 +244,6 @@ jobs:
243244
- name: publish toolstate
244245
run: src/ci/publish_toolstate.sh
245246
shell: bash
246-
if: github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'
247+
if: needs.calculate_matrix.outputs.run_type == 'auto'
247248
env:
248249
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}

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

+14-1
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+
raise AssertionError()
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)