Files
faumarayandClaude Sonnet 5.5 91dce84b36 release and the images: the agent only for cargo fetch, stopped after the builds, never on a runner that may print the key
release.yml checks the runner version before any step names the secret (same
gate as ci.yml), starts the ssh-agent only on the positive flag, and stops it in
an always() step right after the last build, so the artifact upload and the
release draft have neither the key nor the socket. The four Dockerfiles (linux,
windows, android, the gateway image) give the agent to `RUN cargo fetch --locked`
only; the build after it has no ssh mount and is offline (--offline, and
CARGO_NET_OFFLINE for the Android Gradle task, which starts cargo-ndk).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 02:55:23 +03:00

203 lines
10 KiB
YAML

name: Release
# Complete package set, built on a dedicated trusted host; see docs/ci.md.
# Manual runs upload artifacts only. v* tags also create a draft release.
on:
push:
tags: ["v*"]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: "0"
jobs:
package:
name: packages + draft release
# Native host, not the untrusted-PR CI container: Docker and Flatpak need
# host privileges. Register only for this repository; capacity must be 1.
runs-on: voelin-release
timeout-minutes: 480
defaults:
run:
shell: bash
steps:
- uses: https://github.com/actions/checkout@v4
with:
persist-credentials: false
- name: Check release tools
run: |
set -euo pipefail
command -v docker python3
docker info >/dev/null
# Remove only output owned by this workflow in its checkout.
rm -rf dist
# The workspace depends on the private VoelinProtocol repository over SSH
# (docs/ci.md, "VoelinProtocol access"). The Docker builds fetch it with an
# ssh-agent (`docker build --ssh default`): the key lives in the agent's
# memory, never on disk and never in an image layer, and only the
# `cargo fetch` of each Dockerfile is given the agent (the build that
# follows is --offline and has no ssh mount, so the build scripts and
# procedural macros run without the key). The agent is stopped by the step
# right after the last build, whatever the builds did; the lifetime below
# ends the key anyway if the runner dies first.
#
# A runner prints the `env:` of a step in the job log when the step starts,
# and the runner "gitea-runner-docker" v0.6.1 printed a multi-line secret
# there in clear (2026-10-27; the keys were rotated the next day). It
# carries the same labels as the release runner, so `runs-on` cannot keep
# the job off it: this step decides, before any step names the secret, and
# writes the one positive flag that the agent step asks for. Without the
# flag the job stops here (no package can be built without voelin-identity).
# ci.yml has the same step, with the check of a pull request's head repository
# that a release (tags and manual runs only) does not need.
- name: Check that this runner may hold the VoelinProtocol deploy key
env:
# The oldest runner version known to mask a multi-line secret in the
# log. Lower it only after a canary secret has been shown masked on
# that runner (docs/ci.md, "VoelinProtocol access"). ci.yml has the
# same line.
MIN_MASKING_RUNNER_VERSION: 3.1.0
run: |
set -euo pipefail
version="${GITEA_ACTIONS_RUNNER_VERSION:-}"
name="${RUNNER_NAME:-an unnamed runner}"
if [[ "$version" =~ ^v?([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
oldest="$(printf '%s\n%s\n' "$MIN_MASKING_RUNNER_VERSION" "${BASH_REMATCH[1]}" | sort -V | head -n 1)"
if [[ "$oldest" == "$MIN_MASKING_RUNNER_VERSION" ]]; then
echo "Runner $name reports version $version, which masks secrets in the log (at least $MIN_MASKING_RUNNER_VERSION)."
echo "VOELIN_KEY_ALLOWED=yes" >> "$GITHUB_ENV"
exit 0
fi
fi
echo "::error::The VoelinProtocol deploy key is not given to this job: the runner ($name) reports version '${version:-none}', and only a runner of version $MIN_MASKING_RUNNER_VERSION or newer is known to keep the deploy key out of the job log (gitea-runner-docker v0.6.1 printed it in clear). Run the job again: it may be given another runner." >&2
echo "::error::The job stops here: no package can be built without the private VoelinProtocol repository (docs/ci.md, VoelinProtocol access)." >&2
exit 1
- name: Start ssh-agent with the VoelinProtocol deploy key
# Both lines below ask for the positive flag of the check above: on a
# runner that is not known to mask the secret (or whose expression context
# does not hold what an earlier step wrote to GITHUB_ENV) the step is not
# started and the expression is empty as well, in case a runner prints a
# header anyway. The key reaches the step through the environment only:
# never in the script text, never echoed, no `set -x`.
if: env.VOELIN_KEY_ALLOWED == 'yes'
env:
PROTOCOL_DEPLOY_KEY: ${{ env.VOELIN_KEY_ALLOWED == 'yes' && secrets.VOELIN_PROTOCOL_DEPLOY_KEY || '' }}
run: |
set -euo pipefail
if [[ -z "${PROTOCOL_DEPLOY_KEY//[[:space:]]/}" ]]; then
echo "::error::The repository secret VOELIN_PROTOCOL_DEPLOY_KEY is missing or empty. It holds the private key of the read-only deploy key on Voelin/VoelinProtocol (docs/ci.md, VoelinProtocol access)." >&2
exit 1
fi
for tool in ssh-agent ssh-add; do
command -v "$tool" > /dev/null || { echo "::error::The runner needs the OpenSSH client: $tool is missing." >&2; exit 1; }
done
eval "$(ssh-agent -s -t 32400)" > /dev/null
started=
trap '[[ -n "$started" ]] || ssh-agent -k > /dev/null' EXIT
# LF lines and one final newline, whatever the secret store did.
printf '%s\n' "$PROTOCOL_DEPLOY_KEY" | tr -d '\r' | sed '/^[[:space:]]*$/d' | ssh-add -q -
unset PROTOCOL_DEPLOY_KEY
# The fingerprint of the public half, to compare with the deploy key.
ssh-add -l
{
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK"
echo "SSH_AGENT_PID=$SSH_AGENT_PID"
# Only an agent this job started is stopped at the end.
echo "VOELIN_AGENT_STARTED=1"
} >> "$GITHUB_ENV"
started=1
- name: Linux packages
run: scripts/docker-build.sh linux --progress=plain
- name: Windows packages (MinGW)
run: scripts/docker-build.sh windows --progress=plain
- name: Android debug APK
run: scripts/docker-build.sh android --progress=plain
- name: Android release APK (signed, optional)
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
VOELIN_SIGNING_STORE_PASSWORD: ${{ secrets.VOELIN_SIGNING_STORE_PASSWORD }}
VOELIN_SIGNING_KEY_ALIAS: ${{ secrets.VOELIN_SIGNING_KEY_ALIAS }}
VOELIN_SIGNING_KEY_PASSWORD: ${{ secrets.VOELIN_SIGNING_KEY_PASSWORD }}
run: |
set -euo pipefail
if [[ -z "$KEYSTORE_BASE64" ]]; then
echo "No ANDROID_KEYSTORE_BASE64: debug APK only"
exit 0
fi
: "${VOELIN_SIGNING_STORE_PASSWORD:?Missing Android store password}"
: "${VOELIN_SIGNING_KEY_ALIAS:?Missing Android key alias}"
: "${VOELIN_SIGNING_KEY_PASSWORD:?Missing Android key password}"
umask 077
signing=$(mktemp -d "$RUNNER_TEMP/voelin-signing.XXXXXX")
trap 'rm -rf "$signing"' EXIT
signing=$(cd "$signing" && pwd -P)
[[ "$signing" != "$(pwd -P)/"* ]] || { echo "RUNNER_TEMP must be outside the checkout" >&2; exit 1; }
export SIGNING_ENV="$signing/signing.env"
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$signing/release.jks"
# The Dockerfile sources this with /bin/sh; quote arbitrary secret
# values as POSIX shell data, never interpolate them into code.
python3 - <<'PY'
import os, shlex
from pathlib import Path
names = ("VOELIN_SIGNING_STORE_PASSWORD", "VOELIN_SIGNING_KEY_ALIAS", "VOELIN_SIGNING_KEY_PASSWORD")
Path(os.environ["SIGNING_ENV"]).write_text("".join(f"{name}={shlex.quote(os.environ[name])}\n" for name in names))
PY
scripts/docker-build.sh android --progress=plain --build-arg APK=release \
--build-arg "SIGNING_CACHE_BUST=$(basename "$signing")" \
--secret "id=keystore,src=$signing/release.jks" \
--secret "id=signing,src=$SIGNING_ENV"
- name: Gateway container image
run: |
set -euo pipefail
version=$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/voelin-gateway/Cargo.toml | head -n 1)
test -n "$version"
DOCKER_BUILDKIT=1 docker build --ssh default -f crates/voelin-gateway/Dockerfile -t "tsgw:$version" -t tsgw:latest .
mkdir -p dist/gateway
docker save "tsgw:$version" tsgw:latest | gzip > dist/gateway/tsgw-image.tar.gz
# Right after the builds, the only steps that use the agent, and whatever
# they did (a failed build, a cancelled job): the steps after this one
# (the artifact upload, the release draft with its token) have neither the
# key nor the socket.
- name: Stop the ssh-agent
if: always()
run: |
if [[ -n "${VOELIN_AGENT_STARTED:-}" && -n "${SSH_AGENT_PID:-}" ]]; then
if ssh-agent -k > /dev/null; then
echo "The ssh-agent with the deploy key is stopped."
else
echo "::warning::ssh-agent -k failed; the agent ends by itself when its lifetime (nine hours) is over." >&2
fi
else
echo "No ssh-agent of this job is running."
fi
{
echo "SSH_AUTH_SOCK="
echo "SSH_AGENT_PID="
echo "VOELIN_AGENT_STARTED="
} >> "$GITHUB_ENV"
- name: Collect packages and checksums
run: |
set -euo pipefail
mkdir -p dist/release
for file in dist/{linux,windows,android,gateway}/*; do
[[ -f "$file" && ! -L "$file" ]] || { echo "Missing package: $file" >&2; exit 1; }
name=$(basename "$file")
[[ "$name" != SHA256SUMS* ]] || continue
[[ ! -e "dist/release/$name" ]] || { echo "Duplicate package: $name" >&2; exit 1; }
cp -- "$file" "dist/release/$name"
done
(cd dist/release && sha256sum -- * > SHA256SUMS)
# Gitea-compatible artifact API (Node 20), not stock GitHub artifact v4.
- uses: https://gitea.com/actions/gitea-upload-artifact@81f940d004763f986ba3582c007fd842dd5cb0d7
with:
name: voelin-packages
path: dist/release/
if-no-files-found: error
- name: Draft Gitea release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
env:
# Gitea refuses secret names starting with GITEA_ or GITHUB_.
GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: scripts/gitea-release.sh dist/release