|
| 1 | +# This workflow can be used to trigger a rebuild of checks for a certain PR. |
| 2 | +# |
| 3 | +# Automatic triggering is based on PR labeled event. |
| 4 | +# The workflow will check if the new label is "rebuild". |
| 5 | +# It triggers up to 3 check runs taken from the PR and triggers all their jobs again, independent |
| 6 | +# of the previous status. (3 is an arbitrary number, it was just necessary to have more than one in |
| 7 | +# case there are different relevant workflows, e.g. build and codeql. This could be limited to |
| 8 | +# checks marked as "required" or "failed", but it seems better to trigger all). |
| 9 | +# The label "rebuild" is removed after the rebuild is triggered. |
| 10 | +# |
| 11 | +# It can be triggered manually, referencing a PR number (this is mainly for testing purposes). |
1 | 12 | name: Rebuild PR |
2 | 13 |
|
3 | 14 | on: |
|
13 | 24 | description: 'Label to trigger rebuild' |
14 | 25 | required: false |
15 | 26 | default: 'rebuild' |
16 | | - |
| 27 | + |
17 | 28 | # grant permission |
18 | 29 | # - actions:write to allow rerun |
19 | 30 | # - PR:write to allow removing the label |
|
26 | 37 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
27 | 38 | PR_NUMBER: ${{ github.event.number || inputs.pr }} |
28 | 39 | LABEL: ${{ github.event.label.name || inputs.label }} |
| 40 | + BASE: ${{ github.event.pull_request.base.repo.full_name || github.event.repository.full_name }} |
29 | 41 |
|
30 | 42 | jobs: |
31 | 43 | rebuild: |
32 | 44 | runs-on: ubuntu-latest |
33 | 45 | steps: |
34 | 46 | - name: Info |
35 | 47 | env: |
36 | | - GITHUB_EVENT: ${{ toJson(github.event) }} |
| 48 | + GITHUB: ${{ toJson(github) }} |
37 | 49 | run: | |
38 | | - echo "$GITHUB_EVENT" |
39 | | - |
| 50 | + echo "$GITHUB" |
| 51 | +
|
40 | 52 | - name: Checkout |
41 | | - if: github.head_ref == '' |
| 53 | + if: ${{ github.head_ref == '' && env.LABEL == 'rebuild' }} |
42 | 54 | uses: actions/checkout@v4 |
43 | 55 |
|
44 | 56 | - name: Checkout merge |
45 | | - if: github.head_ref != '' |
| 57 | + if: ${{ github.head_ref != '' && env.LABEL == 'rebuild' }} |
46 | 58 | uses: actions/checkout@v4 |
47 | 59 | with: |
48 | 60 | ref: refs/pull/${{github.event.pull_request.number}}/merge |
49 | 61 |
|
50 | 62 | - name: List Jobs |
| 63 | + if: ${{ env.LABEL == 'rebuild' }} |
51 | 64 | run: | |
52 | 65 | echo "Label: ${{ env.LABEL }}" |
53 | 66 | echo "PR: ${{ env.PR_NUMBER }}" |
54 | | - NUMBER=$(gh pr checks ${{ env.PR_NUMBER }} -R holgerfriedrich/openhab-core|grep -v "^rebuild"| sed -E 's#.*/([0-9]+)/job/([0-9]+)#\1#'|grep -ve '[[:alpha:]]'|sort -nu|head -n3|xargs|tr '\n' ' ') |
| 67 | + NUMBER=$(gh pr checks ${{ env.PR_NUMBER }} -R ${{ env.BASE }}|grep -v "^rebuild"| sed -E 's#.*/([0-9]+)/job/([0-9]+)#\1#'|grep -ve '[[:alpha:]]'|sort -nu|head -n3|xargs|tr '\n' ' ') |
55 | 68 | echo "Number of last 3 check jobs: $NUMBER" |
56 | 69 | echo "NUMBER=$NUMBER">>$GITHUB_ENV |
57 | 70 |
|
|
0 commit comments