-
-
Notifications
You must be signed in to change notification settings - Fork 1
217 lines (213 loc) · 7.8 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
name: Release
on:
push:
tags:
- "facti/v[0-9]+.[0-9]+.[0-9]+*"
permissions:
contents: write
jobs:
defines:
name: Define variables
runs-on: ubuntu-latest
outputs:
package: ${{ steps.set-variables.outputs.package }}
tag: ${{ steps.set-variables.outputs.tag }}
version: ${{ steps.set-variables.outputs.version }}
is_prerelease: ${{ steps.set-variables.outputs.is_prerelease == 'true' }}
steps:
- name: Set variables
id: set-variables
shell: bash
run: |
tag="${GITHUB_REF_NAME}"
package="${tag%%/*}"
version="${tag#*/}"
is_prerelease="false"
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+.+$ ]]; then
is_prerelease="true"
fi
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
echo "FACTI_TAG=${tag}" >> "$GITHUB_ENV"
echo "package=${package}" >> "$GITHUB_OUTPUT"
echo "FACTI_PACKAGE=${package}" >> "$GITHUB_ENV"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "FACTI_VERSION=${version}" >> "$GITHUB_ENV"
echo "is_prerelease=${is_prerelease}" >> "$GITHUB_OUTPUT"
echo "FACTI_IS_PRERELEASE=${is_prerelease}" >> "$GITHUB_ENV"
echo "Tag: ${tag}"
echo "Package: ${package}"
echo "Version: ${version}"
echo "Is prerelease?: ${is_prerelease}"
create-release:
name: Create Release
needs: defines
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create GitHub release
shell: bash
run: |
gh release create \
--draft \
--prerelease=${{ needs.defines.outputs.is_prerelease }}
--generate-notes \
--title "${{ needs.defines.outputs.version }}" \
--verify-tag \
"${{ github.ref_name }}"
env:
GH_TOKEN: ${{ github.token }}
build-assets:
name: Build assets
needs: []
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Generate manpages
run: cargo xtask-ci man
- name: Generate completions
run: |
mkdir -p target/assets/completion
cargo run --release --package facti -- completion zsh > target/assets/completion/_facti
cargo run --release --package facti -- completion bash > target/assets/completion/facti.bash
cargo run --release --package facti -- completion fish > target/assets/completion/facti.fish
cargo run --release --package facti -- completion powershell > target/assets/completion/_facti.ps1
- name: Upload manpages artifact
uses: actions/upload-artifact@v4
with:
name: manpages
path: target/assets/man
- name: Upload completions artifact
uses: actions/upload-artifact@v4
with:
name: completions
path: target/assets/completion
build-release:
name: Build Release
needs: [defines, create-release, build-assets]
runs-on: ${{ matrix.os }}
env:
CARGO: cargo
REL_FLAGS: "--profile dist"
TARGET_FLAGS: "--target ${{ matrix.target }}"
TARGET_DIR: "./target/${{ matrix.target }}"
RUST_BACKTRACE: 1
strategy:
matrix:
build: [linux, linux-arm, macos, macos-arm, win-msvc]
rust: [stable]
include:
- build: linux
os: ubuntu-latest
target: x86_64-unknown-linux-musl
cross: false
- build: linux
os: ubuntu-latest
target: i686-unknown-linux-musl
cross: true
- build: linux-arm
os: ubuntu-latest
target: aarch64-unknown-linux-musl
cross: true
- build: macos
os: macos-latest
target: x86_64-apple-darwin
cross: false
- build: macos-arm
os: macos-latest
target: aarch64-apple-darwin
cross: false
- build: win-msvc
os: windows-latest
target: x86_64-pc-windows-msvc
cross: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare asset directories
run: |
mkdir -p target/assets/man
mkdir -p target/assets/completion
- name: Download manpages artifact
if: matrix.build != 'win-msvc'
id: manpages
uses: actions/download-artifact@v4
with:
name: manpages
path: taraget/assets/man
- name: Download completions artifact
id: completions
uses: actions/download-artifact@v4
with:
name: completions
path: target/assets/completion
- name: Install packages (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt update
sudo apt install musl-dev musl-tools zstd
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Setup cross
if: matrix.cross == true
shell: bash
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show cargo command
run: |
echo "cross is: ${{ matrix.cross }}"
echo "cargo command is: ${{ env.CARGO }}"
echo "rel flags are: ${{ env.REL_FLAGS }}"
echo "target is: ${{ matrix.target }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
run: ${{ env.CARGO }} build ${{ env.REL_FLAGS }} --all-features --locked --verbose --package facti ${{ env.TARGET_FLAGS }}
- name: Strip release binary (linux, macos)
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "${{ env.TARGET_DIR}}/release/facti"
- name: Build release archives
shell: bash
run: |
dist="target/dist"
mkdir -p "$dist"
staging="facti-${{ needs.defines.outputs.version }}-${{ matrix.target }}"
mkdir -p "$staging"/completion
cp {README.md,LICENSE} "$staging"
cp crates/cli/CHANGELOG.md "$staging"
cp target/assets/completion/* "$staging"/completion
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp "${{ env.TARGET_DIR }}/release/facti.exe" "$staging/"
7z a "$dist/$staging.zip" "$staging"
certutil -hashfile "$dist/$staging.zip" SHA512 > "$dist/$staging.zip.sha512"
echo "ASSET=$dist/$staging.zip" >> $GITHUB_ENV
echo "ASSET_SUM=$dist/$staging.zip.sha512" >> $GITHUB_ENV
else
cp "${{ env.TARGET_DIR }}/release/facti" "$staging/"
mkdir "$staging"/man
cp target/assets/man/* "$staging"/man
tar --zstd -cvf "$dist/$staging.tar.zst" "$staging"
shasum -a 512 "$dist/$staging.tar.zst" > "$dist/$staging.tar.zst.sha512"
echo "ASSET=$dist/$staging.tar.zst" >> $GITHUB_ENV
echo "ASSET_SUM=$dist/$staging.tar.zst.sha512" >> $GITHUB_ENV
fi
- name: Upload release archives
run: gh release upload ${{ github.ref_name }} ${{ env.ASSET }} ${{ env.ASSET_SUM }}
env:
GH_TOKEN: ${{ github.token }}
publish-release:
name: Publish release
needs: [create-release, build-release]
if: needs.create-release.result == 'success' && (needs.build-release.result == 'skipped' || needs.build-release.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Publish release (mark as non-draft)
run: gh release edit ${{ github.ref_name }} --draft=false