#! /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"