-
Notifications
You must be signed in to change notification settings - Fork 3
179 lines (173 loc) · 5.97 KB
/
release.yml
File metadata and controls
179 lines (173 loc) · 5.97 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
name: Release
on:
push:
tags:
- "v*"
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
packages: write
jobs:
build-binaries:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive: tar.gz
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
archive: tar.gz
use_cross: true
- os: macos-latest
target: x86_64-apple-darwin
archive: tar.gz
use_cross: false
- os: macos-latest
target: aarch64-apple-darwin
archive: tar.gz
use_cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
archive: zip
use_cross: false
# aarch64-pc-windows-msvc removed: cross-compilation from Linux
# fails for crypto crates (ring, aws-lc-sys) that require
# Windows ARM64 SDK headers unavailable in cross containers.
# Re-enable when GitHub provides hosted Windows ARM64 runners.
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
cache-targets: "false"
- uses: mozilla-actions/sccache-action@v0.0.9
- uses: taiki-e/install-action@cross
- name: Build binary (cross)
if: matrix.use_cross
run: cross build --release --target ${{ matrix.target }}
env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
- name: Build binary (native)
if: "!matrix.use_cross"
run: cargo build --release --target ${{ matrix.target }}
env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
- name: Strip binary (Unix)
if: "!matrix.use_cross && runner.os != 'Windows'"
run: strip target/${{ matrix.target }}/release/zeph
- name: Create archive (tar.gz)
if: matrix.archive == 'tar.gz'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../zeph-${{ matrix.target }}.tar.gz zeph
cd ../../..
shasum -a 256 zeph-${{ matrix.target }}.tar.gz > zeph-${{ matrix.target }}.tar.gz.sha256
- name: Create archive (zip)
if: matrix.archive == 'zip'
shell: bash
run: |
cd target/${{ matrix.target }}/release
if [ -f zeph.exe ]; then
7z a ../../../zeph-${{ matrix.target }}.zip zeph.exe
else
7z a ../../../zeph-${{ matrix.target }}.zip zeph
fi
cd ../../..
if command -v shasum &> /dev/null; then
shasum -a 256 zeph-${{ matrix.target }}.zip > zeph-${{ matrix.target }}.zip.sha256
else
sha256sum zeph-${{ matrix.target }}.zip > zeph-${{ matrix.target }}.zip.sha256
fi
- name: Upload archive
uses: actions/upload-artifact@v6
with:
name: binary-${{ matrix.target }}
path: |
zeph-${{ matrix.target }}.tar.gz
zeph-${{ matrix.target }}.tar.gz.sha256
zeph-${{ matrix.target }}.zip
zeph-${{ matrix.target }}.zip.sha256
retention-days: 3
create-release:
name: Create GitHub Release
needs: [build-binaries]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Verify version matches tag
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | grep -m1 'version' | sed 's/.*version = "\(.*\)".*/\1/')
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- name: Download all artifacts
uses: actions/download-artifact@v7
with:
path: artifacts
- name: Create release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
artifacts/**/*.tar.gz
artifacts/**/*.zip
artifacts/**/*.sha256
docker-publish:
name: Publish Docker Image
needs: [build-binaries]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
- name: Download Linux binaries
uses: actions/download-artifact@v7
with:
pattern: binary-*-unknown-linux-gnu
path: artifacts
- name: Extract and prepare binaries
run: |
mkdir -p binaries
tar -xzf artifacts/binary-x86_64-unknown-linux-gnu/zeph-x86_64-unknown-linux-gnu.tar.gz -C binaries
mv binaries/zeph binaries/zeph-amd64
tar -xzf artifacts/binary-aarch64-unknown-linux-gnu/zeph-aarch64-unknown-linux-gnu.tar.gz -C binaries
mv binaries/zeph binaries/zeph-arm64
chmod +x binaries/zeph-*
ls -lh binaries/
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
- uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max