Skip to content

Commit 40eafbc

Browse files
authored
simplify advance-zed.yaml and ci.yaml workflows (#296)
Convert ci.yaml into a reusable workflow and call it from advance-zed.yaml.
1 parent 04b28f1 commit 40eafbc

File tree

2 files changed

+44
-135
lines changed

2 files changed

+44
-135
lines changed

.github/workflows/advance-zed.yaml

Lines changed: 38 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,55 @@
11
name: Advance Zed
22

3+
concurrency: ${{ github.workflow }}
4+
35
# This type must match the event type from Zed.
46
# https://help.github.com/en/actions/reference/events-that-trigger-workflows#external-events-repository_dispatch
57
# These events only trigger on the GitHub default branch.
68
on:
79
repository_dispatch:
810
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+
921
jobs:
10-
advance-zed:
11-
name: Advance Zed
22+
create-branch:
1223
runs-on: ubuntu-latest
13-
timeout-minutes: 60
1424
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.
2825
- uses: actions/checkout@v3
2926
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.
3431
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-
6332
- uses: actions/setup-go@v3
6433
with:
6534
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 }}

.github/workflows/ci.yaml

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ on:
77
- main
88
tags:
99
- v*
10-
workflow_dispatch: # triggered by advance zed workflow
10+
workflow_call:
1111
inputs:
12-
title:
13-
required: true
14-
user:
15-
required: true
16-
url:
17-
required: true
18-
number:
12+
ref:
1913
required: true
14+
type: string
15+
workflow_dispatch:
2016

2117
jobs:
2218
test:
@@ -26,6 +22,8 @@ jobs:
2622
os: [macos-latest, ubuntu-latest, windows-latest]
2723
steps:
2824
- uses: actions/checkout@v3
25+
with:
26+
ref: ${{ inputs.ref || github.sha }}
2927
- uses: actions/setup-go@v3
3028
with:
3129
go-version-file: go.mod
@@ -47,47 +45,3 @@ jobs:
4745
file: build/brimcap-*.zip
4846
file_glob: true
4947
overwrite: true
50-
51-
advance-zed-success:
52-
name: Advance Zed success
53-
if: success() && github.event_name == 'workflow_dispatch'
54-
needs: test
55-
runs-on: ubuntu-latest
56-
steps:
57-
- uses: actions/checkout@v3
58-
with:
59-
token: ${{ secrets.PAT_TOKEN }}
60-
fetch-depth: 0
61-
ref: main
62-
- run: git config --local user.email 'automation@brimdata.io'
63-
- run: git config --local user.name 'Brim Automation'
64-
- name: Commit and push change
65-
run: |
66-
git cherry-pick ${{ github.sha }}
67-
git push
68-
- name: Delete branch
69-
run: git push origin --delete ${{ github.ref }}
70-
71-
advance-zed-failure:
72-
name: Advance Zed failure
73-
if: failure() && github.event_name == 'workflow_dispatch'
74-
needs: test
75-
runs-on: ubuntu-latest
76-
steps:
77-
- uses: actions/checkout@v3
78-
- run: git config --local user.email 'automation@brimdata.io'
79-
- run: git config --local user.name 'Brim Automation'
80-
- name: Create Pull Request for Manual Inspection
81-
uses: peter-evans/create-pull-request@v3.8.2
82-
with:
83-
token: ${{ secrets.GITHUB_TOKEN }}
84-
commit-message: Zed update through "${{ github.event.inputs.title }}" by ${{ github.event.inputs.user }}
85-
title: Zed update through "${{ github.event.inputs.title }}" by ${{ github.event.inputs.user }}
86-
body: |
87-
This is an auto-generated PR with a Zed dependency update needing manual attention. brimdata/zed#${{ github.event.inputs.number }}, authored by @${{ github.event.inputs.user }}, has been merged, however Zed could not be updated automatically. Please see https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} for the original failing run. If a Brimcap update is needed, you may use the branch on this PR to do so.
88-
89-
----
90-
#### ${{ github.event.inputs.title }}
91-
${{ github.event.inputs.body }}
92-
branch: ${{ github.ref }}
93-
base: main

0 commit comments

Comments
 (0)