@@ -21,33 +21,42 @@ jobs:
2121 # Don't run on forks, where we wouldn't have permissions to add the label anyway.
2222 if : github.repository == 'leanprover-community/mathlib4'
2323 steps :
24- - name : Checkout code
24+ - name : Checkout master branch to build autolabel from
2525 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2626 with :
27- ref : ${{ github.event.pull_request.head.sha }}
28- fetch-depth : 0
27+ ref : master
28+ path : tools
2929 - name : Configure Lean
3030 uses : leanprover/lean-action@c544e89643240c6b398f14a431bcdc6309e36b3e # v1.4.0
3131 with :
3232 auto-config : false
3333 use-github-cache : false
3434 use-mathlib-cache : false
35- - name : lake exe autolabel
35+ lake-package-directory : tools # Building here
36+ - name : Build autolabel from master
37+ working-directory : tools
38+ run : |
39+ lake build autolabel
40+ - name : Checkout branch to label
41+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42+ with :
43+ ref : ${{ github.event.pull_request.head.sha || github.sha }}
44+ fetch-depth : 0
45+ path : pr-branch
46+ - name : Run autolabel
47+ working-directory : pr-branch
3648 run : |
37- # the checkout dance, to avoid a detached head
38- git checkout master
39- git checkout -
40- labels="$(lake exe autolabel)"
49+ labels="$("${GITHUB_WORKSPACE}/tools/.lake/build/bin/autolabel")"
4150 printf '%s\n' "${labels}"
4251 # extract
4352 label="$(printf '%s' "${labels}" | sed -n 's=^::notice::.*#\[\([^,]*\)\].*=\1=p')"
4453 printf 'label: "%s"\n' "${label}"
45- if [ -n "${label}" ]
54+ if [ -n "${label}" ] && [ -n "${PR_NUMBER}" ]
4655 then
4756 printf 'Applying label %s\n' "${label}"
4857 # we use curl rather than octokit/request-action so that the job won't fail
4958 # (and send an annoying email) if the labels don't exist
50- url="https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number } }/labels"
59+ url="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER }/labels"
5160 printf 'url: %s\n' "${url}"
5261 jsonLabel="$(printf '{"labels":["%s"]}' "${label}")"
5362 printf 'jsonLabel: %s\n' "${jsonLabel}"
6271 fi
6372 env :
6473 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
74+ # the PR number could be undefined in workflows triggered by 'push',
75+ # in which case we only log the applicable label and exit
76+ PR_NUMBER : ${{ github.event.pull_request.number }}
0 commit comments