diff --git a/.gitignore b/.gitignore index 4cd1e31..0030d36 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ debug/ target/ coverage/ +dist/ # Generated locally by Cargo Tarpaulin. /lcov.info diff --git a/Cargo.lock b/Cargo.lock index 3592cfd..39843a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1003,7 +1003,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" [[package]] name = "vsg-bridge-ls" -version = "0.3.2" +version = "0.3.2-rc.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 1154faf..c1002e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "vsg-bridge-ls" description = "A very featureless VSG to lsp bridge" -version = "0.3.2" +version = "0.3.2-rc.1" edition = "2021" rust-version = "1.85.1" categories =["developement-tools"] @@ -10,6 +10,11 @@ keywords = ["lsp", "bridge"] repository = "https://proxy.dandaedre.com/gitea/MadGobblins/vsg-bridge-ls" authors = ["dandaedre"] +[package.metadata.binstall] +pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.tgz" +pkg-fmt = "tgz" +bin-dir = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }" + [dependencies] anyhow = "1.0.93" clap = { version = "4.5.21", features = ["derive"] } diff --git a/Jenkinsfile b/Jenkinsfile index 05a8031..c563925 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -154,6 +154,10 @@ pipeline { echo "Running tests..." + sh -n release.sh + sh -n tests/release-wrapper.sh + tests/release-wrapper.sh + cargo test \ --locked \ --all-targets \ diff --git a/README.md b/README.md index 44d9953..9c20adf 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ vsg-bridge-ls --version ``` The version includes both the Cargo release and build commit, for example -`0.3.2+git.0123abcd`, so editor logs can identify the exact binary. +`0.3.2-rc.1+git.0123abcd`, so editor logs can identify the exact binary. ## 3. Configure Helix @@ -130,6 +130,7 @@ process environment variables. See the [debug-mode reference](doc/debug-mode.md) - [Experimental individual rule fixes](doc/experimental-rule-fix.md) - [Debug-information mode](doc/debug-mode.md) - [Development and packaging](doc/development.md) +- [Release procedure](doc/releasing.md) The bridge is deliberately small. Contributions should preserve clean LSP standard output and keep the VSG subprocess boundary explicit. diff --git a/doc/releasing.md b/doc/releasing.md new file mode 100644 index 0000000..08df1f1 --- /dev/null +++ b/doc/releasing.md @@ -0,0 +1,89 @@ +# Release procedure + +`release.sh` is the project-local wrapper for `rust_realease`. It releases the +single Cargo package and binary named `vsg-bridge-ls` using the release profile +and both cargo-binstall `.tgz` archives and standalone binaries. + +The default target matrix is owned by `rust_realease`: + +- `x86_64-unknown-linux-musl`; +- `aarch64-unknown-linux-musl`; and +- `x86_64-pc-windows-gnu`. + +Cross and a working Docker or Podman backend are required for those builds. +`cargo-binstall` is required to verify the archives. Install the publisher from +its authoritative repository if `rust_realease --version` is unavailable: + +```sh +cargo install --git \ + https://proxy.dandaedre.com/gitea/idle-org/rust_realease.git \ + --locked rust_realease +``` + +## Release identity + +The Cargo version is authoritative and produces a `v`-prefixed tag. For +example, version `0.3.2-rc.1` requires tag `v0.3.2-rc.1`. A hyphenated Cargo +version makes the wrapper add `--prerelease` automatically. + +Development uses the SSH origin +`git@git.dandaedre.com:MadGobblins/vsg-bridge-ls.git`. The exact fallback in +`rust-release.toml` directs release creation, downloads, and cargo-binstall to +the public HTTPS repository without changing the Git remote. + +This repository does not currently maintain a changelog file. Release notes and +version selection must therefore be reviewed from the commits since the prior +tag before publication. + +## Token handling + +Pass a readable token file as the first wrapper argument. Only its first line is +exported as `GITEA_TOKEN`; the value is never placed in process arguments. Do +not commit the token or its path. The usual workspace-local invocation is: + +```sh +./release.sh ../gitea_token.txt --dry-run +``` + +The token needs repository read and release write access. This is a public +repository, so generated downloads and cargo-binstall verification can be +performed anonymously after upload. + +## Verification and publication + +Run the wrapper test and a non-mutating publisher inspection first: + +```sh +sh -n release.sh +sh -n tests/release-wrapper.sh +tests/release-wrapper.sh +./release.sh ../gitea_token.txt --dry-run +``` + +The dry run must report the expected package, version, tag, three targets, +artifact names, and HTTPS destination. It does not build, tag, push, create a +release, or upload files. + +A local build and package inspection is also non-publishing: + +```sh +./release.sh ../gitea_token.txt --compile-only +``` + +Inspect the resulting `dist/release-*` directory, `SHA256SUMS`, archives, +executables, and cargo-binstall metadata. Generated `dist/` content is ignored +by Git. + +Before a live run, require a clean checkout, confirm that the expected signed +tag points to `HEAD`, push the commit and tag, and verify the same tag exists on +the remote. Recheck Gitea for an existing release and asset-name collisions. +Then publish explicitly: + +```sh +./release.sh ../gitea_token.txt +``` + +The wrapper itself never edits Git metadata, creates or pushes a tag, or +publishes without `rust_realease`. An existing asset is a hard stop. Never pass +`--replace-assets` unless the exact existing release and assets were inspected +and replacement was separately approved. diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..5874f22 --- /dev/null +++ b/release.sh @@ -0,0 +1,48 @@ +#!/bin/sh +set -eu + +usage() { + echo "usage: $0 [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 + +if ! command -v rust_realease >/dev/null 2>&1; then + echo "rust_realease is not installed or not available in PATH" >&2 + exit 2 +fi + +GITEA_TOKEN= +IFS= read -r GITEA_TOKEN <"$token_file" || : +if [ -z "$GITEA_TOKEN" ]; then + echo "token file is empty: $token_file" >&2 + exit 2 +fi +export GITEA_TOKEN + +repository_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +manifest_version=$(sed -n 's/^version = "\([^"]*\)"/\1/p' \ + "$repository_dir/Cargo.toml" | head -n 1) +if [ -z "$manifest_version" ]; then + echo "could not determine the selected package version" >&2 + exit 2 +fi + +set -- \ + "$repository_dir" \ + --package vsg-bridge-ls \ + --artifact-format both \ + "$@" +case "$manifest_version" in + *-*) set -- "$@" --prerelease ;; +esac + +exec rust_realease "$@" diff --git a/rust-release.toml b/rust-release.toml new file mode 100644 index 0000000..b20c9b0 --- /dev/null +++ b/rust-release.toml @@ -0,0 +1,3 @@ +[[repository.fallbacks]] +origin = "git@git.dandaedre.com:MadGobblins/vsg-bridge-ls.git" +fallback-url = "https://proxy.dandaedre.com/gitea/MadGobblins/vsg-bridge-ls" diff --git a/src/lib.rs b/src/lib.rs index 712c762..8ba7922 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -312,9 +312,9 @@ mod tests { #[test] fn version_includes_source_revision() { assert_eq!(Options::command().get_version(), Some(VERSION)); - assert!(VERSION.starts_with("0.3.2+git.")); + assert!(VERSION.starts_with("0.3.2-rc.1+git.")); assert!(VERSION - .strip_prefix("0.3.2+git.") + .strip_prefix("0.3.2-rc.1+git.") .is_some_and(|revision| revision == "unknown" || (revision.len() == 8 && revision.bytes().all(|byte| byte.is_ascii_hexdigit())))); } diff --git a/src/presentation.rs b/src/presentation.rs index 55d1de1..62b9563 100644 --- a/src/presentation.rs +++ b/src/presentation.rs @@ -219,7 +219,7 @@ mod tests { #[test] fn appends_debug_information_to_hover() { let hover = hover_for_line(&[diagnostic(None, None)], 2); - let hover = append_debug_hover(hover, r#"{"version":"0.3.2","note":"```"}"#); + let hover = append_debug_hover(hover, r#"{"version":"0.3.2-rc.1","note":"```"}"#); let HoverContents::Markup(markup) = hover.contents else { panic!("expected Markdown hover") }; diff --git a/src/server.rs b/src/server.rs index 2ec468e..d21d6c5 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1292,7 +1292,7 @@ mod tests { assert!(report["bridge"]["version"] .as_str() - .is_some_and(|version| version.starts_with("0.3.2+git."))); + .is_some_and(|version| version.starts_with("0.3.2-rc.1+git."))); assert_eq!(report["modes"]["debug"], true); assert_eq!(report["modes"]["experimental_rule_fix"], true); assert_eq!(report["modes"]["experimental_multi_rule_line_fix"], true); diff --git a/tests/release-wrapper.sh b/tests/release-wrapper.sh new file mode 100755 index 0000000..75bbc62 --- /dev/null +++ b/tests/release-wrapper.sh @@ -0,0 +1,131 @@ +#!/bin/sh +set -eu + +fail() { + echo "release wrapper test failed: $*" >&2 + exit 1 +} + +assert_line() { + expected=$1 + file=$2 + line=$3 + actual=$(sed -n "${line}p" "$file") + [ "$actual" = "$expected" ] || + fail "line $line of $file: expected '$expected', got '$actual'" +} + +repository_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +temporary_dir=$(mktemp -d "${TMPDIR:-/tmp}/vsg-bridge-release-test.XXXXXX") +trap 'chmod -R u+rw "$temporary_dir" 2>/dev/null || :; rm -rf "$temporary_dir"' EXIT HUP INT TERM + +fake_bin="$temporary_dir/fake-bin" +capture="$temporary_dir/capture" +mkdir -p "$fake_bin" "$capture" + +cat >"$fake_bin/rust_realease" <<'EOF' +#!/bin/sh +set -eu +: "${RELEASE_TEST_CAPTURE:?}" +printf '%s\n' "${GITEA_TOKEN-}" >"$RELEASE_TEST_CAPTURE/token" +: >"$RELEASE_TEST_CAPTURE/arguments" +for argument do + printf '%s\n' "$argument" >>"$RELEASE_TEST_CAPTURE/arguments" +done +if [ -f "$1/rust-release.toml" ]; then + cp "$1/rust-release.toml" "$RELEASE_TEST_CAPTURE/rust-release.toml" +fi +git -C "$1" remote get-url origin >"$RELEASE_TEST_CAPTURE/origin" 2>/dev/null || : +exit "${RELEASE_TEST_EXIT_STATUS:-0}" +EOF +chmod +x "$fake_bin/rust_realease" + +token_file="$temporary_dir/token.txt" +printf '%s\n%s\n' 'wrapper-test-token' 'ignored-second-line' >"$token_file" +output="$temporary_dir/output" +RELEASE_TEST_CAPTURE=$capture PATH="$fake_bin:$PATH" \ + "$repository_dir/release.sh" "$token_file" --dry-run "value with spaces" \ + >"$output" 2>&1 + +assert_line 'wrapper-test-token' "$capture/token" 1 +assert_line "$repository_dir" "$capture/arguments" 1 +assert_line '--package' "$capture/arguments" 2 +assert_line 'vsg-bridge-ls' "$capture/arguments" 3 +assert_line '--artifact-format' "$capture/arguments" 4 +assert_line 'both' "$capture/arguments" 5 +assert_line '--dry-run' "$capture/arguments" 6 +assert_line 'value with spaces' "$capture/arguments" 7 +assert_line '--prerelease' "$capture/arguments" 8 +[ "$(wc -l <"$capture/arguments" | tr -d ' ')" = 8 ] || + fail 'unexpected extra publisher arguments' +if grep -F 'wrapper-test-token' "$capture/arguments" "$output" >/dev/null; then + fail 'token leaked through publisher arguments or output' +fi +grep -F 'git@git.dandaedre.com:MadGobblins/vsg-bridge-ls.git' \ + "$capture/rust-release.toml" >/dev/null || fail 'SSH fallback origin was not visible' +grep -F 'https://proxy.dandaedre.com/gitea/MadGobblins/vsg-bridge-ls' \ + "$capture/rust-release.toml" >/dev/null || fail 'HTTPS fallback URL was not visible' +assert_line 'git@git.dandaedre.com:MadGobblins/vsg-bridge-ls.git' "$capture/origin" 1 + +stable_repository="$temporary_dir/repository with spaces" +stable_capture="$temporary_dir/stable capture" +mkdir -p "$stable_repository" "$stable_capture" +cp "$repository_dir/release.sh" "$stable_repository/release.sh" +chmod +x "$stable_repository/release.sh" +printf '%s\n' '[package]' 'name = "vsg-bridge-ls"' 'version = "1.2.3"' \ + >"$stable_repository/Cargo.toml" +RELEASE_TEST_CAPTURE=$stable_capture PATH="$fake_bin:$PATH" \ + "$stable_repository/release.sh" "$token_file" "option with spaces" \ + >"$output" 2>&1 +assert_line "$stable_repository" "$stable_capture/arguments" 1 +assert_line 'option with spaces' "$stable_capture/arguments" 6 +if grep -Fx -- '--prerelease' "$stable_capture/arguments" >/dev/null; then + fail 'stable version unexpectedly enabled prerelease mode' +fi + +set +e +RELEASE_TEST_CAPTURE=$capture RELEASE_TEST_EXIT_STATUS=23 PATH="$fake_bin:$PATH" \ + "$repository_dir/release.sh" "$token_file" >"$output" 2>&1 +publisher_status=$? +set -e +[ "$publisher_status" = 23 ] || fail "publisher status became $publisher_status" + +if "$repository_dir/release.sh" >"$output" 2>&1; then + fail 'missing token argument succeeded' +fi +if "$repository_dir/release.sh" "$temporary_dir/missing-token" >"$output" 2>&1; then + fail 'missing token file succeeded' +fi +empty_token="$temporary_dir/empty-token" +: >"$empty_token" +if PATH="$fake_bin:$PATH" "$repository_dir/release.sh" "$empty_token" >"$output" 2>&1; then + fail 'empty token file succeeded' +fi +unreadable_token="$temporary_dir/unreadable-token" +printf '%s\n' 'unreadable' >"$unreadable_token" +chmod 000 "$unreadable_token" +if [ ! -r "$unreadable_token" ]; then + if PATH="$fake_bin:$PATH" "$repository_dir/release.sh" "$unreadable_token" \ + >"$output" 2>&1; then + fail 'unreadable token file succeeded' + fi +fi +chmod 600 "$unreadable_token" + +missing_bin="$temporary_dir/missing-bin" +mkdir "$missing_bin" +if PATH="$missing_bin" "$repository_dir/release.sh" "$token_file" >"$output" 2>&1; then + fail 'missing publisher succeeded' +fi + +invalid_repository="$temporary_dir/invalid-repository" +mkdir "$invalid_repository" +cp "$repository_dir/release.sh" "$invalid_repository/release.sh" +chmod +x "$invalid_repository/release.sh" +printf '%s\n' '[package]' 'name = "vsg-bridge-ls"' >"$invalid_repository/Cargo.toml" +if RELEASE_TEST_CAPTURE=$capture PATH="$fake_bin:$PATH" \ + "$invalid_repository/release.sh" "$token_file" >"$output" 2>&1; then + fail 'manifest without a version succeeded' +fi + +echo 'release wrapper tests passed'