-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (144 loc) · 5.07 KB
/
Copy pathrelease.yml
File metadata and controls
163 lines (144 loc) · 5.07 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Release tag to publish, for example v0.2.0"
required: true
type: string
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
LINUX_X64_TARGET: x86_64-unknown-linux-musl
permissions:
contents: read
jobs:
build-linux-x64:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@v5
with:
ref: ${{ env.RELEASE_TAG }}
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Install Linux x64 static build target
shell: bash
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y musl-tools binutils file
rustup target add "$LINUX_X64_TARGET"
- name: Validate tag and package versions
id: version
shell: bash
run: |
set -euo pipefail
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
tag="${RELEASE_TAG#v}"
test "$version" = "$tag"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
- run: cargo fmt --check
- run: cargo test --locked
- run: cargo clippy --all-targets --locked -- -D warnings
- run: cargo build --release --locked --target "$LINUX_X64_TARGET"
- name: Package Linux x64 static binaries
shell: bash
run: |
set -euo pipefail
mkdir -p dist/termviz-linux-x64
cp "target/$LINUX_X64_TARGET/release/termviz" dist/termviz-linux-x64/
cp "target/$LINUX_X64_TARGET/release/tvz" dist/termviz-linux-x64/
cp "target/$LINUX_X64_TARGET/release/termviz" dist/termviz
cp "target/$LINUX_X64_TARGET/release/tvz" dist/tvz
cp README.md LICENSE dist/termviz-linux-x64/
file dist/termviz-linux-x64/termviz
file dist/termviz-linux-x64/tvz
if readelf -l dist/termviz-linux-x64/termviz | grep -q "Requesting program interpreter"; then
echo "Expected a static Linux x64 binary without a glibc runtime dependency." >&2
exit 1
fi
if readelf -l dist/termviz-linux-x64/tvz | grep -q "Requesting program interpreter"; then
echo "Expected a static Linux x64 alias binary without a glibc runtime dependency." >&2
exit 1
fi
dist/termviz-linux-x64/termviz --version
dist/termviz-linux-x64/tvz --version
tar -C dist -czf "dist/termviz-linux-x64.tar.gz" termviz-linux-x64
- uses: actions/upload-artifact@v7
with:
name: termviz-linux-x64
path: |
dist/termviz-linux-x64.tar.gz
dist/termviz
dist/tvz
github-release:
runs-on: ubuntu-latest
needs: build-linux-x64
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.build-linux-x64.outputs.tag }}
- uses: actions/download-artifact@v8
with:
name: termviz-linux-x64
path: dist
- name: Create checksums
shell: bash
run: |
set -euo pipefail
cd dist
sha256sum termviz-linux-x64.tar.gz > sha256sums.txt
- name: Extract release notes
id: release-notes
env:
TAG: ${{ needs.build-linux-x64.outputs.tag }}
shell: bash
run: |
set -euo pipefail
version="${TAG#v}"
notes_file="$RUNNER_TEMP/release-notes.md"
awk -v version="$version" '
$0 == "## [" version "]" || $0 ~ "^## \\[" version "\\] - " {
found = 1
next
}
found && /^## / {
exit
}
found {
print
}
' CHANGELOG.md > "$notes_file"
if ! grep -q '[^[:space:]]' "$notes_file"; then
echo "CHANGELOG.md is missing a non-empty section for $TAG." >&2
exit 1
fi
echo "file=$notes_file" >> "$GITHUB_OUTPUT"
- name: Publish GitHub Release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
TAG: ${{ needs.build-linux-x64.outputs.tag }}
NOTES_FILE: ${{ steps.release-notes.outputs.file }}
shell: bash
run: |
set -euo pipefail
if gh release view "$TAG" --repo "$GH_REPO" >/dev/null 2>&1; then
gh release edit "$TAG" --repo "$GH_REPO" --notes-file "$NOTES_FILE"
gh release upload "$TAG" dist/termviz-linux-x64.tar.gz dist/sha256sums.txt --clobber --repo "$GH_REPO"
else
gh release create "$TAG" dist/termviz-linux-x64.tar.gz dist/sha256sums.txt \
--repo "$GH_REPO" \
--verify-tag \
--title "$TAG" \
--notes-file "$NOTES_FILE"
fi