|
1 | 1 | name: Advance Zed |
2 | 2 |
|
| 3 | +concurrency: ${{ github.workflow }} |
| 4 | + |
3 | 5 | # This type must match the event type from Zed. |
4 | 6 | # https://help.github.com/en/actions/reference/events-that-trigger-workflows#external-events-repository_dispatch |
5 | 7 | # These events only trigger on the GitHub default branch. |
6 | 8 | on: |
7 | 9 | repository_dispatch: |
8 | 10 | types: [zed-pr-merged] |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + zed_ref: |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + |
| 17 | +env: |
| 18 | + branch: advance-zed-${{ github.event.client_payload.merge_commit_sha || inputs.zed_ref }} |
| 19 | + zed_ref: ${{ github.event.client_payload.merge_commit_sha || inputs.zed_ref }} |
| 20 | + |
9 | 21 | jobs: |
10 | | - advance-zed: |
11 | | - name: Advance Zed |
| 22 | + create-branch: |
12 | 23 | runs-on: ubuntu-latest |
13 | | - timeout-minutes: 60 |
14 | 24 | steps: |
15 | | - # Only one of these should run at a time, and the checkout of brimcap |
16 | | - # has to be in the "protected section". This will poll every 60s |
17 | | - # forever. It will be timed out based on any change to |
18 | | - # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes |
19 | | - # It is not possible to time out this step and fail. It's only |
20 | | - # possible to time out this step and continue. |
21 | | - - name: Turnstyle |
22 | | - uses: softprops/turnstyle@v0.1.2 |
23 | | - env: |
24 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
25 | | - |
26 | | - # Since we intend to push, we must have a a writable token and |
27 | | - # minimal git config settings to create commits. |
28 | 25 | - uses: actions/checkout@v3 |
29 | 26 | with: |
30 | | - # ref defaults to github.sha, which is fixed at the time a run |
31 | | - # is triggered. Using github.ref ensures a run that waits in |
32 | | - # the turnstyle action will see any commits pushed by the runs |
33 | | - # that caused it to wait, reducing push failures down below. |
| 27 | + # ref defaults to github.sha, which is fixed at the time a workflow is |
| 28 | + # triggered. Using github.ref ensures that a run that waits for the |
| 29 | + # concurrency group will see any commits pushed by the runs that |
| 30 | + # caused it to wait, reducing push failures down below. |
34 | 31 | ref: ${{ github.ref }} |
35 | | - token: ${{ secrets.PAT_TOKEN }} |
36 | | - - run: git config --local user.email 'automation@brimdata.io' |
37 | | - - run: git config --local user.name 'Brim Automation' |
38 | | - |
39 | | - # This section gets event information. |
40 | | - - run: jq '.' "${GITHUB_EVENT_PATH}" |
41 | | - - name: process pull request event |
42 | | - id: zed_pr |
43 | | - # $GITHUB_EVENT_PATH is the JSON we posted from Zed. |
44 | | - # Variables for other steps get set as described here: |
45 | | - # https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-output-parameter |
46 | | - # |
47 | | - # Rewrite bare PR numbers as Zed PRs (https://github.com/brimdata/brim/issues/797) |
48 | | - run: | |
49 | | - sha="$(jq -r '.client_payload.merge_commit_sha' "${GITHUB_EVENT_PATH}")" |
50 | | - echo "sha=$sha" >> $GITHUB_OUTPUT |
51 | | - branch="$(jq -r '.client_payload.branch' "${GITHUB_EVENT_PATH}")" |
52 | | - echo "branch=$branch" >> $GITHUB_OUTPUT |
53 | | - number="$(jq -r '.client_payload.number' "${GITHUB_EVENT_PATH}")" |
54 | | - echo "number=$number" >> $GITHUB_OUTPUT |
55 | | - title="$(jq -r '.client_payload.title' "${GITHUB_EVENT_PATH}")" |
56 | | - title="$(perl -pe 's,(\W+)(#\d+)(\W+),$1brimdata/zed$2$3,g; s,^(#\d+)(\W+),brimdata/zed$1$2,g; s,(\W+)(#\d+),$1brimdata/zed$2,g; s,^(#\d+)$,brimdata/zed$1,g;' <<< "${title}")" |
57 | | - echo "title=$title" >> $GITHUB_OUTPUT |
58 | | - url="$(jq -r '.client_payload.url' "${GITHUB_EVENT_PATH}")" |
59 | | - echo "url=$url" >> $GITHUB_OUTPUT |
60 | | - user="$(jq -r '.client_payload.user' "${GITHUB_EVENT_PATH}")" |
61 | | - echo "user=$user" >> $GITHUB_OUTPUT |
62 | | -
|
63 | 32 | - uses: actions/setup-go@v3 |
64 | 33 | with: |
65 | 34 | go-version-file: go.mod |
66 | | - |
67 | | - - name: Update Zed |
68 | | - run: | |
69 | | - go get -d github.com/brimdata/zed@${{ steps.zed_pr.outputs.sha }} |
70 | | - go mod tidy |
71 | | -
|
72 | | - - name: Create branch |
73 | | - id: createBranch |
74 | | - run: | |
75 | | - branch="upgrade-zed-${{ steps.zed_pr.outputs.number }}" |
76 | | - echo "branch=$branch" >> $GITHUB_OUTPUT |
77 | | - git branch -m $branch |
78 | | - git commit -a -m 'upgrade Zed to ${{ github.event.client_payload.merge_commit_sha }}' |
79 | | - git push -f -u origin $branch |
80 | | -
|
81 | | - - name: Dispatch CI workflow |
82 | | - run: | |
83 | | - cat <<EOF > payload.json |
84 | | - { |
85 | | - "ref": "${{ steps.createBranch.outputs.branch }}", |
86 | | - "inputs": { |
87 | | - "title": "${{ steps.zed_pr.outputs.title }}", |
88 | | - "user": "${{ steps.zed_pr.outputs.user }}", |
89 | | - "url": "${{ steps.zed_pr.outputs.url }}", |
90 | | - "number": "${{ steps.zed_pr.outputs.number }}" |
91 | | - } |
92 | | - } |
93 | | - EOF |
94 | | - curl -XPOST \ |
95 | | - -u "${{ secrets.PAT_USERNAME }}:${{ secrets.PAT_TOKEN }}" \ |
96 | | - -H "Accept: application/vnd.github.v3+json" \ |
97 | | - -H "Content-Type: application/json" \ |
98 | | - --data @payload.json \ |
99 | | - https://api.github.com/repos/brimdata/brimcap/actions/workflows/ci.yaml/dispatches |
100 | | -
|
| 35 | + - run: go get github.com/brimdata/zed@${{ env.zed_ref }} |
| 36 | + - run: go mod tidy |
| 37 | + - run: git -c user.name='Brim Automation' -c user.email=automation@brimdata.io commit -a -m 'upgrade Zed to ${{ env.zed_ref }}' |
| 38 | + - run: git push origin HEAD:${{ env.branch }} |
| 39 | + ci: |
| 40 | + needs: create-branch |
| 41 | + uses: ./.github/workflows/ci.yaml |
| 42 | + with: |
| 43 | + # This value must match env.branch. (Can't use that here because the env |
| 44 | + # context isn't available). |
| 45 | + ref: advance-zed-${{ github.event.client_payload.merge_commit_sha || inputs.zed_ref }} |
| 46 | + push: |
| 47 | + needs: ci |
| 48 | + runs-on: ubuntu-latest |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v3 |
| 51 | + with: |
| 52 | + ref: ${{ env.branch }} |
| 53 | + - run: git push origin HEAD:${{ github.ref }} |
| 54 | + if: github.event_name != 'workflow_dispatch' |
| 55 | + - run: git push --delete origin ${{ env.branch }} |
0 commit comments