Repository navigation
165 lines (154 loc) · 6.87 KB
/
Copy path_runner-determinator.yml
File metadata and controls
165 lines (154 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Owner(s): ["module: ci"]
name: Check whether the workflow owner can use ARC runners
on:
workflow_call:
inputs:
check_experiments:
required: false
type: string
description: |
Comma-separated list of non-default experiments to opt into for this workflow.
These are added on top of all default experiments. If not defined, only default experiments are included.
opt_out_experiments:
required: false
type: string
description: Comma-separated list of experiments this workflow will opt-out of.
triggering_actor:
required: true
type: string
description: The triggering_actor for the workflow. Use github.triggering_actor
issue_owner:
required: true
type: string
description: The owner of the issue. Use github.event.pull_request.user.login || github.event.issue.user.login
curr_branch:
required: true
type: string
description: Current branch or tag.
curr_ref_type:
required: false
type: string
default: branch
description: The value of "github.ref_type", "branch" or "tag"
issue_number:
required: false
type: string
default: "5132"
description: |
Fetch's GitHub Issue from pytorch/test-infra
Example: https://github.com/pytorch/test-infra/issues/5132
outputs:
label-type:
description: Type of runners to use
value: ${{ jobs.runner-determinator.outputs.label-type }}
amd-sandbox-label-type:
description: Runner prefix for the "amd-sandbox" experiment (empty when not enabled)
value: ${{ jobs.runner-determinator.outputs.amd-sandbox-label-type }}
amd-dpx-label-type:
description: Runner prefix for the "amd-dpx" experiment (empty when not enabled)
value: ${{ jobs.runner-determinator.outputs.amd-dpx-label-type }}
scale-config-label-type:
description: Scale-config AMI variant prefix, e.g. "wincanary." (empty when none)
value: ${{ jobs.runner-determinator.outputs.scale-config-label-type }}
ci-docker-hash:
description: "Git tree hash of .ci/docker, used as the suffix of CI docker image tags"
value: ${{ jobs.runner-determinator.outputs.ci-docker-hash }}
jobs:
runner-determinator:
# Don't run on forked repos
if: github.repository_owner == 'pytorch'
runs-on: ubuntu-24.04
outputs:
label-type: ${{ steps.set-condition.outputs.label-type }}
amd-sandbox-label-type: ${{ steps.set-condition.outputs.amd-sandbox-label-type }}
amd-dpx-label-type: ${{ steps.set-condition.outputs.amd-dpx-label-type }}
scale-config-label-type: ${{ steps.set-condition.outputs.scale-config-label-type }}
ci-docker-hash: ${{ steps.ci-docker-hash.outputs.ci-docker-hash }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ inputs.issue_number }}
TRIGGERING_ACTOR: ${{ inputs.triggering_actor }}
ISSUE_OWNER: ${{ inputs.issue_owner }}
CHECK_EXPERIMENTS: ${{ inputs.check_experiments }}
OPT_OUT_EXPERIMENTS: ${{ inputs.opt_out_experiments }}
PR_NUMBER: ${{ github.event.pull_request.number }}
WORKFLOW_NAME: ${{ github.workflow }}
steps:
- name: Check for disabled CI
# Keep inline to avoid fetching PyTorch or depending on the PR checkout.
# test_check_ci.py keeps the three gate steps in sync.
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
pr_number="${PR_NUMBER:-}"
if [[ -z "${pr_number}" && "${GITHUB_REF}" =~ ^refs/tags/ciflow/[^/]+/([0-9]+)$ ]]; then
pr_number="${BASH_REMATCH[1]}"
fi
if [[ -z "${pr_number}" ]]; then
exit 0
fi
for attempt in 1 2 3; do
if pr_title="$(timeout 10s gh api "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}" --jq .title)"; then
if [[ "${pr_title}" == "[no-ci]"* ]]; then
echo "::error::CI is disabled by the [no-ci] PR title prefix. Remove the prefix and push a new commit to run CI."
exit 1
fi
exit 0
fi
if [[ "${attempt}" -lt 3 ]]; then
sleep "${attempt}"
fi
done
echo "::warning::Could not read the title of PR #${pr_number} after three attempts; running CI."
- name: Checkout PyTorch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# Use the default ref (the merge commit for pull_request events) so the
# determinator script always reflects the current base branch, even when
# a PR's own branch is far behind main. See #189113/#189171: main's build
# workflow no longer has an EC2 fallback, so a stale determinator script
# here can emit a runner-label prefix (e.g. "lf.") that main's build job
# no longer knows how to route.
fetch-depth: 1
sparse-checkout: |
.github/scripts/runner_determinator.py
sparse-checkout-cone-mode: false
- name: Checkout .ci/docker from PR head
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# .ci/docker is hashed from the PR's own branch (not the merge commit) so
# the resulting image tag reflects the docker changes the PR is actually
# introducing. See #182579.
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
fetch-depth: 1
path: pr-head
sparse-checkout: |
.ci/docker
sparse-checkout-cone-mode: false
- name: Compute .ci/docker tree hash
id: ci-docker-hash
shell: bash
run: |
echo "ci-docker-hash=$(git -C pr-head rev-parse HEAD:.ci/docker)" >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: python3 -m pip install urllib3==1.26.18 PyGithub==2.3.0
- name: Get the workflow type for the current user
id: set-condition
run: |
curr_branch="${{ inputs.curr_branch }}"
curr_ref_type="${{ inputs.curr_ref_type }}"
echo "Current branch is '$curr_branch'"
python3 .github/scripts/runner_determinator.py \
--github-token "$GITHUB_TOKEN" \
--github-issue "$ISSUE_NUMBER" \
--github-branch "$curr_branch" \
--github-actor "$TRIGGERING_ACTOR" \
--github-issue-owner "$ISSUE_OWNER" \
--github-ref-type "$curr_ref_type" \
--github-repo "$GITHUB_REPOSITORY" \
--eligible-experiments "$CHECK_EXPERIMENTS" \
--opt-out-experiments "$OPT_OUT_EXPERIMENTS" \
--pr-number "${PR_NUMBER}" \
--workflow-name "${WORKFLOW_NAME}"