-
Notifications
You must be signed in to change notification settings - Fork 312
224 lines (202 loc) · 9.43 KB
/
release-tiup.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
name: release-tiup
on:
push:
branches:
- ci/gh-*
- release-*
- master
paths-ignore:
- '**.html'
- '**.md'
- 'CNAME'
- 'LICENSE'
- 'doc/**'
- 'embed/templates/examples/**'
release:
types:
- published
workflow_dispatch:
inputs:
git-ref:
description: git ref
required: true
jobs:
release:
runs-on: ubuntu-20.04
timeout-minutes: 30
outputs:
REL_VER: ${{ steps.build_tiup.outputs.REL_VER }}
strategy:
fail-fast: true
matrix:
os:
- "linux"
- "darwin"
arch:
- "amd64"
- "arm64"
env:
working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
steps:
- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: 1.21.x
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.git-ref || github.event.pull_request.head.sha }}
path: go/src/github.com/${{ github.repository }}
fetch-depth: 0
- name: Check if this is a staging build
id: check_staging
working-directory: ${{ env.working-directory }}
if: github.event_name != 'release'
run: |
STAGING_VER=`git describe --tags | sed 's/-[^-]*$//' | sed -r 's/(-[^-]*$)/-nightly\1/'`
echo ::set-output name=STAGING::$STAGING_VER
- name: Get git ref and commit
id: get_git
working-directory: ${{ env.working-directory }}
# when empty, it will be determined by Makefile
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo ::set-output name=GIT_REF::${GITHUB_REF/refs\/tags\//}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
echo ::set-output name=GIT_REF::${GITHUB_REF/refs\/heads\//}
fi
COMMIT_TIMESTAMP=`git show --no-patch --no-notes --pretty='%aI'`
echo ::set-output name=COMMIT_TIMESTAMP::$COMMIT_TIMESTAMP
- name: Build for ${{ matrix.os }}-${{ matrix.arch }}
id: build_tiup
working-directory: ${{ env.working-directory }}
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
COMMIT: ${GITHUB_SHA}
GITREF: ${{ steps.get_git.outputs.GIT_REF }}
actor: ${{ github.actor }}
event: ${{ github.event_name }}
run: |
export GOPATH=${GITHUB_WORKSPACE}/go
export PATH=$PATH:$GOPATH/bin
if [ ! -z ${{ steps.check_staging.outputs.STAGING }} ]; then
export EXTRA_LDFLAGS="-X \"github.com/${{ github.repository }}/pkg/version.TiUPVerName=${{ steps.check_staging.outputs.STAGING }}\""
export REL_VER=${{ steps.check_staging.outputs.STAGING }}
else
export REL_VER=`git describe --tags --always`
fi
echo ::set-output name=REL_VER::$REL_VER
BUILD_FLAGS='-trimpath -mod=readonly -modcacherw -buildvcs=false' make build && \
BUILD_FLAGS='-trimpath -mod=readonly -modcacherw -buildvcs=false' make ctl && \
echo "Build success."
checksum_file=checksum.${{ matrix.os }}-${{ matrix.arch }}.txt
checksum_header="TiUP $REL_VER (${actor}@${event}) ${{ github.run_id }}"
echo ${checksum_header} > ${checksum_file}
echo "sha256sum:" >> ${checksum_file}
sha256sum bin/* >> ${checksum_file}
echo "b2sum:" >> ${checksum_file}
b2sum bin/* >> ${checksum_file}
cat ${checksum_file}
- name: Package components
id: packaging
working-directory: ${{ env.working-directory }}
env:
ARCH: ${{ matrix.os }}-${{ matrix.arch }}
REL_VER: ${{ steps.build_tiup.outputs.REL_VER }}
run: |
TMP_DIR=`mktemp -d`
export TIUP_HOME="$TMP_DIR/home"
echo ::set-output name=TIUP_HOME::$TIUP_HOME
echo ::set-output name=TIUP_BIN::$TIUP_HOME/bin/tiup
rm -rf $TIUP_HOME && mkdir -p $TIUP_HOME/{bin,keys}
wget -O $TMP_DIR/tiup-linux-amd64.tar.gz -q https://tiup-mirrors.pingcap.com/tiup-linux-amd64.tar.gz
tar -zxf $TMP_DIR/tiup-linux-amd64.tar.gz -C $TIUP_HOME/bin && chmod 755 $TIUP_HOME/bin/tiup
curl -s https://tiup-mirrors.pingcap.com/root.json -o $TIUP_HOME/bin/root.json
mkdir -p package
cp $TIUP_HOME/bin/root.json bin/root.json
# make tar reproducible
TAR="tar --sort=name --mtime=${{ steps.get_git.outputs.COMMIT_TIMESTAMP }} --owner=0 --group=0 --numeric-owner"
# package all binaries to upload to github release asset
${TAR} -czf tiup-${REL_VER}-${ARCH}.tar.gz bin checksum.${{ matrix.os }}-${{ matrix.arch }}.txt
# package each component
# tiup-ctl is destributed with other components, so not packaging / publishing here
${TAR} -C bin -czf package/tiup-${REL_VER}-${ARCH}.tar.gz tiup
${TAR} -C bin -czf package/cluster-${REL_VER}-${ARCH}.tar.gz tiup-cluster
${TAR} -C bin -czf package/dm-${REL_VER}-${ARCH}.tar.gz tiup-dm
${TAR} -C bin -czf package/playground-${REL_VER}-${ARCH}.tar.gz tiup-playground
${TAR} -C bin -czf package/client-${REL_VER}-${ARCH}.tar.gz tiup-client
${TAR} -C bin -czf package/server-${REL_VER}-${ARCH}.tar.gz tiup-server
- name: Publish packages
working-directory: ${{ env.working-directory }}
env:
TIUP_MIRRORS: ${{ secrets.TIUP_SERVER_PROD }}
TIUP_HOME: ${{ steps.packaging.outputs.TIUP_HOME }}
TIUP_BIN: ${{ steps.packaging.outputs.TIUP_BIN }}
REL_VER: ${{ steps.build_tiup.outputs.REL_VER }}
ARCH: ${{ matrix.os }}-${{ matrix.arch }}
tiup_desc: "TiUP is a command-line component management tool that can help to download and install TiDB platform components to the local system"
cluster_desc: "Deploy a TiDB cluster for production"
dm_desc: "Data Migration Platform manager"
playground_desc: "Bootstrap a local TiDB cluster for fun"
client_desc: "Client to connect playground"
server_desc: "TiUP publish/cache server"
run: |
${TIUP_BIN} mirror set ${TIUP_MIRRORS}
echo ${{ secrets.TIUP_COMP_KEY_PINGCAP }} | base64 -d > $TIUP_HOME/keys/private.json
# add a random delay before actually publishing, this can help reduce manifest conflict
# when there are multiple jobs running in parallel
sleep $[ ( $RANDOM % 10 ) ]s
${TIUP_BIN} mirror publish tiup ${REL_VER} package/tiup-${REL_VER}-${ARCH}.tar.gz tiup --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${tiup_desc}"
${TIUP_BIN} mirror publish cluster ${REL_VER} package/cluster-${REL_VER}-${ARCH}.tar.gz tiup-cluster --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${cluster_desc}"
${TIUP_BIN} mirror publish dm ${REL_VER} package/dm-${REL_VER}-${ARCH}.tar.gz tiup-dm --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${dm_desc}" --standalone
${TIUP_BIN} mirror publish playground ${REL_VER} package/playground-${REL_VER}-${ARCH}.tar.gz tiup-playground --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${playground_desc}"
${TIUP_BIN} mirror publish client ${REL_VER} package/client-${REL_VER}-${ARCH}.tar.gz tiup-client --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${client_desc}"
${TIUP_BIN} mirror publish server ${REL_VER} package/server-${REL_VER}-${ARCH}.tar.gz tiup-server --arch ${{ matrix.arch }} --os ${{ matrix.os }} --desc="${server_desc}" --hide --standalone
- name: Upload the all-in-one tarball to GitHub release
uses: ncipollo/release-action@v1
if: github.event_name == 'release'
with:
allowUpdates: true
artifacts: ${{ env.working-directory }}/tiup-${{ steps.build_tiup.outputs.REL_VER }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
artifactContentType: application/gzip
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
prerelease: ${{ github.event.release.prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}
brew-upgrade:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: release
steps:
- name: Check out brew code
uses: actions/checkout@v3
continue-on-error: true
if: github.event_name == 'release'
with:
repository: pingcap/homebrew-brew
persist-credentials: false
ref: master
path: ${{ github.workspace }}/homebrew-brew
fetch-depth: 0
- name: Update and Check tiup version
id: update_version
working-directory: ${{ github.workspace }}/homebrew-brew
continue-on-error: true
if: github.event_name == 'release'
run: |
sed -i 's/version.*/version "${{ needs.release.outputs.REL_VER }}"/g' Formula/tiup.rb
sed -i 's/tag:.*/tag: "${{ needs.release.outputs.REL_VER }}"/g' Formula/tiup.rb
cat Formula/tiup.rb
- name: Push new homebrew
uses: actions-js/push@master
continue-on-error: true
if: github.event_name == 'release'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: ${{ github.workspace }}/homebrew-brew
message: "tiup: ${{ needs.release.outputs.REL_VER }}"
branch: master
repository: pingcap/homebrew-brew