From 6fcb8c602b0589759b0fde15c627c8d2ceb2d5a8 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 20 Jan 2026 14:27:19 +0100 Subject: [PATCH] scripts: avoid running `create-release` directly --- scripts/create-release.nix | 71 +++++++++++++++++++++++++++++++++++-- scripts/create-release.sh | 72 -------------------------------------- 2 files changed, 69 insertions(+), 74 deletions(-) delete mode 100755 scripts/create-release.sh diff --git a/scripts/create-release.nix b/scripts/create-release.nix index 42f3319..d0885be 100644 --- a/scripts/create-release.nix +++ b/scripts/create-release.nix @@ -1,5 +1,4 @@ { - lib, writeShellApplication, bash, coreutils, @@ -14,5 +13,73 @@ writeShellApplication { coreutils nix-fast-build ]; - text = lib.readFile ./create-release.sh; + text = '' + version=''${1:-} + if [[ -z "$version" ]]; then + echo "USAGE: nix run .#create-release -- " >&2 + exit 1 + fi + + # Check if we're running from the root of the repository + if [[ ! -f "flake.nix" || ! -f "version.nix" ]]; then + echo "This script must be run from the root of the repository" >&2 + exit 1 + fi + + # Check if the version matches the semver pattern (without suffixes) + semver_regex="^([0-9]+)\.([0-9]+)\.([0-9]+)$" + if [[ ! "$version" =~ $semver_regex ]]; then + echo "Version must match the semver pattern (e.g., 1.0.0, 2.3.4)" >&2 + exit 1 + fi + + if [[ "$(git symbolic-ref --short HEAD)" != "master" ]]; then + echo "must be on master branch" >&2 + exit 1 + fi + + # Ensure there are no uncommitted or unpushed changes + uncommited_changes=$(git diff --compact-summary) + if [[ -n "$uncommited_changes" ]]; then + echo -e "There are uncommited changes, exiting:\n''${uncommited_changes}" >&2 + exit 1 + fi + git pull git@github.com:nix-community/disko master + unpushed_commits=$(git log --format=oneline origin/master..master) + if [[ "$unpushed_commits" != "" ]]; then + echo -e "\nThere are unpushed changes, exiting:\n$unpushed_commits" >&2 + 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 + + # Update the version file + cat > version.nix < version.nix + git commit -am "release: reset released flag" + + echo "Release was prepared successfully!" + echo "To push the release, run the following command:" + echo + echo " git push origin master v$version && git push --force origin latest" + echo + echo "After that, create a release on GitHub:" + echo + echo " https://github.com/nix-community/disko/releases/new" + ''; } diff --git a/scripts/create-release.sh b/scripts/create-release.sh deleted file mode 100755 index 179fe61..0000000 --- a/scripts/create-release.sh +++ /dev/null @@ -1,72 +0,0 @@ -#! /usr/bin/env bash - -# Don't run directly! Instead, use -# nix run .#create-release - -version=${1:-} -if [[ -z "$version" ]]; then - echo "USAGE: nix run .#create-release -- " >&2 - exit 1 -fi - -# Check if we're running from the root of the repository -if [[ ! -f "flake.nix" || ! -f "version.nix" ]]; then - echo "This script must be run from the root of the repository" >&2 - exit 1 -fi - -# Check if the version matches the semver pattern (without suffixes) -semver_regex="^([0-9]+)\.([0-9]+)\.([0-9]+)$" -if [[ ! "$version" =~ $semver_regex ]]; then - echo "Version must match the semver pattern (e.g., 1.0.0, 2.3.4)" >&2 - exit 1 -fi - -if [[ "$(git symbolic-ref --short HEAD)" != "master" ]]; then - echo "must be on master branch" >&2 - exit 1 -fi - -# Ensure there are no uncommitted or unpushed changes -uncommited_changes=$(git diff --compact-summary) -if [[ -n "$uncommited_changes" ]]; then - echo -e "There are uncommited changes, exiting:\n${uncommited_changes}" >&2 - exit 1 -fi -git pull git@github.com:nix-community/disko master -unpushed_commits=$(git log --format=oneline origin/master..master) -if [[ "$unpushed_commits" != "" ]]; then - echo -e "\nThere are unpushed changes, exiting:\n$unpushed_commits" >&2 - 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 - -# Update the version file -cat > version.nix < version.nix -git commit -am "release: reset released flag" - -echo "Release was prepared successfully!" -echo "To push the release, run the following command:" -echo -echo " git push origin master v$version && git push --force origin latest" -echo -echo "After that, create a release on GitHub:" -echo -echo " https://github.com/nix-community/disko/releases/new"