44
44
id : set_pr_number
45
45
run : echo "PR_NUMBER=${{ env.PR_NUMBER }}" >> "$GITHUB_OUTPUT"
46
46
47
+ # Get commit sha of `refs/pull/PR_NUMBER/merge` and `refs/pull/PR_NUMBER/head`
48
+ get-sha :
49
+ runs-on : ubuntu-latest
50
+ needs : get-pr-number
51
+ if : ${{ needs.get-pr-number.outputs.PR_NUMBER != ''}}
52
+ outputs :
53
+ PR_MERGE_COMMIT_SHA : ${{ steps.get_sha.outputs.PR_MERGE_COMMIT_SHA }}
54
+ PR_HEAD_SHA : ${{ steps.get_sha.outputs.PR_HEAD_SHA }}
55
+ steps :
56
+ - uses : actions/checkout@v4
57
+ with :
58
+ fetch-depth : " 0"
59
+ ref : " refs/pull/${{needs.get-pr-number.outputs.PR_NUMBER}}/merge"
60
+
61
+ - name : Get SHA
62
+ id : get_sha
63
+ env :
64
+ PR_NUMBER : ${{needs.get-pr-number.outputs.PR_NUMBER}}
65
+ run : |
66
+ echo "PR_MERGE_COMMIT_SHA: $(git log -1 --format=%H)"
67
+ echo "PR_MERGE_COMMIT_SHA=$(git log -1 --format=%H)" >> "$GITHUB_OUTPUT"
68
+ git fetch origin refs/pull/$PR_NUMBER/head:refs/remotes/pull/$PR_NUMBER/head
69
+ git checkout refs/remotes/pull/$PR_NUMBER/head
70
+ echo "PR_HEAD_SHA: $(git log -1 --format=%H)"
71
+ echo "PR_HEAD_SHA=$(git log -1 --format=%H)" >> "$GITHUB_OUTPUT"
72
+
47
73
# use a python script to handle this complex logic
48
74
# case 1: `run-slow` (auto. infer with limited number of models, but in particular, new model)
49
75
# case 2: `run-slow model_1, model_2`
61
87
fetch-depth : " 0"
62
88
ref : " refs/pull/${{needs.get-pr-number.outputs.PR_NUMBER}}/merge"
63
89
64
- - name : Reply to the comment
65
- env :
66
- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67
- run : |
68
- gh api \
69
- --method POST \
70
- -H "Accept: application/vnd.github+json" \
71
- -H "X-GitHub-Api-Version: 2022-11-28" \
72
- repos/${{ github.repository }}/issues/${{ needs.get-pr-number.outputs.PR_NUMBER }}/comments \
73
- -f "body=This comment contains run-slow, running the specified job..."
74
-
75
90
- name : Get models to test
76
91
run : |
77
92
python -m pip install GitPython
@@ -84,10 +99,22 @@ jobs:
84
99
echo "${{ env.models }}"
85
100
echo "models=${{ env.models }}" >> $GITHUB_OUTPUT
86
101
102
+ # TODO: update
103
+ - name : Reply to the comment
104
+ env :
105
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
106
+ run : |
107
+ gh api \
108
+ --method POST \
109
+ -H "Accept: application/vnd.github+json" \
110
+ -H "X-GitHub-Api-Version: 2022-11-28" \
111
+ repos/${{ github.repository }}/issues/${{ needs.get-pr-number.outputs.PR_NUMBER }}/comments \
112
+ -f "body=This comment contains run-slow, running the specified job..."
113
+
87
114
create_run :
88
115
name : Create run
89
116
if : ${{ needs.get-tests.outputs.models != '[]' }}
90
- needs : get-tests
117
+ needs : [ get-sha, get- tests]
91
118
permissions : write-all
92
119
runs-on : ubuntu-latest
93
120
steps :
@@ -101,15 +128,16 @@ jobs:
101
128
--method POST \
102
129
-H "Accept: application/vnd.github+json" \
103
130
-H "X-GitHub-Api-Version: 2022-11-28" \
104
- / repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
131
+ repos/${{ github.repository }}/statuses/${{ needs.get-sha.outputs.PR_HEAD_SHA }} \
105
132
-f "target_url=$GITHUB_RUN_URL" -f "state=pending" -f "description=Slow CI job" -f "context=pytest/custom-tests"
106
133
134
+ # (To be removed: only for playing with this PR on `transformers_ci_bot` where no self-hosted runner is available)
107
135
run_models_gpu_dummy :
108
- name : Run all tests for the model
136
+ name : Run all tests for the model (dummy)
109
137
# Triggered only `find_models_to_run` is triggered (label `run-slow` is added) which gives the models to run
110
138
# (either a new model PR or via a commit message)
111
139
if : ${{ needs.get-tests.outputs.models != '[]' }}
112
- needs : [get-tests, create_run]
140
+ needs : [get-pr-number, get- tests, create_run]
113
141
strategy :
114
142
fail-fast : false
115
143
matrix :
@@ -121,13 +149,14 @@ jobs:
121
149
shell : bash
122
150
run : |
123
151
echo "${{ matrix.folders }}"
152
+ sleep 10s
124
153
125
154
run_models_gpu :
126
155
name : Run all tests for the model
127
156
# Triggered only `find_models_to_run` is triggered (label `run-slow` is added) which gives the models to run
128
157
# (either a new model PR or via a commit message)
129
158
if : ${{ needs.get-tests.outputs.models != '[]' }}
130
- needs : [get-tests, create_run]
159
+ needs : [get-pr-number, get- tests, create_run]
131
160
strategy :
132
161
fail-fast : false
133
162
matrix :
@@ -155,9 +184,12 @@ jobs:
155
184
echo "$matrix_folders"
156
185
echo "matrix_folders=$matrix_folders" >> $GITHUB_ENV
157
186
158
- - name : Update clone
187
+ - name : Checkout to PR merge commit
159
188
working-directory : /transformers
160
- run : git fetch && git fetch origin pull/${{ github.event.pull_request.number }}/head:pull/${{ github.event.pull_request.number }}/merge && git checkout pull/${{ github.event.pull_request.number }}/merge
189
+ run : |
190
+ git fetch origin refs/pull/${{ needs.get-pr-number.outputs.PR_NUMBER }}/merge:refs/remotes/pull/${{ needs.get-pr-number.outputs.PR_NUMBER }}/merge
191
+ git checkout refs/remotes/pull/${{ needs.get-pr-number.outputs.PR_NUMBER }}/merge
192
+ git log -1 --format=%H
161
193
162
194
- name : Reinstall transformers in edit mode (remove the one installed during docker image build)
163
195
working-directory : /transformers
@@ -180,7 +212,7 @@ jobs:
180
212
machine_type=${{ matrix.machine_type }}
181
213
fi
182
214
echo "$machine_type"
183
- echo "machine_type=$machine_type" >> $GITHUB_ENV
215
+ echo "machine_type=$machine_type" >> $GITHUB_ENV
184
216
185
217
- name : Environment
186
218
working-directory : /transformers
@@ -219,9 +251,9 @@ jobs:
219
251
220
252
update_run_status :
221
253
name : Update Check Run Status
222
- needs : [run_models_gpu]
254
+ needs : [get-sha, create_run, run_models_gpu]
223
255
permissions : write-all
224
- if : always()
256
+ if : ${{ always() && needs.create_run.result == 'success' }}
225
257
runs-on : ubuntu-latest
226
258
env :
227
259
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -238,13 +270,13 @@ jobs:
238
270
echo "STATUS=${{ needs.run_models_gpu.result }}" >> $GITHUB_ENV
239
271
fi
240
272
241
- - name : Update run's status
273
+ - name : Update PR commit statuses
242
274
run : |
243
275
echo "${{ needs.run_models_gpu.result }}"
244
276
echo "${{ env.STATUS }}"
245
277
gh api \
246
278
--method POST \
247
279
-H "Accept: application/vnd.github+json" \
248
280
-H "X-GitHub-Api-Version: 2022-11-28" \
249
- repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
281
+ repos/${{ github.repository }}/statuses/${{ needs.get-sha.outputs.PR_HEAD_SHA }} \
250
282
-f "target_url=$GITHUB_RUN_URL" -f "state=${{ env.STATUS }}" -f "description=Slow CI job" -f "context=pytest/custom-tests"
0 commit comments