diff --git a/scripts/create-release.nix b/scripts/create-release.nix index fbb7cc1..e1b2a20 100644 --- a/scripts/create-release.nix +++ b/scripts/create-release.nix @@ -3,6 +3,7 @@ bash, coreutils, git, + gh, nix-fast-build, }: writeShellApplication { @@ -10,10 +11,13 @@ writeShellApplication { runtimeInputs = [ bash git + gh coreutils nix-fast-build ]; text = '' + set -x + version=''${1:-} if [[ -z "$version" ]]; then echo "USAGE: nix run .#create-release -- " >&2 @@ -51,9 +55,22 @@ writeShellApplication { exit 1 fi - # Run all tests to ensure we don't release a broken version - # Two workers are safe on systems with at least 16GB of RAM - nix-fast-build --no-link -j 2 --eval-workers 2 --flake .#checks + branch_name="release/v$version" + + # Check if branch already exists + if git show-ref --verify --quiet "refs/heads/$branch_name"; then + echo "Branch $branch_name already exists locally, please delete it first" >&2 + exit 1 + fi + + # Check if tag already exists (locally or remotely) + if git show-ref --verify --quiet "refs/tags/v$version" || git ls-remote --tags origin "v$version" | grep -q .; then + echo "Tag v$version already exists, aborting" >&2 + exit 1 + fi + + # Create release branch + git checkout -b "$branch_name" # Update the version file cat > version.nix <&2 + git checkout master + git branch -D "$branch_name" + exit 1 + fi + echo "Waiting for PR to merge (current state: $state)..." + sleep 10 + done + + # Switch back to master and pull the merged commit + git checkout master + git pull origin master + + # Delete the local release branch + git branch -D "$branch_name" + + # Tag the release and push tags + git tag -a "v$version" -m "release: v$version" + git tag -d "latest" 2>/dev/null || true + git tag -a "latest" -m "release: v$version" + git push origin "v$version" + git push --force origin latest + + # Create follow-up branch to reset released flag + followup_branch="release/v$version-followup" + git checkout -b "$followup_branch" + cat > version.nix <