CI: the VoelinProtocol deploy key lives for one step, cargo fetch, and the checks run offline
The job checks first that it may hold the key (a runner that reports 3.1.0 or newer, which masks a multi-line secret in the log; on a pull request, a head branch in this repository, asked in the job-level expression and again in the script from the head repository's name), installs the system packages and the toolchain, writes the key to a directory of its own for one step (no ~/.ssh configuration; the step removes the directory itself on any way out but its last line), fetches with `ssh -i` and the committed host key (`cargo fetch --locked`) and deletes it, and a step that always runs deletes it again. The checks action has no input and no secret and every cargo command in it is --offline. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0d44148ef5
commit
cfde421af4
3 files changed
+277
-143
No files matched your search
@@ -1,135 +1,21 @@
|
||||
name: Linux checks
|
||||
description: Shared Linux validation for Gitea CI and release packaging.
|
||||
inputs:
|
||||
protocol-deploy-key:
|
||||
description: >
|
||||
Private half of the read-only deploy key registered on the private
|
||||
Voelin/VoelinProtocol repository (the repository secret
|
||||
VOELIN_PROTOCOL_DEPLOY_KEY, passed in by the workflow: secrets are not
|
||||
visible inside a composite action). The action fails when it is empty.
|
||||
required: true
|
||||
description: >
|
||||
Linux validation for Gitea CI: formatting, Clippy, the build, the tests, the
|
||||
dependency policy, the third-party notices and the release tooling tests. It
|
||||
runs after the job has fetched every dependency (the steps before it in
|
||||
.gitea/workflows/ci.yml: system packages, the Rust toolchain and `cargo fetch`
|
||||
with the read-only deploy key for the private VoelinProtocol repository) and
|
||||
has deleted the key (docs/ci.md, "VoelinProtocol access"). This action has no
|
||||
input and no secret, and every cargo command in it is --offline (or has
|
||||
CARGO_NET_OFFLINE set where a script or a plugin starts cargo): it needs no key
|
||||
and cannot use one, so the build scripts, procedural macros and tests it runs
|
||||
hold none.
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
# The workspace depends on the private VoelinProtocol repository over SSH
|
||||
# (docs/ci.md, "VoelinProtocol access"). First, so that a missing key fails
|
||||
# in seconds and before anything runs cargo.
|
||||
- name: Install the VoelinProtocol deploy key
|
||||
# The key reaches this step through the environment only: never in the
|
||||
# script text, never echoed, no `set -x`.
|
||||
env:
|
||||
PROTOCOL_DEPLOY_KEY: ${{ inputs.protocol-deploy-key }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
if [[ -z "${PROTOCOL_DEPLOY_KEY//[[:space:]]/}" ]]; then
|
||||
echo "::error::The VoelinProtocol deploy key is empty. Set the repository secret VOELIN_PROTOCOL_DEPLOY_KEY to the private key of the read-only deploy key on Voelin/VoelinProtocol (docs/ci.md, VoelinProtocol access). Pull requests from forks get no secrets." >&2
|
||||
exit 1
|
||||
fi
|
||||
for tool in ssh ssh-keygen; do
|
||||
command -v "$tool" > /dev/null || {
|
||||
echo "::error::The job image needs the OpenSSH client: $tool is missing." >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
ssh_dir="$HOME/.ssh"
|
||||
key_file="$ssh_dir/voelin_protocol"
|
||||
mkdir -p "$ssh_dir"
|
||||
chmod 700 "$ssh_dir"
|
||||
|
||||
# Whatever the secret store did to the line ends and the final newline,
|
||||
# OpenSSH needs LF lines, the BEGIN line first and a newline at the end.
|
||||
printf '%s\n' "$PROTOCOL_DEPLOY_KEY" | tr -d '\r' | sed '/^[[:space:]]*$/d' > "$key_file"
|
||||
unset PROTOCOL_DEPLOY_KEY
|
||||
chmod 600 "$key_file"
|
||||
if ! public=$(ssh-keygen -y -f "$key_file" < /dev/null); then
|
||||
rm -f "$key_file"
|
||||
echo "::error::VOELIN_PROTOCOL_DEPLOY_KEY is not an unencrypted OpenSSH or PEM private key." >&2
|
||||
exit 1
|
||||
fi
|
||||
# The fingerprint of the public half, to compare with the deploy key in
|
||||
# the VoelinProtocol settings.
|
||||
printf 'Deploy key installed: %s\n' "$(ssh-keygen -lf - <<< "$public")"
|
||||
|
||||
# The reviewed host key from the repository, never one fetched now.
|
||||
known_hosts="$ssh_dir/known_hosts"
|
||||
touch "$known_hosts"
|
||||
chmod 600 "$known_hosts"
|
||||
[[ -s "${GITHUB_WORKSPACE:-.}/.gitea/known_hosts" ]] || {
|
||||
echo "::error::.gitea/known_hosts is missing from the checkout." >&2
|
||||
exit 1
|
||||
}
|
||||
while IFS= read -r line; do
|
||||
case "$line" in '' | '#'*) continue ;; esac
|
||||
grep -qxF -- "$line" "$known_hosts" || printf '%s\n' "$line" >> "$known_hosts"
|
||||
done < "${GITHUB_WORKSPACE:-.}/.gitea/known_hosts"
|
||||
|
||||
# Use this key, and only this one, for the Gitea server; fail rather than
|
||||
# ask when its host key is unknown or changed. The block goes first: ssh
|
||||
# takes the first value it finds for each option.
|
||||
config="$ssh_dir/config"
|
||||
marker="# VoelinProtocol deploy key (.gitea/actions/checks)"
|
||||
touch "$config"
|
||||
if ! grep -qxF -- "$marker" "$config"; then
|
||||
{
|
||||
cat << EOF
|
||||
$marker
|
||||
Host git.faumaray.com
|
||||
User gitea
|
||||
IdentityFile $key_file
|
||||
IdentitiesOnly yes
|
||||
UserKnownHostsFile $known_hosts
|
||||
StrictHostKeyChecking yes
|
||||
BatchMode yes
|
||||
ConnectTimeout 30
|
||||
|
||||
EOF
|
||||
cat "$config"
|
||||
} > "$config.new"
|
||||
mv "$config.new" "$config"
|
||||
fi
|
||||
chmod 600 "$config"
|
||||
|
||||
# Cargo's built-in git client (libgit2) cannot use IdentityFile; the
|
||||
# system git runs ssh, which reads the config above. `-F` names it
|
||||
# outright: ssh looks for ~/.ssh in the passwd entry's home directory, not
|
||||
# in $HOME, and a job image may set the two apart.
|
||||
{
|
||||
echo "CARGO_NET_GIT_FETCH_WITH_CLI=true"
|
||||
echo "GIT_SSH_COMMAND=ssh -F '$config'"
|
||||
} >> "$GITHUB_ENV"
|
||||
shell: bash
|
||||
- uses: ./.github/actions/system-deps
|
||||
- name: Check read access to VoelinProtocol
|
||||
# The first thing cargo does, with the same git and ssh configuration, so
|
||||
# that a wrong key or a changed host key fails here with a clear message
|
||||
# and not minutes later inside a cargo command.
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if ! GIT_TERMINAL_PROMPT=0 timeout 120 git ls-remote --exit-code \
|
||||
ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git HEAD > /dev/null; then
|
||||
echo "::error::git cannot read Voelin/VoelinProtocol over SSH with the deploy key. 'Permission denied (publickey)' above: the key is not registered on that repository (or is not the one in VOELIN_PROTOCOL_DEPLOY_KEY). 'Host key verification failed': .gitea/known_hosts no longer matches the server (docs/ci.md, VoelinProtocol access)." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Voelin/VoelinProtocol is readable with the deploy key."
|
||||
shell: bash
|
||||
- name: Install pinned Rust toolchain
|
||||
run: |
|
||||
set -euo pipefail
|
||||
export CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
|
||||
export PATH="$CARGO_HOME/bin:$PATH"
|
||||
if ! command -v rustup >/dev/null 2>&1; then
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
||||
sh -s -- -y --profile minimal --default-toolchain none
|
||||
fi
|
||||
if [[ -f "$CARGO_HOME/env" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$CARGO_HOME/env"
|
||||
fi
|
||||
echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
|
||||
rustup toolchain install
|
||||
shell: bash
|
||||
- name: rustfmt (own crates)
|
||||
env:
|
||||
CARGO_NET_OFFLINE: "true"
|
||||
run: |
|
||||
set -euo pipefail
|
||||
packages=$(scripts/own-crates.sh)
|
||||
@@ -137,33 +23,45 @@ runs:
|
||||
cargo fmt "${packages[@]}" --check
|
||||
shell: bash
|
||||
- name: clippy (own crates, deny warnings)
|
||||
env:
|
||||
CARGO_NET_OFFLINE: "true"
|
||||
run: |
|
||||
set -euo pipefail
|
||||
packages=$(scripts/own-crates.sh)
|
||||
read -r -a packages <<< "$packages"
|
||||
cargo clippy "${packages[@]}" --all-targets --no-deps --locked -- -D warnings
|
||||
cargo clippy "${packages[@]}" --all-targets --no-deps --locked --offline -- -D warnings
|
||||
shell: bash
|
||||
- name: clippy (workspace, report warnings)
|
||||
run: cargo clippy --workspace --all-targets --locked
|
||||
run: cargo clippy --workspace --all-targets --locked --offline
|
||||
shell: bash
|
||||
- name: Build
|
||||
run: cargo build --workspace --all-targets --locked
|
||||
run: cargo build --workspace --all-targets --locked --offline
|
||||
shell: bash
|
||||
- name: Test (X11 enabled)
|
||||
run: |
|
||||
# DISPLAY is assigned by xvfb-run, then expanded by the inner shell.
|
||||
# shellcheck disable=SC2016
|
||||
xvfb-run -a bash -c 'VOELIN_X11_TEST_DISPLAY="$DISPLAY" cargo test --workspace --locked'
|
||||
xvfb-run -a bash -c 'VOELIN_X11_TEST_DISPLAY="$DISPLAY" cargo test --workspace --locked --offline'
|
||||
shell: bash
|
||||
- name: Install cargo-deny and cargo-about
|
||||
# The only cargo commands here that go online: they download two tools from
|
||||
# crates.io and build them. They read no manifest of this workspace and
|
||||
# nothing in the job gives them a key.
|
||||
run: |
|
||||
cargo install cargo-deny --locked --version 0.20.2
|
||||
cargo install cargo-about --locked --version 0.9.2 --features cli
|
||||
shell: bash
|
||||
- name: Dependency policy
|
||||
# cargo-deny's own --offline would also stop it from fetching the RustSec
|
||||
# advisory database, which the check needs (from github.com, no key).
|
||||
# CARGO_NET_OFFLINE keeps only the `cargo metadata` it runs offline.
|
||||
env:
|
||||
CARGO_NET_OFFLINE: "true"
|
||||
run: cargo deny --locked --workspace check
|
||||
shell: bash
|
||||
- name: Third-party notices
|
||||
env:
|
||||
CARGO_NET_OFFLINE: "true"
|
||||
run: scripts/notices.sh --check
|
||||
shell: bash
|
||||
- name: Release tooling regressions
|
||||
|
||||
Reference in new issue
Block a user