Skip to content

Commit c7fd367

Browse files
committed
update
1 parent adfbca7 commit c7fd367

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

.github/workflows/self-comment-slow-ci.yml

+55-23
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ jobs:
4444
id: set_pr_number
4545
run: echo "PR_NUMBER=${{ env.PR_NUMBER }}" >> "$GITHUB_OUTPUT"
4646

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+
4773
# use a python script to handle this complex logic
4874
# case 1: `run-slow` (auto. infer with limited number of models, but in particular, new model)
4975
# case 2: `run-slow model_1, model_2`
@@ -61,17 +87,6 @@ jobs:
6187
fetch-depth: "0"
6288
ref: "refs/pull/${{needs.get-pr-number.outputs.PR_NUMBER}}/merge"
6389

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-
7590
- name: Get models to test
7691
run: |
7792
python -m pip install GitPython
@@ -84,10 +99,22 @@ jobs:
8499
echo "${{ env.models }}"
85100
echo "models=${{ env.models }}" >> $GITHUB_OUTPUT
86101
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+
87114
create_run:
88115
name: Create run
89116
if: ${{ needs.get-tests.outputs.models != '[]' }}
90-
needs: get-tests
117+
needs: [get-sha, get-tests]
91118
permissions: write-all
92119
runs-on: ubuntu-latest
93120
steps:
@@ -101,15 +128,16 @@ jobs:
101128
--method POST \
102129
-H "Accept: application/vnd.github+json" \
103130
-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 }} \
105132
-f "target_url=$GITHUB_RUN_URL" -f "state=pending" -f "description=Slow CI job" -f "context=pytest/custom-tests"
106133
134+
# (To be removed: only for playing with this PR on `transformers_ci_bot` where no self-hosted runner is available)
107135
run_models_gpu_dummy:
108-
name: Run all tests for the model
136+
name: Run all tests for the model (dummy)
109137
# Triggered only `find_models_to_run` is triggered (label `run-slow` is added) which gives the models to run
110138
# (either a new model PR or via a commit message)
111139
if: ${{ needs.get-tests.outputs.models != '[]' }}
112-
needs: [get-tests, create_run]
140+
needs: [get-pr-number, get-tests, create_run]
113141
strategy:
114142
fail-fast: false
115143
matrix:
@@ -121,13 +149,14 @@ jobs:
121149
shell: bash
122150
run: |
123151
echo "${{ matrix.folders }}"
152+
sleep 10s
124153
125154
run_models_gpu:
126155
name: Run all tests for the model
127156
# Triggered only `find_models_to_run` is triggered (label `run-slow` is added) which gives the models to run
128157
# (either a new model PR or via a commit message)
129158
if: ${{ needs.get-tests.outputs.models != '[]' }}
130-
needs: [get-tests, create_run]
159+
needs: [get-pr-number, get-tests, create_run]
131160
strategy:
132161
fail-fast: false
133162
matrix:
@@ -155,9 +184,12 @@ jobs:
155184
echo "$matrix_folders"
156185
echo "matrix_folders=$matrix_folders" >> $GITHUB_ENV
157186
158-
- name: Update clone
187+
- name: Checkout to PR merge commit
159188
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
161193
162194
- name: Reinstall transformers in edit mode (remove the one installed during docker image build)
163195
working-directory: /transformers
@@ -180,7 +212,7 @@ jobs:
180212
machine_type=${{ matrix.machine_type }}
181213
fi
182214
echo "$machine_type"
183-
echo "machine_type=$machine_type" >> $GITHUB_ENV
215+
echo "machine_type=$machine_type" >> $GITHUB_ENV
184216
185217
- name: Environment
186218
working-directory: /transformers
@@ -219,9 +251,9 @@ jobs:
219251

220252
update_run_status:
221253
name: Update Check Run Status
222-
needs: [run_models_gpu]
254+
needs: [get-sha, create_run, run_models_gpu]
223255
permissions: write-all
224-
if: always()
256+
if: ${{ always() && needs.create_run.result == 'success' }}
225257
runs-on: ubuntu-latest
226258
env:
227259
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -238,13 +270,13 @@ jobs:
238270
echo "STATUS=${{ needs.run_models_gpu.result }}" >> $GITHUB_ENV
239271
fi
240272
241-
- name: Update run's status
273+
- name: Update PR commit statuses
242274
run: |
243275
echo "${{ needs.run_models_gpu.result }}"
244276
echo "${{ env.STATUS }}"
245277
gh api \
246278
--method POST \
247279
-H "Accept: application/vnd.github+json" \
248280
-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 }} \
250282
-f "target_url=$GITHUB_RUN_URL" -f "state=${{ env.STATUS }}" -f "description=Slow CI job" -f "context=pytest/custom-tests"

0 commit comments

Comments
 (0)