-
Notifications
You must be signed in to change notification settings - Fork 2
209 lines (192 loc) · 7.4 KB
/
releaser.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
name: Release Time
on:
push:
# run only against tags
tags:
- "*"
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)"
required: false
default: false
permissions:
contents: write
issues: write
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check that the Cargo.yaml has been updated with tag
if: ${{ !inputs.debug_enabled }}
run: |
if ! grep -E "version[ ]*=[ ]*.${GITHUB_REF#refs/tags/}." Cargo.toml; then
echo "Cargo.toml version does not match tag, version in current Cargo.toml:"
exit 1
fi
crate_metadata:
name: Extract crate metadata
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract crate information
id: crate_metadata
run: |
cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT
outputs:
name: ${{ steps.crate_metadata.outputs.name }}
version: ${{ steps.crate_metadata.outputs.version }}
maintainer: ${{ steps.crate_metadata.outputs.maintainer }}
homepage: ${{ steps.crate_metadata.outputs.homepage }}
msrv: ${{ steps.crate_metadata.outputs.msrv }}
build:
name: ${{ matrix.job.os }} (${{ matrix.job.target }})
needs: [check, crate_metadata]
env:
BUILD_CMD: cargo
EXTENSION: ""
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
- { os: windows-latest, target: x86_64-pc-windows-msvc }
- { os: macos-latest, target: x86_64-apple-darwin }
- {
target: aarch64-unknown-linux-gnu,
os: ubuntu-latest,
use-cross: true,
}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch all tags
run: git fetch --force --tags
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.job.target }}
- uses: Swatinem/rust-cache@v2
- name: Install cross
if: matrix.job.use-cross
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Overwrite build command env variable
if: matrix.job.use-cross
shell: bash
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
- name: Show version information (Rust, cargo, GCC)
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Add Extension variable on windows
if: matrix.job.os == 'windows-2019'
shell: bash
run: echo "EXTENSION=.exe" >> $GITHUB_ENV
- name: Build on ${{ matrix.job.target }}
shell: bash
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
- uses: actions/upload-artifact@v4
with:
name: snazy-${{ matrix.job.target }}
path: target/${{ matrix.job.target }}/release/snazy${{ env.EXTENSION }}
- name: Set binary name & path
id: bin
shell: bash
run: |
# Figure out suffix of binary
EXE_suffix=""
case ${{ matrix.job.target }} in
*-pc-windows-*) EXE_suffix=".exe" ;;
esac;
# Setup paths
BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
# Let subsequent steps know where to find the binary
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
- name: Create tarball
id: package
shell: bash
run: |
set -x
PKG_suffix=".tar.gz" ;
DIRNAME="${{ matrix.job.target }}"
case ${DIRNAME} in
*-pc-windows-*) PKG_suffix=".zip"; DIRNAME=${DIRNAME/x86_64-pc-windows-msvc/windows} ;;
*aarch64-unknown-linux-gnu) DIRNAME=${DIRNAME/aarch64-unknown-linux-gnu/linux-arm64} ;;
*x86_64-unknown-linux-gnu) DIRNAME=${DIRNAME/x86_64-unknown-linux-gnu/linux-amd64} ;;
*x86_64-apple-darwin) DIRNAME=${DIRNAME/x86_64-apple-darwin/macos} ;;
esac;
PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${DIRNAME}
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
PKG_STAGING="package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
# Binary
cp "${{ steps.bin.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
# README, LICENSE and CHANGELOG files
cp "README.md" "LICENSE" "$ARCHIVE_DIR"
# base compressed package
pushd "${ARCHIVE_DIR}" >/dev/null
case "${{ matrix.job.target }}" in
*-pc-windows-*) 7z -y a "../${PKG_NAME}" * | tail -2 ;;
*) tar czf "../${PKG_NAME}" * ;;
esac;
popd >/dev/null
# Let subsequent steps know where to find the compressed package
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT
if [[ ${{ matrix.job.os }} == 'windows-latest' ]]; then
certutil -hashfile "${PKG_STAGING}/${PKG_NAME}" sha256 | grep -E [A-Fa-f0-9]{64} > "${PKG_STAGING}/${PKG_NAME}.sha256"
else
shasum "${PKG_STAGING}/${PKG_NAME}" > "${PKG_STAGING}/${PKG_NAME}.sha256"
fi
- name: "Artifact upload: tarball"
uses: actions/upload-artifact@master
with:
name: ${{ steps.package.outputs.PKG_NAME }}
path: ${{ steps.package.outputs.PKG_PATH }}
- name: "Artifact upload: tarball sha256"
uses: actions/upload-artifact@master
with:
name: ${{ steps.package.outputs.PKG_NAME }}.sha256
path: ${{ steps.package.outputs.PKG_PATH }}.sha256
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
generate_release_notes: true
files: |
${{ steps.package.outputs.PKG_PATH }}
${{ steps.package.outputs.PKG_PATH }}.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update_packages:
if: startsWith(github.ref, 'refs/tags/')
name: Update Homebrew formula
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Run update-formula.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUR_PRIVATE_KEY: ${{ secrets.AUR_PRIVATE_KEY }}
run: |
misc/packages/update.sh