219 lines
8.8 KiB
YAML
219 lines
8.8 KiB
YAML
name: release
|
|
|
|
on:
|
|
push:
|
|
tags: ["v*"]
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
CARGO_INCREMENTAL: "0"
|
|
|
|
# Two jobs: `build` compiles untrusted-by-default code and has NO secrets and
|
|
# NO cache; `publish` holds the signing key and only handles built artifacts.
|
|
jobs:
|
|
build:
|
|
runs-on: self-hosted
|
|
env:
|
|
TAG: ${{ github.ref_name }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Preflight (tag, version, branch)
|
|
run: |
|
|
set -euo pipefail
|
|
# Only commits reachable from main may be released.
|
|
git fetch origin main
|
|
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
|
|
echo "::error::tagged commit is not on main, refusing to release"
|
|
exit 1
|
|
fi
|
|
case "$TAG" in v[0-9]*) ;; *) echo "::error::tag '$TAG' is not vX.Y.Z"; exit 1;; esac
|
|
VERSION="${TAG#v}"
|
|
# The first top-level `version =` line in Cargo.toml belongs to [package].
|
|
CARGO_VERSION=$(grep -m1 -E '^version[[:space:]]*=' Cargo.toml | cut -d'"' -f2)
|
|
if [ "$VERSION" != "$CARGO_VERSION" ]; then
|
|
echo "::error::tag version '$VERSION' differs from Cargo.toml version '$CARGO_VERSION'"
|
|
exit 1
|
|
fi
|
|
case "$VERSION" in *-*) CHANNEL=beta;; *) CHANNEL=stable;; esac
|
|
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
|
|
python3 scripts/release/extract_changelog.py "$VERSION" CHANGELOG.md > /dev/null
|
|
echo "releasing $VERSION on channel $CHANNEL"
|
|
|
|
- name: Verify system dependencies
|
|
run: |
|
|
set -euo pipefail
|
|
# The runner is a developer machine (not Debian): never install system packages from CI.
|
|
miss=0
|
|
for t in cmake protoc zip pkg-config python3 curl git x86_64-w64-mingw32-gcc; do
|
|
command -v "$t" >/dev/null || { echo "::error::missing tool: $t"; miss=1; }
|
|
done
|
|
for m in alsa opus libudev gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0 gstreamer-webrtc-1.0 gstreamer-sdp-1.0 openssl xkbcommon wayland-client fontconfig dbus-1; do
|
|
pkg-config --exists "$m" || { echo "::error::missing pkg-config module: $m"; miss=1; }
|
|
done
|
|
[ "$miss" = 0 ]
|
|
|
|
- name: Install pinned Rust toolchain into a throwaway home
|
|
run: |
|
|
set -euo pipefail
|
|
# Never reuse a persistent toolchain/config from the shared runner host.
|
|
export CARGO_HOME="$RUNNER_TEMP/cargo" RUSTUP_HOME="$RUNNER_TEMP/rustup"
|
|
mkdir -p "$CARGO_HOME" "$RUSTUP_HOME"
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o "$RUNNER_TEMP/rustup-init.sh"
|
|
sh "$RUNNER_TEMP/rustup-init.sh" -y --no-modify-path --profile minimal --default-toolchain stable
|
|
"$CARGO_HOME/bin/rustup" target add x86_64-pc-windows-gnu
|
|
echo "CARGO_HOME=$CARGO_HOME" >> "$GITHUB_ENV"
|
|
echo "RUSTUP_HOME=$RUSTUP_HOME" >> "$GITHUB_ENV"
|
|
echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Build Linux x86_64
|
|
run: cargo build --release --locked --bin vnox-client
|
|
|
|
- name: Build Windows x86_64 (cross, windows-gnu)
|
|
# screen-capture is Linux only (its dependencies are cfg(target_os = "linux")),
|
|
# so it compiles to nothing on Windows.
|
|
run: cargo build --release --locked --target x86_64-pc-windows-gnu --bin vnox-client
|
|
|
|
- name: Package
|
|
run: |
|
|
set -euo pipefail
|
|
OUT="$PWD/dist"
|
|
mkdir -p "$OUT" stage
|
|
LIN="vnox-client-${VERSION}-linux-x86_64"
|
|
WIN="vnox-client-${VERSION}-windows-x86_64"
|
|
|
|
mkdir -p "stage/$LIN"
|
|
install -m 755 target/release/vnox-client "stage/$LIN/vnox-client"
|
|
cp LICENSE README.md "stage/$LIN/"
|
|
tar -C stage -czf "$OUT/$LIN.tar.gz" "$LIN"
|
|
|
|
mkdir -p "stage/$WIN"
|
|
cp target/x86_64-pc-windows-gnu/release/vnox-client.exe "stage/$WIN/"
|
|
cp LICENSE README.md "stage/$WIN/"
|
|
(cd stage && zip -qr "$OUT/$WIN.zip" "$WIN")
|
|
|
|
cd "$OUT"
|
|
sha256sum "$LIN.tar.gz" "$WIN.zip" > SHA256SUMS
|
|
cat SHA256SUMS
|
|
|
|
- name: Upload build artifacts
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: dist/
|
|
if-no-files-found: error
|
|
|
|
publish:
|
|
needs: build
|
|
runs-on: self-hosted
|
|
env:
|
|
MIN_VERSION: ${{ vars.VNOX_MIN_VERSION }}
|
|
TAG: ${{ github.ref_name }}
|
|
SERVER_URL: ${{ github.server_url }}
|
|
REPO: ${{ github.repository }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Derive version
|
|
run: |
|
|
set -euo pipefail
|
|
VERSION="${TAG#v}"
|
|
case "$VERSION" in *-*) CHANNEL=beta;; *) CHANNEL=stable;; esac
|
|
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
|
|
echo "CHANNEL=$CHANNEL" >> "$GITHUB_ENV"
|
|
echo "LIN_ASSET=vnox-client-${VERSION}-linux-x86_64.tar.gz" >> "$GITHUB_ENV"
|
|
echo "WIN_ASSET=vnox-client-${VERSION}-windows-x86_64.zip" >> "$GITHUB_ENV"
|
|
python3 scripts/release/extract_changelog.py "$VERSION" CHANGELOG.md > "$RUNNER_TEMP/changelog.md"
|
|
|
|
- name: Verify signing dependencies
|
|
run: |
|
|
python3 -I -c 'import cryptography' || { echo "::error::python cryptography is missing"; exit 1; }
|
|
|
|
- name: Download build artifacts
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dist
|
|
path: dist/
|
|
|
|
- name: Verify artifacts match SHA256SUMS
|
|
run: cd dist && sha256sum -c SHA256SUMS
|
|
|
|
- name: Build and sign manifest
|
|
env:
|
|
VNOX_RELEASE_SIGNING_KEY: ${{ secrets.VNOX_RELEASE_SIGNING_KEY }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "${VNOX_RELEASE_SIGNING_KEY:-}" ]; then
|
|
echo "::error::secret VNOX_RELEASE_SIGNING_KEY is not set, refusing to publish an unsigned release"
|
|
exit 1
|
|
fi
|
|
cd dist
|
|
python3 -I ../scripts/release/manifest.py build \
|
|
--version "$VERSION" --channel "$CHANNEL" \
|
|
--min-version "${MIN_VERSION:-0.0.0}" \
|
|
--base-url "$SERVER_URL/$REPO/releases/download/$TAG" \
|
|
--dir . --out manifest.json \
|
|
"$LIN_ASSET=linux-x86_64" "$WIN_ASSET=windows-x86_64"
|
|
python3 -I ../scripts/release/manifest.py sign \
|
|
--manifest manifest.json --out manifest.json.sig
|
|
ls -l
|
|
|
|
- name: Create Gitea release and upload assets
|
|
env:
|
|
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -z "${RELEASE_TOKEN:-}" ]; then
|
|
echo "::error::no API token available (RELEASE_TOKEN / GITHUB_TOKEN)"; exit 1
|
|
fi
|
|
API="$SERVER_URL/api/v1/repos/$REPO"
|
|
AUTH="Authorization: token $RELEASE_TOKEN"
|
|
PRERELEASE=false
|
|
[ "$CHANNEL" = beta ] && PRERELEASE=true
|
|
|
|
python3 - "$TAG" "$PRERELEASE" "$RUNNER_TEMP/changelog.md" > "$RUNNER_TEMP/release.json" <<'PY'
|
|
import json, sys
|
|
tag, pre, body = sys.argv[1], sys.argv[2] == "true", sys.argv[3]
|
|
print(json.dumps({
|
|
"tag_name": tag,
|
|
"name": tag,
|
|
"body": open(body, encoding="utf-8").read(),
|
|
"draft": False,
|
|
"prerelease": pre,
|
|
}))
|
|
PY
|
|
|
|
# Create as a draft first, publish only after every asset is uploaded.
|
|
python3 - "$RUNNER_TEMP/release.json" <<'PY'
|
|
import json, sys
|
|
p = sys.argv[1]
|
|
d = json.load(open(p))
|
|
d["draft"] = True
|
|
json.dump(d, open(p, "w"))
|
|
PY
|
|
|
|
HTTP=$(curl -sS -o "$RUNNER_TEMP/resp.json" -w '%{http_code}' -X POST "$API/releases" \
|
|
-H "$AUTH" -H 'Content-Type: application/json' --data-binary "@$RUNNER_TEMP/release.json")
|
|
if [ "$HTTP" != 201 ]; then
|
|
echo "::error::release creation failed (HTTP $HTTP)"; cat "$RUNNER_TEMP/resp.json"; exit 1
|
|
fi
|
|
ID=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["id"])' "$RUNNER_TEMP/resp.json")
|
|
|
|
for f in dist/*; do
|
|
name=$(basename "$f")
|
|
echo "uploading $name"
|
|
HTTP=$(curl -sS -o "$RUNNER_TEMP/up.json" -w '%{http_code}' -X POST \
|
|
"$API/releases/$ID/assets?name=$name" -H "$AUTH" -F "attachment=@$f")
|
|
if [ "$HTTP" != 201 ]; then
|
|
echo "::error::upload of $name failed (HTTP $HTTP)"; cat "$RUNNER_TEMP/up.json"; exit 1
|
|
fi
|
|
done
|
|
|
|
HTTP=$(curl -sS -o "$RUNNER_TEMP/pub.json" -w '%{http_code}' -X PATCH "$API/releases/$ID" \
|
|
-H "$AUTH" -H 'Content-Type: application/json' -d '{"draft": false}')
|
|
if [ "$HTTP" != 200 ]; then
|
|
echo "::error::publishing release failed (HTTP $HTTP)"; cat "$RUNNER_TEMP/pub.json"; exit 1
|
|
fi
|
|
echo "release published: $SERVER_URL/$REPO/releases/tag/$TAG"
|