195 lines (192 loc) · 7.04 KB
/
release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Release
on:
workflow_dispatch:
inputs:
version:
type: string
description: The version you intend to release (eg x.y.z)
pull_request:
types: [ closed ]
push:
branches:
- 'release/**'
- 'next/**'
tags:
- v*
release:
types: [ created ]
env:
VERSION: ${{ github.event.inputs.version }}
APP_ID: 251311
jobs:
prepare:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' }}
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{env.APP_ID}}
private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }}
repository: ${{ github.repository }}
permissions: >-
{"contents": "write", "pull_requests": "write"}
- name: Checkout repository code
uses: actions/checkout@v3
with:
token: ${{ steps.generate_token.outputs.token }}
- uses: actions/setup-go@v3
with:
go-version: '^1.19.x'
- name: Install Buf
run: make installbuf
- name: Update Buf Version
run: make updateversion
- name: Create PR
id: cpr
uses: peter-evans/create-pull-request@331d02c7e2104af23ad5974d4d5cbc58a3e6dc77
with:
add-paths: .
commit-message: "Update version to v${{env.VERSION}}"
branch: release/v${{env.VERSION}}
delete-branch: true
title: "Release v${{env.VERSION}}"
body: |
Release prepared for ${{env.VERSION}}
Reminder: Update the changelog
token: ${{ steps.generate_token.outputs.token }}
- name: Slack Notification
run: |
jq --null-input '{ text: "BufCLI Release v${{env.VERSION}} has started: ${{ steps.cpr.outputs.pull-request-url }}" }' \
| curl -sSL -X POST -H 'Content-Type: application/json' -d @- '${{ secrets.SLACK_RELEASE_NOTIFICATION_WEBHOOK }}'
verify:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'release') }}
steps:
- name: Checkout repository code
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Check changelog is modified
run: |
files=`(git fetch origin main:main) && (git diff --name-only main)`
for file in $files; do
if [ "$file" = "CHANGELOG.md" ]; then
exit 0
fi
done
echo ERROR: CHANGELOG has not been updated
exit 1
tag:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release') }}
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{env.APP_ID}}
private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }}
repository: ${{ github.repository }}
permissions: >-
{"contents": "write"}
- name: Set VERSION variable from tag
run: |
VERSION=${{github.head_ref}}
echo "VERSION=${VERSION##*/}" >> $GITHUB_ENV
- name: Checkout repository code
uses: actions/checkout@v3
with:
token: ${{ steps.generate_token.outputs.token }}
fetch-depth: 0
- name: Tag Release
run: |
git config --global user.password ${{ steps.generate_token.outputs.token }}
git tag -d ${{env.VERSION}} 2> /dev/null || echo 'local ref does not exist'
git push origin :${{env.VERSION}} 2> /dev/null || echo 'remote ref does not exist'
git tag ${{env.VERSION}}
git push origin ${{env.VERSION}}
perform:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && startsWith(github.ref_name, 'v') && github.ref_type == 'tag'}}
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{env.APP_ID}}
private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }}
repository: ${{ github.repository }}
permissions: >-
{"contents": "write", "pull_requests": "write"}
- name: Checkout repository code
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set VERSION variable from tag
run: |
echo "VERSION=${{github.ref_name}}" >> $GITHUB_ENV
- uses: actions/setup-go@v3
with:
go-version: '^1.19.x'
- name: Create assets
env:
RELEASE_MINISIGN_PRIVATE_KEY: ${{secrets.RELEASE_MINISIGN_PRIVATE_KEY}}
RELEASE_MINISIGN_PRIVATE_KEY_PASSWORD: ${{secrets.RELEASE_MINISIGN_PRIVATE_KEY_PASSWORD}}
run: make bufrelease
- name: unset keys
run: |
unset RELEASE_MINISIGN_PRIVATE_KEY
unset RELEASE_MINISIGN_PRIVATE_KEY_PASSWORD
- name: Release
id: ghr
uses: softprops/action-gh-release@v1
with:
token: ${{ steps.generate_token.outputs.token }}
generate_release_notes: true # change to the CHANGELOG somehow
files: |
${{github.workspace}}/.build/release/buf/assets/*
- name: Slack Notification
run: |
jq --null-input '{ text: "BufCLI Release v${{env.VERSION}} is complete: ${{ steps.ghr.outputs.url }}" }' \
| curl -sSL -X POST -H 'Content-Type: application/json' -d @- '${{ secrets.SLACK_RELEASE_NOTIFICATION_WEBHOOK }}'
post-release:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{env.APP_ID}}
private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }}
repository: ${{ github.repository }}
permissions: >-
{"contents": "write", "pull_requests": "write"}
- name: Checkout repository code
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set NEXT VERSION variable from tag
run: |
NEXT_VERSION=$(echo ${{github.ref_name}} | awk -F. -v OFS=. '{$NF += 1 ; print}')
echo "NEXT_VERSION=$NEXT_VERSION-dev" >> $GITHUB_ENV
- name: update version
run: make updateversion VERSION=${{env.NEXT_VERSION}}
- name: update home brew badge
run: make updatehomebrewbadge
- name: create PR
uses: peter-evans/create-pull-request@331d02c7e2104af23ad5974d4d5cbc58a3e6dc77
with:
add-paths: .
commit-message: "Back to development"
branch: next/${{env.NEXT_VERSION}}
delete-branch: true
base: main
title: "Return to development"
body: Release complete for ${{github.ref_name}}
token: ${{ steps.generate_token.outputs.token }}