forked from vacs-project/vacs-data
-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (185 loc) · 6.6 KB
/
release-tools.yml
File metadata and controls
211 lines (185 loc) · 6.6 KB
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
name: Release • Tools
on:
push:
tags:
- "vacs-data-v*"
workflow_dispatch:
inputs:
version:
description: "Version to publish (1.2.3, v1.2.3, or vacs-data-v1.2.3)"
required: true
type: string
ref:
description: "Git ref to build (branch/tag/SHA). Empty = default branch tip."
required: false
default: ""
type: string
permissions: {}
defaults:
run:
shell: bash
working-directory: tools
jobs:
prep:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
version: ${{ steps.vars.outputs.version }}
tag: ${{ steps.vars.outputs.tag }}
draft: ${{ steps.vars.outputs.draft }}
prerelease: ${{ steps.vars.outputs.prerelease }}
release_name: ${{ steps.vars.outputs.release_name }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
ref: ${{ inputs.ref }}
- name: Resolve version & tag
id: vars
shell: bash
run: |
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
RAW="${{ inputs.version }}"
else
RAW="${GITHUB_REF_NAME}" # e.g. vacs-data-v1.2.3
fi
# Extract X.Y.Z from: 1.2.3 | v1.2.3 | vacs-data-v1.2.3 | 1.2.3-rc.1
if [[ "$RAW" =~ ([0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?) ]]; then
VER="${BASH_REMATCH[1]}"
else
echo "Could not parse semver from: $RAW" >&2
exit 1
fi
TAG="vacs-data-v${VER}"
REL_NAME="vacs-data: v${VER}"
# Draft release when manual; published on tag-push
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
DRAFT=true
else
DRAFT=false
fi
# Mark prerelease if version contains a prerelease part (e.g., -rc.1)
if [[ "$VER" =~ -[A-Za-z0-9] ]]; then
PRERELEASE=true
else
PRERELEASE=false
fi
echo "version=$VER" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "draft=$DRAFT" >> "$GITHUB_OUTPUT"
echo "prerelease=$PRERELEASE" >> "$GITHUB_OUTPUT"
echo "release_name=$REL_NAME" >> "$GITHUB_OUTPUT"
generate-changelog:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
release_body: ${{ steps.git-cliff.outputs.content }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Generate a changelog
uses: orhun/git-cliff-action@e16f179f0be49ecdfe63753837f20b9531642772 # v4.7.0
id: git-cliff
with:
config: tools/cliff.toml
args: -vv --latest --no-exec --github-repo ${{ github.repository }}
build:
needs: [prep]
name: Build ${{ matrix.platform }}
runs-on: ${{ matrix.os }}
permissions:
contents: read
attestations: write
id-token: write
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux-x86_64
target: x86_64-unknown-linux-gnu
- os: windows-latest
platform: windows-x86_64
target: x86_64-pc-windows-msvc
- os: macos-latest
platform: macos-aarch64
target: aarch64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
with:
shared-key: ${{ matrix.platform }}
workspaces: "tools -> target"
- name: Set binary name
id: vars
run: |
EXT=""
if [[ "${{ matrix.platform }}" == *"windows"* ]]; then
EXT=".exe"
fi
echo "binary_name=vacs-data$EXT" >> "$GITHUB_OUTPUT"
echo "release_binary_name=vacs-data-${{ needs.prep.outputs.version }}-${{ matrix.platform }}$EXT" >> "$GITHUB_OUTPUT"
- name: Build binary
run: cargo build --release --locked --bin vacs-data --target ${{ matrix.target }}
- name: Rename binary to include platform
run: |
mv "target/${{ matrix.target }}/release/${{ steps.vars.outputs.binary_name }}" "target/${{ matrix.target }}/release/${{ steps.vars.outputs.release_binary_name }}"
- name: Upload binary artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: vacs-data-${{ matrix.platform }}
if-no-files-found: error
retention-days: 30
path: |
tools/target/${{ matrix.target }}/release/${{ steps.vars.outputs.release_binary_name }}
- name: Attest build provenance
if: ${{ !github.event.repository.private || github.event.repository.owner.type == 'Organization' }}
uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0
with:
subject-path: |
tools/target/${{ matrix.target }}/release/${{ steps.vars.outputs.release_binary_name }}
release:
needs: [prep, generate-changelog, build]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Download binaries
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 #v7.0.0
with:
path: dist
pattern: vacs-data-*
merge-multiple: true
- name: Generate checksums
working-directory: dist
run: |
for f in *; do
[[ "$f" == *.sha512 ]] && continue
shasum -a 512 "$f" > "$f.sha512"
done
- name: Create/update GitHub release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
with:
tag_name: ${{ needs.prep.outputs.tag }}
name: ${{ needs.prep.outputs.release_name }}
draft: ${{ needs.prep.outputs.draft }}
prerelease: ${{ needs.prep.outputs.prerelease }}
make_latest: ${{ needs.prep.outputs.draft == 'false' && needs.prep.outputs.prerelease == 'false' }}
body: ${{ needs.generate-changelog.outputs.release_body }}
files: |
dist/**