-
Notifications
You must be signed in to change notification settings - Fork 2
252 lines (214 loc) · 8.78 KB
/
release.yml
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
name: release
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+*"
env:
CARGO_TERM_COLOR: always
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
WUKONG_HONEYCOMB_API_KEY: ${{ secrets.WUKONG_HONEYCOMB_API_KEY }}
jobs:
tag-name:
name: Get Version Name
runs-on: ubuntu-22.04
outputs:
wukong_version: ${{ env.WUKONG_VERSION }}
steps:
- name: Get the release version from the tag
shell: bash
if: env.WUKONG_VERSION == ''
run: |
TAG_NAME=${{ github.ref }}
echo "WUKONG_VERSION=${TAG_NAME#refs/tags/}" >> $GITHUB_ENV
echo "version is: ${{ env.WUKONG_VERSION }}"
build-release:
name: ${{ matrix.job.name }} (${{ matrix.job.target }})
needs: [tag-name]
strategy:
fail-fast: false
matrix:
rust: [stable]
job:
- {
name: "macOS-arm",
target: aarch64-apple-darwin,
os: macos-latest,
}
- { name: "macOS-x86", target: x86_64-apple-darwin, os: macos-latest }
- {
name: "linux-x86",
target: x86_64-unknown-linux-gnu,
os: ubuntu-22.04,
use-cross: true,
}
- {
name: "linux-x86-musl",
target: x86_64-unknown-linux-musl,
os: ubuntu-22.04,
use-cross: true,
}
runs-on: ${{ matrix.job.os }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
target: ${{ matrix.job.target }}
components: rustfmt, clippy
toolchain: 1.81.0
- name: Install protoc for Linux
if: contains(matrix.job.target, 'linux')
shell: bash
run: |
sudo apt -y update
sudo curl -sSLO https://github.com/protocolbuffers/protobuf/releases/download/v22.3/protoc-22.3-linux-x86_64.zip
sudo unzip protoc-22.3-linux-x86_64.zip -d /usr
which protoc
- name: Install protoc for macOS
if: contains(matrix.job.target, 'apple-darwin')
shell: bash
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install protobuf
protoc --version
- name: Extract crate information
shell: bash
run: |
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' ./cli/Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' ./cli/Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' ./cli/Cargo.toml)" >> $GITHUB_ENV
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' ./cli/Cargo.toml)" >> $GITHUB_ENV
- name: Build Wukong CLI
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: build
args: --locked --features prod --release --target=${{ matrix.job.target }}
- name: Create tarball
id: package
shell: bash
run: |
PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
PKG_BASENAME=${PROJECT_NAME}-v${{ needs.tag-name.outputs.wukong_version }}-${{ matrix.job.name }}
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
BIN_NAME="${{ env.PROJECT_NAME }}"
echo "BIN_NAME=${BIN_NAME}"
echo "PKG_NAME=${PKG_NAME}"
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
mkdir -p "${ARCHIVE_DIR}/completions"
# Binary
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "$ARCHIVE_DIR"
# Completions
cp -r ./cli/completions/{bash,fish,zsh} "$ARCHIVE_DIR/completions"
# base compressed package
pushd "${PKG_STAGING}/" >/dev/null
case ${{ matrix.job.target }} in
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;;
*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
esac;
popd >/dev/null
# Let subsequent steps know where to find the compressed package
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT
- name: "Artifact upload: tarball"
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package.outputs.PKG_NAME }}
path: ${{ steps.package.outputs.PKG_PATH }}
retention-days: 1
publish:
needs: [build-release]
runs-on: ubuntu-22.04
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
pull-requests: write
steps:
# Must perform checkout first, since it deletes the target directory
# before running, and would therefore delete the downloaded artifacts
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Display structure of downloaded files
run: ls -R ./artifacts
- name: Set TAG_NAME
run: |
TAG_NAME=${{ github.ref }}
echo "TAG_NAME=${TAG_NAME#refs/tags/}" >> $GITHUB_ENV
- run: echo 'PRERELEASE=' >> $GITHUB_ENV
- if: |
contains(env.TAG_NAME, 'dev') ||
contains(env.TAG_NAME, 'alpha') ||
contains(env.TAG_NAME, 'beta') ||
contains(env.TAG_NAME, 'nightly')
run: |
echo 'PRERELEASE=--prerelease' >> $GITHUB_ENV
- name: Publish Github Release
env:
DEBUG: api
run: |
gh release create $TAG_NAME $PRERELEASE --title "$TAG_NAME" --target $GITHUB_SHA ./artifacts/*/*.tar.gz
- name: Calculate SHA256 Hash
id: sha256
shell: bash
run: |
VERSION=${{ env.TAG_NAME }}
SHA256_MAC_ARM=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-arm.tar.gz/wukong-v${VERSION}-macOS-arm.tar.gz" | cut -f 1 -d " ")
SHA256_MAC_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-x86.tar.gz/wukong-v${VERSION}-macOS-x86.tar.gz" | cut -f 1 -d " ")
SHA256_LINUX_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-linux-x86.tar.gz/wukong-v${VERSION}-linux-x86.tar.gz"| cut -f 1 -d " ")
echo "${VERSION}"
echo "${SHA256_MAC_ARM}"
echo "${SHA256_MAC_X86}"
echo "${SHA256_LINUX_X86}"
echo "SHA256_MAC_ARM=${SHA256_MAC_ARM}" >> $GITHUB_OUTPUT
echo "SHA256_MAC_X86=${SHA256_MAC_X86}" >> $GITHUB_OUTPUT
echo "SHA256_LINUX_X86=${SHA256_LINUX_X86}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
repository: mindvalley/homebrew-wukong
token: ${{ secrets.HOMEBREW_WUKONG_TOKEN }}
- name: Update Homebrew Formula
shell: bash
run: |
# remove original formula
rm ./wukong.rb
cp ./wukong.rb.template ./wukong.rb
# VERSION=${{ steps.sha256.outputs.VERSION }}
VERSION=${{ env.TAG_NAME }}
SHA256_MAC_ARM=${{ steps.sha256.outputs.SHA256_MAC_ARM }}
SHA256_MAC_X86=${{ steps.sha256.outputs.SHA256_MAC_X86 }}
SHA256_LINUX_X86=${{ steps.sha256.outputs.SHA256_LINUX_X86 }}
# SHA256_MAC_ARM=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-arm.tar.gz/wukong-v${VERSION}-macOS-arm.tar.gz" | cut -f 1 -d " ")
# SHA256_MAC_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-x86.tar.gz/wukong-v${VERSION}-macOS-x86.tar.gz" | cut -f 1 -d " ")
# SHA256_LINUX_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-linux-x86.tar.gz/wukong-v${VERSION}-linux-x86.tar.gz"| cut -f 1 -d " ")
echo "${VERSION}"
echo "${SHA256_MAC_ARM}"
echo "${SHA256_MAC_X86}"
echo "${SHA256_LINUX_X86}"
sed -i "s/__VERSION__/$VERSION/" ./wukong.rb
sed -i "s/__SHA256_MAC_ARM__/$SHA256_MAC_ARM/" ./wukong.rb
sed -i "s/__SHA256_MAC_X86__/$SHA256_MAC_X86/" ./wukong.rb
sed -i "s/__SHA256_LINUX_X86__/$SHA256_LINUX_X86/" ./wukong.rb
- name: Create a new PR to bump version
env:
DEBUG: api
run: |
VERSION=${{ env.TAG_NAME }}
NEW_BRANCH_NAME="release/${VERSION}"
git config --global user.email "[email protected]"
git config --global user.name "Gan Jun Kai"
git branch
git switch -c "${NEW_BRANCH_NAME}"
git add ./wukong.rb
git commit -m "release: bump version -> ${VERSION}"
git push origin "${NEW_BRANCH_NAME}"