-
-
Notifications
You must be signed in to change notification settings - Fork 8
268 lines (230 loc) · 8.47 KB
/
build_and_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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
name: "Build & Release"
permissions:
# To upload files to GitHub Releases
contents: write
on:
workflow_dispatch:
inputs:
version:
type: string
description: "Version: (e.g. -> v3.1.4-alpha+159)"
release_type:
type: choice
default: none
options:
- none
- patch
- minor
- major
check-to-publish:
type: boolean
workflow_call:
inputs:
version:
type: string
description: "Version: (e.g. -> v3.1.4-alpha+159)"
release_type:
type: string
check-to-publish:
type: boolean
jobs:
validate-input:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate input
id: regex-match
run: |
text="${INPUT_VERSION}";
regex="^v([0-9]+)\.([0-9]+)\.([0-9]+)-?([[:alnum:]]*)\+?([0-9]*)$";
# Perform the regex match
if grep -qE "$regex" <<< "$text"; then
echo "match=true" >> "$GITHUB_OUTPUT";
else
echo "match=false" >> "$GITHUB_OUTPUT";
fi
- name: Fail if don't match regex
if: ${{ inputs.version && steps.regex-match.outputs.match == 'false' }}
run: |
echo "${{inputs.version}} doesn't match regex. Use a version similar to v3.1.4-alpha+159"
exit 1;
get-version:
needs: validate-input
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install jql
if: ${{ !inputs.version }}
uses: taiki-e/install-action@v2
with:
tool: jql
- name: Install cargo-bump
if: ${{ !inputs.version }}
uses: taiki-e/install-action@v2
with:
tool: cargo-bump
- name: Current versions with None
id: current_version
if: ${{ !inputs.version && inputs.release_type == 'none' }}
run: |
version=$(cargo metadata --format-version=1 --no-deps | jql '"packages"|>"version"<|[0]' --raw-string);
echo $version;
echo "current_version=$version" >> "$GITHUB_OUTPUT";
normal_version=v$version
echo $normal_version;
echo "normal_tag_version=$normal_version" >> "$GITHUB_OUTPUT";
- name: New versions using release_type
id: new_version
if: ${{ !inputs.version && inputs.release_type != 'none' }}
run: |
cargo bump ${{ inputs.release_type }};
version=$(cargo metadata --format-version=1 --no-deps | jql '"packages"|>"version"<|[0]' --raw-string);
echo $version;
echo "new_version=$version" >> "$GITHUB_OUTPUT";
normal_version=v$version
echo $normal_version;
echo "normal_tag_version=$normal_version" >> "$GITHUB_OUTPUT";
- name: Versions using tag
id: full_version
if: inputs.version
run: |
tag=${{inputs.version}};
echo $tag;
echo "normal_crate_version=${tag##v} >> GITHUB_OUTPUT";
echo ${tag##v};
outputs:
tag_version: ${{ inputs.version || steps.new_version.outputs.normal_tag_version || steps.current_version.outputs.normal_tag_version }}
crate_version: ${{ steps.full_version.outputs.normal_crate_version || steps.new_version.outputs.new_version || steps.current_version.outputs.current_version }}
run-ci:
needs: validate-input
uses: ./.github/workflows/ci.yaml
cargo-semver-checks:
needs: [run-ci, get-version]
uses: ./.github/workflows/cargo_semver_checks.yaml
with:
bump-version: ${{ needs.get-version.outputs.crate_version }}
add-notice:
needs: [run-ci, get-version]
uses: ./.github/workflows/add_notice.yaml
with:
commit_message: ${{ needs.get-version.outputs.crate_version }}
bump-version:
needs: [cargo-semver-checks, get-version]
uses: ./.github/workflows/bump_version.yaml
with:
crate-version: ${{ needs.get-version.outputs.crate_version }}
update-attribution:
needs: [bump-version, get-version]
uses: ./.github/workflows/cargo_attribution.yaml
with:
commit_message: ${{ needs.get-version.outputs.crate_version }}
create-tag:
needs: [get-version, update-attribution]
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- run: git pull
- uses: mukunku/tag-exists-action@v1.6.0
id: check-tag
with:
tag: ${{ needs.get-version.outputs.tag_version }}
- name: Create tag
if: steps.check-tag.outputs.exists == 'false'
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git tag ${{ needs.get-version.outputs.tag_version }}
git push origin ${{ needs.get-version.outputs.tag_version }}
create-release:
needs: [get-version, create-tag]
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
changelog: CHANGELOG.md
allow-missing-changelog: true
ref: refs/tags/${{ needs.get-version.outputs.tag_version }}
check-if-bin:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install jql
uses: taiki-e/install-action@v2
with:
tool: jql
- name: Searching for bin
id: searching
run: |
result=$(cargo metadata --format-version=1 --no-deps | jql '"packages"|>"targets"<|[0]|>"kind"' | jql '..' -i);
echo "targets=$result" >> "$GITHUB_OUTPUT";
echo kind of targets $result;
- name: print if skip upploading binaries to github release
if: ${{ !contains(steps.searching.outputs.targets, 'bin') }}
run: echo "This job avoid publishing binaries to github releases for libraries crates"
outputs:
is_bin: ${{ contains(steps.searching.outputs.targets, 'bin') }}
build-and-release:
needs: [get-version, create-release, check-if-bin]
if: ${{ needs.check-if-bin.outputs.is_bin == 'true' }}
name: ${{ matrix.target }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- {os: ubuntu-latest, target: x86_64-unknown-linux-gnu, cross: false}
- {os: ubuntu-latest, target: x86_64-unknown-linux-musl, cross: true}
- {os: ubuntu-latest, target: aarch64-unknown-linux-gnu, cross: true}
- {os: ubuntu-latest, target: aarch64-unknown-linux-musl, cross: true}
- {os: ubuntu-latest, target: riscv64gc-unknown-linux-gnu, cross: true}
- {os: windows-latest, target: x86_64-pc-windows-msvc, cross: false}
- {os: windows-latest, target: x86_64-pc-windows-gnu, cross: true}
- {os: windows-latest, target: aarch64-pc-windows-msvc, cross: false}
- {os: macos-latest, target: x86_64-apple-darwin, cross: false}
- {os: macos-latest, target: aarch64-apple-darwin, cross: false}
steps:
- name: Fetch Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get sha-commit from tag
id: get_baseline_sha
shell: bash
run: |
latest_sha=$(git rev-list --tags --max-count=1)
echo "sha_tag=$latest_sha" >> "$GITHUB_OUTPUT";
- name: Checkout source code to specific tag
uses: actions/checkout@v4
with:
ref: ${{ steps.get_baseline_sha.outputs.sha_tag }}
- name: Install stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}
- name: Install cross-compilation tools
if: ${{ matrix.cross }} == 'true'
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- uses: taiki-e/upload-rust-binary-action@v1
with:
bin: ${{ github.event.repository.name }}
target: ${{ matrix.target }}
include: attribution
archive: $bin-$tag-$target
token: ${{ secrets.GITHUB_TOKEN }}
ref: refs/tags/${{ needs.get-version.outputs.tag_version }}
checksum: sha256
publish-crate:
needs: [create-tag]
if: ${{ inputs.check-to-publish }}
uses: ./.github/workflows/publish.yaml
secrets: inherit