-
Notifications
You must be signed in to change notification settings - Fork 3
216 lines (191 loc) · 6.87 KB
/
Copy pathtunnel.yml
File metadata and controls
216 lines (191 loc) · 6.87 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
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
name: Tunnel CI & Release
on:
push:
branches: [main]
tags: ["tunnel-v*"]
paths:
- "tunnel/**"
- ".github/workflows/tunnel.yml"
pull_request:
branches: [main]
paths:
- "tunnel/**"
- ".github/workflows/tunnel.yml"
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"
REGISTRY: ghcr.io
SIDECAR_IMAGE: ${{ github.repository_owner }}/mailcue-relay-sidecar
jobs:
# -----------------------------------------------------------------
# Lint, format check, clippy, tests — single job on the host runner.
# Pinned via tunnel/rust-toolchain.toml (1.95).
# -----------------------------------------------------------------
lint:
name: Rust Lint, Format, Clippy & Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: tunnel
steps:
- uses: actions/checkout@v7
- name: Cache cargo registry & target
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
tunnel/target
key: tunnel-${{ runner.os }}-cargo-${{ hashFiles('tunnel/Cargo.lock') }}
restore-keys: |
tunnel-${{ runner.os }}-cargo-
- name: Install toolchain components
run: |
rustup show active-toolchain
rustup component add rustfmt clippy
- name: Format check
run: cargo fmt --all -- --check
- name: Clippy (deny warnings)
run: cargo clippy --workspace --all-targets --locked -- -D warnings
- name: Test
run: cargo test --workspace --locked
# -----------------------------------------------------------------
# Build static musl binaries for amd64 + arm64 on every push to main
# and every tunnel-v* tag. Releases attach the binaries as assets.
# -----------------------------------------------------------------
build-binaries:
name: Build ${{ matrix.target }} (${{ matrix.bin }})
needs: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
bin:
- mailcue-relay-edge
- mailcue-relay-sidecar
defaults:
run:
working-directory: tunnel
steps:
- uses: actions/checkout@v7
- name: Install cross
run: |
cargo install cross --locked --version ^0.2
- name: Cache cargo registry & target
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
tunnel/target
key: tunnel-${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('tunnel/Cargo.lock') }}
restore-keys: |
tunnel-${{ runner.os }}-cargo-${{ matrix.target }}-
- name: Build (release, static musl)
run: |
cross build --release --locked \
--target ${{ matrix.target }} \
--bin ${{ matrix.bin }}
- name: Stage artifact
run: |
mkdir -p ../dist
ARTIFACT="${{ matrix.bin }}-${{ matrix.target }}"
cp "target/${{ matrix.target }}/release/${{ matrix.bin }}" "../dist/${ARTIFACT}"
(cd ../dist && sha256sum "${ARTIFACT}" > "${ARTIFACT}.sha256")
- uses: actions/upload-artifact@v7
with:
name: ${{ matrix.bin }}-${{ matrix.target }}
path: dist/${{ matrix.bin }}-${{ matrix.target }}*
if-no-files-found: error
retention-days: 14
# -----------------------------------------------------------------
# Tagged release: pull all artifacts, write a combined SHA256SUMS,
# publish a GitHub release that install-edge.sh can download from.
# -----------------------------------------------------------------
release:
name: Publish Release
if: startsWith(github.ref, 'refs/tags/tunnel-v')
needs: build-binaries
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
# Pattern-filter so we only pull the binary artifacts we uploaded
# in the build-binaries job. Without this, `download-artifact`
# also tries to fetch the auxiliary `*.dockerbuild` summary blob
# produced by docker/build-push-action and a transient retry-
# exhausted failure on that side artifact fails the whole job.
- uses: actions/download-artifact@v8
with:
path: dist
pattern: mailcue-relay-*
merge-multiple: true
# Bundle the systemd unit into the release so install-edge.sh can
# fetch it directly from the release URL when the script itself
# is being curl|bash-ed onto a fresh VPS (no local checkout).
- name: Stage systemd unit
run: |
cp tunnel/deploy/systemd/mailcue-relay-edge.service dist/
- name: Combined SHA256SUMS
working-directory: dist
run: |
rm -f SHA256SUMS
# shellcheck disable=SC2035
sha256sum mailcue-relay-* mailcue-relay-edge.service > SHA256SUMS
cat SHA256SUMS
- name: GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
files: |
dist/mailcue-relay-edge-*
dist/mailcue-relay-sidecar-*
dist/mailcue-relay-edge.service
dist/SHA256SUMS
# -----------------------------------------------------------------
# Sidecar Docker image: built from tunnel/deploy/docker/Dockerfile.sidecar
# and pushed to GHCR on main + tunnel-v* tags. Multi-arch via buildx.
# -----------------------------------------------------------------
sidecar-image:
name: Build & Push Sidecar Image
if: github.event_name == 'push'
needs: lint
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v7
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.SIDECAR_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=match,pattern=tunnel-v(.*),group=1
type=sha,prefix=
- uses: docker/build-push-action@v7
with:
context: tunnel
file: tunnel/deploy/docker/Dockerfile.sidecar
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=tunnel-sidecar
cache-to: type=gha,mode=max,scope=tunnel-sidecar