-
Notifications
You must be signed in to change notification settings - Fork 0
221 lines (197 loc) · 8.25 KB
/
Copy pathrelease.yml
File metadata and controls
221 lines (197 loc) · 8.25 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
217
218
219
220
221
name: release
# Triggered by tags matching `v*` (e.g. v0.1.0, v1.2.3-rc.1).
#
# Produces:
# * Cross-platform server binaries attached to the GitHub Release
# (linux-x86_64, linux-aarch64, macos-x86_64, macos-aarch64, windows-x86_64)
# * Multi-arch Docker image on GHCR: ghcr.io/<owner>/geomqtt:<version>
# * A dedicated `upm` branch + `upm/<tag>` tag so Unity users can install via
# https://github.com/<owner>/<repo>.git#upm/v0.1.0
#
# npm publishing of @openfantasymap/geomqtt-* lives in npm.yml so it can
# also be triggered manually for prereleases / republishes without retagging.
#
# GITHUB_TOKEN is provided automatically and is used for GHCR + release upload.
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to simulate (e.g. v0.1.0)'
required: true
env:
CARGO_TERM_COLOR: always
jobs:
# ──────────────────────────────────────────────────────────────────────
# 1. Cross-platform server binaries
# ──────────────────────────────────────────────────────────────────────
binaries:
name: binary — ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive: tar.gz
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
archive: tar.gz
cross_deps: gcc-aarch64-linux-gnu
linker: aarch64-linux-gnu-gcc
- os: macos-14
target: aarch64-apple-darwin
archive: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
archive: zip
ext: .exe
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install Linux cross deps
if: matrix.cross_deps
run: sudo apt-get update && sudo apt-get install -y ${{ matrix.cross_deps }}
- name: Build
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.linker }}
run: cargo build --release --bin geomqtt-server --target ${{ matrix.target }}
- name: Package
id: pkg
shell: bash
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME:-${{ github.event.inputs.tag }}}"
VERSION="${VERSION#v}"
NAME="geomqtt-server-${VERSION}-${{ matrix.target }}"
mkdir -p "dist/$NAME"
cp "target/${{ matrix.target }}/release/geomqtt-server${{ matrix.ext }}" "dist/$NAME/"
cp README.md PROTOCOL.md "dist/$NAME/"
cd dist
if [[ "${{ matrix.archive }}" == "zip" ]]; then
7z a "$NAME.zip" "$NAME"
echo "asset=dist/$NAME.zip" >> "$GITHUB_OUTPUT"
else
tar czf "$NAME.tar.gz" "$NAME"
echo "asset=dist/$NAME.tar.gz" >> "$GITHUB_OUTPUT"
fi
- uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.target }}
path: ${{ steps.pkg.outputs.asset }}
if-no-files-found: error
retention-days: 7
# ──────────────────────────────────────────────────────────────────────
# 2. Multi-arch Docker images to GHCR
# - geomqtt (the server)
# - geomqtt-iss-demo (the examples/iss-demo sidecar)
# ──────────────────────────────────────────────────────────────────────
docker:
name: docker — ${{ matrix.image }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- image: geomqtt
context: .
dockerfile: Dockerfile
- image: geomqtt-iss-demo
context: examples/iss-demo
dockerfile: examples/iss-demo/Dockerfile
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: type=gha,mode=max,scope=${{ matrix.image }}
# ──────────────────────────────────────────────────────────────────────
# 3. Unity UPM branch + tag
# ──────────────────────────────────────────────────────────────────────
unity-upm:
name: unity — upm branch + tag
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: Split clients/geomqtt-unity to upm branch
run: |
set -euo pipefail
VERSION_TAG="${GITHUB_REF_NAME:-${{ github.event.inputs.tag }}}"
VERSION="${VERSION_TAG#v}"
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
# Pin the Unity package's version to the release tag before splitting.
python3 - <<PY
import json
p = json.load(open('clients/geomqtt-unity/package.json'))
p['version'] = '$VERSION'
json.dump(p, open('clients/geomqtt-unity/package.json', 'w'), indent=2)
PY
git add clients/geomqtt-unity/package.json
git commit -m "upm: pin version to $VERSION" --allow-empty
# subtree split captures the upm/ subdirectory as a standalone branch.
git subtree split --prefix=clients/geomqtt-unity -b upm-split
git push origin upm-split:upm --force
git tag "upm/$VERSION_TAG" upm-split
git push origin "upm/$VERSION_TAG"
# ──────────────────────────────────────────────────────────────────────
# 4. GitHub Release with all binary assets attached
# ──────────────────────────────────────────────────────────────────────
github-release:
name: github release
runs-on: ubuntu-latest
needs: [binaries]
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: binary-*
path: dist
merge-multiple: true
- name: List artifacts
run: ls -la dist
- uses: softprops/action-gh-release@v2
with:
files: dist/*
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}