Files
narratio/scripts/check-release-candidate.sh

96 lines
3.7 KiB
Bash
Executable File

#!/bin/sh
set -eu
script_dir=$(CDPATH= cd "$(dirname "$0")" && pwd -P)
# shellcheck source=release-lib.sh
. "$script_dir/release-lib.sh"
tool_name=check-release-candidate
if [ "$#" -ne 1 ]; then
narratio_release_fail "$tool_name" 'usage: scripts/check-release-candidate.sh VERSION'
fi
release_version=$1
if ! narratio_release_validate_version "$release_version"; then
narratio_release_fail "$tool_name" "invalid stable version: $release_version"
fi
repo_root=$(narratio_release_repo_root "$0") || narratio_release_fail "$tool_name" 'cannot locate repository root'
if ! cd "$repo_root"; then
narratio_release_fail "$tool_name" "cannot enter repository root: $repo_root"
fi
release_note="docs/releases/$release_version.md"
if [ ! -s "$release_note" ]; then
narratio_release_fail "$tool_name" "release note must be nonempty: $release_note"
fi
note_heading=$(sed -n '1p' "$release_note")
if [ "$note_heading" != "# Narratio $release_version" ]; then
narratio_release_fail "$tool_name" "release note must begin with # Narratio $release_version"
fi
for required_heading in '## Summary' '## Compatibility' '## Upgrade' '## Changes'; do
if ! grep -Fqx "$required_heading" "$release_note"; then
narratio_release_fail "$tool_name" "release note is missing required heading: $required_heading"
fi
done
if ! grep -Eq '^module[[:space:]]+gitea\.maximumdirect\.net/eric/narratio[[:space:]]*$' go.mod; then
narratio_release_fail "$tool_name" 'go.mod must declare module gitea.maximumdirect.net/eric/narratio'
fi
for workspace_file in go.work go.work.sum; do
if git ls-files --error-unmatch "$workspace_file" >/dev/null 2>&1; then
narratio_release_fail "$tool_name" "tracked workspace file is not allowed: $workspace_file"
fi
done
if [ -d vendor ]; then
narratio_release_fail "$tool_name" 'vendor directory is not allowed'
fi
if grep -Eq '^[[:space:]]*replace[[:space:]]' go.mod; then
narratio_release_fail "$tool_name" 'go.mod replace directives are not allowed'
fi
narratio_release_go() {
if ! GOWORK=off go "$@"; then
narratio_release_fail "$tool_name" "failed: go $*"
fi
}
narratio_release_go mod tidy -diff
unformatted_files=$(git ls-files -z -- '*.go' | xargs -0 env GOWORK=off gofmt -l) || narratio_release_fail "$tool_name" 'failed: gofmt tracked Go files'
if [ -n "$unformatted_files" ]; then
narratio_release_fail "$tool_name" "tracked Go files are not gofmt clean: $unformatted_files"
fi
if ! git diff --check; then
narratio_release_fail "$tool_name" 'working-tree whitespace check failed'
fi
if ! git diff --cached --check; then
narratio_release_fail "$tool_name" 'cached whitespace check failed'
fi
narratio_release_go test -count=1 ./...
narratio_release_go test -race -count=1 ./...
narratio_release_go vet ./...
narratio_release_go build ./...
narratio_release_go test -count=1 ./internal/doccheck
narratio_release_go test -count=1 ./internal/config -run '^TestExamplesLoadAndValidate$'
temporary_assets_dir=$(mktemp -d "${TMPDIR:-/tmp}/narratio-release-candidate.XXXXXX") || narratio_release_fail "$tool_name" 'cannot create temporary asset directory'
case $temporary_assets_dir in
/*) ;;
*) narratio_release_fail "$tool_name" 'temporary asset directory must be absolute' ;;
esac
if [ ! -d "$temporary_assets_dir" ] || [ -L "$temporary_assets_dir" ]; then
narratio_release_fail "$tool_name" "temporary asset directory is unsafe: $temporary_assets_dir"
fi
cleanup_temporary_assets() {
if [ -n "${temporary_assets_dir:-}" ] && [ -d "$temporary_assets_dir" ] && [ ! -L "$temporary_assets_dir" ]; then
rm -rf "$temporary_assets_dir"
fi
}
trap cleanup_temporary_assets 0 HUP INT TERM
if ! GOWORK=off "$script_dir/build-release-assets.sh" "$release_version" "$temporary_assets_dir"; then
narratio_release_fail "$tool_name" 'failed: build-release-assets.sh'
fi