-
Notifications
You must be signed in to change notification settings - Fork 1
212 lines (206 loc) · 6.93 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tags:
description: The tags to be released
required: false
type: string
permissions:
id-token: write
contents: write
jobs:
create_release:
name: create release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.generated-tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get latest tag
id: get-latest-tag
run: |
echo "tag=`gh release list -L 1 | cut -f 1`" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version
id: generated-tag
uses: actions/github-script@v6
with:
script: |
if (context.ref.startsWith("refs/tags/")) {
let tag = context.ref.replace("refs/tags/", "");
core.setOutput('tag', tag);
console.log(`This event pushed a tag ${tag}, return directly.`)
return
}
if ("${{ github.event.inputs.tags }}") {
let tag = "${{ github.event.inputs.tags }}";
core.setOutput('tag', tag);
console.log(`This event triggered by workflow_dispatch with a tag ${tag}, return directly.`)
return
}
let tag = "${{ steps.get-latest-tag.outputs.tag }}";
let result = /v(\d+)\.(\d+)\.(\d+)/g.exec(tag);
if (result === null) {
throw `The previous tag ${{ steps.get-latest-tag.outputs.tag }} is invalid, ignoring`;
}
let major = result[1];
let minor = result[2];
let patch = (parseInt(result[3]) + 1).toString();
let next_tag = `v${major}.${minor}.${patch}-nightly`;
console.log(`This event is triggered, return generated ${next_tag}.`)
core.setOutput('tag', next_tag)
- name: Create github release if not exist
# Allow this action failure
continue-on-error: true
# Reference: https://cli.github.com/manual/gh_release_create
run: |
echo "Create a release for ${{ steps.generated-tag.outputs.tag }}"
gh release create ${{ steps.generated-tag.outputs.tag }} --generate-notes -p
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish_macos:
name: macos assets
runs-on: macos-11
needs: [create_release]
strategy:
fail-fast: false
matrix:
arch:
- x86_64
- aarch64
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get target
id: target
run: echo 'target=${{ matrix.arch }}-apple-darwin' >> $GITHUB_OUTPUT
- name: Rust setup
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
- name: Install coreutils for macOS sha256sum
run: brew install coreutils
- name: Cross setup
if: matrix.arch == 'aarch64'
run: |
rustup target add aarch64-apple-darwin
- name: Build Binary
run: |
target=${{ steps.target.outputs.target }}
version=${{ needs.create_release.outputs.version }}
cargo build --release --target=${target}
cp ./target/${target}/release/blooming blooming-${version}-${target}
- name: generate sha256sums
run: |
target=${{ steps.target.outputs.target }}
version=${{ needs.create_release.outputs.version }}
sha256sum blooming-${version}-${target} >> sha256-${version}-${target}.txt
- name: post sha256
uses: actions/upload-artifact@v3
with:
name: sha256sums
path: sha256-${{ needs.create_release.outputs.version }}-${{ steps.target.outputs.target }}.txt
retention-days: 1
- name: Publish Binaries
uses: ./.github/actions/publish_binary
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ needs.create_release.outputs.version }}
target: ${{ steps.target.outputs.target }}
publish_linux:
name: linux assets
runs-on: ubuntu-latest
needs: [create_release]
strategy:
fail-fast: false
matrix:
arch:
- x86_64
platform:
- gnu
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
- name: Get target
id: target
run: echo 'target=${{ matrix.arch }}-unknown-linux-${{ matrix.platform }}' >> $GITHUB_OUTPUT
- name: Rust setup
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
- name: Build Binary
run: |
target=${{ steps.target.outputs.target }}
version=${{ needs.create_release.outputs.version }}
cargo build --release --target=${target}
cp ./target/${target}/release/blooming blooming-${version}-${target}
- name: generate sha256sums
run: |
target=${{ steps.target.outputs.target }}
version=${{ needs.create_release.outputs.version }}
sha256sum blooming-${version}-${target} >> sha256-${version}-${target}.txt
- name: post sha256
uses: actions/upload-artifact@v3
with:
name: sha256sums
path: sha256-${{ needs.create_release.outputs.version }}-${{ steps.target.outputs.target }}.txt
retention-days: 1
- name: Publish Binaries
uses: ./.github/actions/publish_binary
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ needs.create_release.outputs.version }}
target: ${{ steps.target.outputs.target }}
upload-sha256sums-plugin:
needs: [create_release, publish_linux, publish_macos]
runs-on: ubuntu-latest
name: upload-sha256sums
steps:
- name: checkout
uses: actions/checkout@v2
- name: Get Pre-release
uses: cardinalby/git-get-release-action@v1
id: latest_pre_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prerelease: true
latest: true
- name: download sha256sums
uses: actions/download-artifact@v2
with:
name: sha256sums
- shell: bash
run: |
for file in *.txt
do
cat ${file} >> sha256sums.txt
done
- name: upload checksums
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.latest_pre_release.outputs.upload_url }}
asset_path: sha256sums.txt
asset_name: sha256sums.txt
asset_content_type: text/plain