-
Notifications
You must be signed in to change notification settings - Fork 24
175 lines (168 loc) · 5.61 KB
/
release.yml
File metadata and controls
175 lines (168 loc) · 5.61 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version tag to create and release (e.g. v1.2.3)'
required: true
type: string
concurrency:
group: release
cancel-in-progress: false
jobs:
tag:
name: Create and Push Tag
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Validate version format
env:
VERSION: ${{ github.event.inputs.version }}
run: |
if ! echo "$VERSION" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "ERROR: Version must match vX.Y.Z format (e.g. v1.2.3)"
exit 1
fi
- name: Verify tag does not already exist
env:
VERSION: ${{ github.event.inputs.version }}
run: |
if git ls-remote --tags origin "refs/tags/$VERSION" | grep -qF "$VERSION"; then
echo "ERROR: Tag $VERSION already exists on remote. Aborting."
exit 1
fi
- name: Create and push tag
env:
VERSION: ${{ github.event.inputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$VERSION"
git push origin "$VERSION"
test:
name: Test (${{ matrix.os }})
needs: [tag]
if: "!cancelled() && (needs.tag.result == 'success' || needs.tag.result == 'skipped')"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --check
- name: Clippy
run: cargo clippy -- -D warnings
- name: Test
run: cargo test
build:
name: Build (${{ matrix.target }})
needs: test
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- target: aarch64-apple-darwin
runner: macos-latest
- target: x86_64-apple-darwin
runner: macos-latest
- target: x86_64-unknown-linux-musl
runner: ubuntu-latest
- target: aarch64-unknown-linux-musl
runner: ubuntu-24.04-arm
- target: x86_64-pc-windows-msvc
runner: windows-latest
- target: aarch64-pc-windows-msvc
runner: windows-11-arm
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl tools (Linux)
if: contains(matrix.target, 'linux-musl')
run: sudo apt-get install -y musl-tools
- uses: Swatinem/rust-cache@v2
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Rename binary
shell: bash
run: |
EXT=""
if [[ "${{ matrix.target }}" == *windows* ]]; then EXT=".exe"; fi
cp "target/${{ matrix.target }}/release/cship${EXT}" "cship-${{ matrix.target }}${EXT}"
- name: Validate binary
shell: bash
run: |
EXT=""
if [[ "${{ matrix.target }}" == *windows* ]]; then EXT=".exe"; fi
if [[ "${{ matrix.target }}" != *windows* ]]; then file "cship-${{ matrix.target }}"; fi
test -s "cship-${{ matrix.target }}${EXT}" || { echo "ERROR: binary is empty"; exit 1; }
- uses: actions/upload-artifact@v4
with:
name: cship-${{ matrix.target }}
path: cship-${{ matrix.target }}*
release:
name: Publish GitHub Release
needs: build
if: "!cancelled() && needs.build.result == 'success'"
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version || github.ref_name }}
- uses: actions/download-artifact@v4
- name: Extract changelog for this release
shell: bash
env:
TAG: ${{ github.event.inputs.version || github.ref_name }}
run: |
VERSION="${TAG#v}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "ERROR: Invalid version format: $TAG" >&2; exit 1
fi
awk -v ver="[$VERSION]" '
p && /^## \[/ { exit }
/^## / && index($0, ver) { p=1; next }
p { print }
' CHANGELOG.md > /tmp/release-notes.md
if [ ! -s /tmp/release-notes.md ]; then
echo "See commit history for changes in this release." > /tmp/release-notes.md
fi
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.version || github.ref_name }}
files: cship-*/cship-*
body_path: /tmp/release-notes.md
generate_release_notes: true
publish:
name: Publish to crates.io
needs: release
if: "!cancelled() && needs.release.result == 'success'"
runs-on: ubuntu-latest
permissions: {}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.version || github.ref_name }}
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish