feat: allow token-free compile-only releases

This commit is contained in:
Dandaedre 2026-10-05 11:30:30 +02:00
parent e8625989e0
commit 4f841ec1fa
5 changed files with 79 additions and 13 deletions

View File

@ -54,7 +54,10 @@ Build local artifacts through the package stage with:
rust_realease ./my-tool --compile-only
```
Artifacts and `SHA256SUMS` are written under `dist/release-*/`.
This mode does not require a Gitea token or contact Gitea. Artifacts and
`SHA256SUMS` are written under `dist/release-*/`. A later publication with the
same clean commit and build settings reuses the completed target builds; pass
`--recompile` to rebuild them instead.
## Publish a Gitea release

View File

@ -94,7 +94,7 @@ For repositories whose build scripts need a selected Rust toolchain inside Cross
## Pipeline stages
`--compile-only` runs through the package stage and then stops: it performs host checks, cross-compiles, and writes local artifacts without creating or uploading a release. It is the explicit artifact-build mode and conflicts with `--dry-run`, `--prepare-repo`, and `--stop-after`.
`--compile-only` runs through the package stage and then stops: it performs host checks, cross-compiles, and writes local artifacts without requiring a Gitea token or creating or uploading a release. It is the explicit artifact-build mode and conflicts with `--dry-run`, `--prepare-repo`, and `--stop-after`. For this repository, `./release.sh --compile-only` provides the same token-free path; a later `./release.sh TOKEN_FILE` publication reuses the completed build when its fingerprint still matches.
`--stop-after` can stop at `inspect`, `metadata`, `verify`, `build`, `package`, `release`, `upload`, or `binstall`. `verify` runs host `cargo check` and `cargo test`; `--skip-tests` skips only tests. A successful Cross build from a clean checkout records its Git commit, package, targets, profile, lock mode, container engine, active Rust toolchain, and binary list. A later run with the same inputs reuses those regular binary files from Cargo's target directory; dirty checkouts, changed inputs, missing files, and invalid cache records build in a fresh target directory instead. `--recompile` explicitly bypasses a matching completed build. `release` creates or reuses the Gitea release; `upload` uploads archives and checksums. The final stage downloads assets anonymously for public repositories or with Gitea authentication for private repositories, checks their checksums and archive layout, and runs isolated `cargo-binstall` installs for public targets. `--skip-binstall-test` skips that install check, while retaining download verification.
@ -123,11 +123,11 @@ Normal publication does not create a commit, tag, or push. Existing asset names
Install the publisher from the checkout, then use the repository wrapper. The
wrapper selects this package, publishes both archive and standalone binary
assets, and forwards its token file to `--token-file`:
assets, and forwards its token file to `--token-file` when publishing:
```bash
cargo install --path . --locked
./release.sh ../gitea_token.txt --compile-only
./release.sh --compile-only
./release.sh ../gitea_token.txt --dry-run
./release.sh ../gitea_token.txt
```

View File

@ -3,17 +3,24 @@ set -eu
usage() {
echo "usage: $0 <gitea-token-file> [rust_realease options...]" >&2
echo " $0 --compile-only [rust_realease options...]" >&2
exit 2
}
[ "$#" -ge 1 ] || usage
token_file=$1
shift
if [ ! -f "$token_file" ] || [ ! -r "$token_file" ]; then
echo "token file is not a readable regular file: $token_file" >&2
exit 2
fi
case "$1" in
--compile-only)
token_file=
;;
*)
token_file=$1
shift
if [ ! -f "$token_file" ] || [ ! -r "$token_file" ]; then
echo "token file is not a readable regular file: $token_file" >&2
exit 2
fi
;;
esac
if ! command -v rust_realease >/dev/null 2>&1; then
echo "rust_realease is not installed or not available in PATH" >&2
@ -27,8 +34,10 @@ set -- \
"$repository_dir" \
--package rust_realease \
--artifact-format both \
--token-file "$token_file" \
"$@"
if [ -n "$token_file" ]; then
set -- "$@" --token-file "$token_file"
fi
case "$manifest_version" in
*-*) set -- "$@" --prerelease ;;
esac

View File

@ -44,7 +44,8 @@ fn publisher(project: &Path, fake_bin: &Path, cross_log: &Path, arguments: &[&st
.arg(project)
.args(arguments)
.env("PATH", path)
.env("CROSS_LOG", cross_log))
.env("CROSS_LOG", cross_log)
.env_remove("GITEA_TOKEN"))
}
fn assert_success(output: &Output) -> String {

View File

@ -110,3 +110,56 @@ fn release_wrapper_passes_the_token_file_and_preserves_the_ssh_origin() {
assert!(arguments.lines().any(|argument| argument == "--dry-run"));
assert!(!arguments.lines().any(|argument| argument == "--prerelease"));
}
#[test]
fn release_wrapper_builds_without_a_token_file() {
let temporary = TempDir::new().expect("temporary directory should be created");
let repository = temporary.path().join("repository");
let fake_bin = temporary.path().join("bin");
fs::create_dir_all(&repository).expect("repository directory should be created");
fs::create_dir_all(&fake_bin).expect("fake binary directory should be created");
fs::copy(
Path::new(env!("CARGO_MANIFEST_DIR")).join("release.sh"),
repository.join("release.sh"),
)
.expect("release wrapper should be copied");
fs::write(
repository.join("Cargo.toml"),
"[package]\nname = \"rust_realease\"\nversion = \"0.1.3\"\n",
)
.expect("manifest should be written");
let fake_release = fake_bin.join("rust_realease");
fs::write(
&fake_release,
"#!/bin/sh\nprintf '%s\\n' \"$@\" >\"$OBSERVED_ARGS\"\n",
)
.expect("fake release executable should be written");
for path in [&fake_release, &repository.join("release.sh")] {
let mut permissions = fs::metadata(path)
.expect("script metadata should be readable")
.permissions();
permissions.set_mode(0o755);
fs::set_permissions(path, permissions).expect("script should be executable");
}
let observed_args = temporary.path().join("observed-args.txt");
let path = format!(
"{}:{}",
fake_bin.display(),
env::var("PATH").expect("PATH should be available")
);
let output = run(Command::new(repository.join("release.sh"))
.arg("--compile-only")
.env("PATH", path)
.env("OBSERVED_ARGS", &observed_args)
.env_remove("GITEA_TOKEN"));
assert!(output.status.success());
let arguments =
fs::read_to_string(&observed_args).expect("fake release should record publisher arguments");
assert!(arguments
.lines()
.any(|argument| argument == "--compile-only"));
assert!(!arguments.lines().any(|argument| argument == "--token-file"));
}