Compare commits
8 Commits
fe3547edfc
...
v0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db4ed150e0 | ||
|
|
a5958b3827 | ||
|
|
d06653a743 | ||
|
|
b72bf4f187 | ||
|
|
c13502761c | ||
|
|
8ee5367310 | ||
|
|
d4a7acefd6 | ||
|
|
16f403ef4b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
.direnv
|
.direnv
|
||||||
|
result
|
||||||
22
flake.nix
22
flake.nix
@@ -122,6 +122,7 @@
|
|||||||
${pre-commit-check.shellHook}
|
${pre-commit-check.shellHook}
|
||||||
|
|
||||||
if [ -t 1 ]; then
|
if [ -t 1 ]; then
|
||||||
|
:
|
||||||
# command -v tput >/dev/null 2>&1 && tput clear || printf '\033c'
|
# command -v tput >/dev/null 2>&1 && tput clear || printf '\033c'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -144,16 +145,13 @@
|
|||||||
mkRelease =
|
mkRelease =
|
||||||
{
|
{
|
||||||
system,
|
system,
|
||||||
readVersion,
|
# Source of truth is always $ROOT_DIR/VERSION.
|
||||||
# Shell string — must print current version to stdout: "x.y.z" or "x.y.z-channel.N"
|
# Format:
|
||||||
# Example:
|
# line 1: X.Y.Z
|
||||||
# readVersion = ''cat "$ROOT_DIR/VERSION"'';
|
# line 2: CHANNEL (stable|alpha|beta|rc|internal|...)
|
||||||
writeVersion,
|
# line 3: N (prerelease number, 0 for stable)
|
||||||
# Shell string — env vars available: BASE_VERSION, CHANNEL, PRERELEASE_NUM, FULL_VERSION
|
|
||||||
# Example:
|
|
||||||
# writeVersion = ''echo "$FULL_VERSION" > "$ROOT_DIR/VERSION"'';
|
|
||||||
postVersion ? "",
|
postVersion ? "",
|
||||||
# Shell string — runs after writeVersion and versionFiles, before git add.
|
# Shell string — runs after VERSION + versionFiles are written, before git add.
|
||||||
# Same env vars available.
|
# Same env vars available.
|
||||||
versionFiles ? [ ],
|
versionFiles ? [ ],
|
||||||
# List of { path, template } attrsets.
|
# List of { path, template } attrsets.
|
||||||
@@ -212,15 +210,11 @@
|
|||||||
[
|
[
|
||||||
"__CHANNEL_LIST__"
|
"__CHANNEL_LIST__"
|
||||||
"__VERSION_FILES__"
|
"__VERSION_FILES__"
|
||||||
"__READ_VERSION__"
|
|
||||||
"__WRITE_VERSION__"
|
|
||||||
"__POST_VERSION__"
|
"__POST_VERSION__"
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
channelList
|
channelList
|
||||||
versionFilesScript
|
versionFilesScript
|
||||||
readVersion
|
|
||||||
writeVersion
|
|
||||||
postVersion
|
postVersion
|
||||||
]
|
]
|
||||||
(builtins.readFile ./packages/release/release.sh);
|
(builtins.readFile ./packages/release/release.sh);
|
||||||
@@ -252,8 +246,6 @@
|
|||||||
# Expose a no-op release package for the lib repo itself (dogfood)
|
# Expose a no-op release package for the lib repo itself (dogfood)
|
||||||
release = self.lib.mkRelease {
|
release = self.lib.mkRelease {
|
||||||
inherit system;
|
inherit system;
|
||||||
readVersion = ''cat "$ROOT_DIR/VERSION"'';
|
|
||||||
writeVersion = ''echo "$FULL_VERSION" > "$ROOT_DIR/VERSION"'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
# release.nix
|
# release.nix
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
readVersion,
|
# Source of truth is always $ROOT_DIR/VERSION.
|
||||||
writeVersion,
|
# Format:
|
||||||
|
# line 1: X.Y.Z
|
||||||
|
# line 2: CHANNEL (stable|alpha|beta|rc|internal|...)
|
||||||
|
# line 3: N (prerelease number, 0 for stable)
|
||||||
postVersion ? "",
|
postVersion ? "",
|
||||||
versionFiles ? [ ],
|
versionFiles ? [ ],
|
||||||
channels ? [
|
channels ? [
|
||||||
@@ -27,15 +30,11 @@ let
|
|||||||
[
|
[
|
||||||
"__CHANNEL_LIST__"
|
"__CHANNEL_LIST__"
|
||||||
"__VERSION_FILES__"
|
"__VERSION_FILES__"
|
||||||
"__READ_VERSION__"
|
|
||||||
"__WRITE_VERSION__"
|
|
||||||
"__POST_VERSION__"
|
"__POST_VERSION__"
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
channelList
|
channelList
|
||||||
versionFilesScript
|
versionFilesScript
|
||||||
readVersion
|
|
||||||
writeVersion
|
|
||||||
postVersion
|
postVersion
|
||||||
]
|
]
|
||||||
(builtins.readFile ./release.sh);
|
(builtins.readFile ./release.sh);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ CREATED_TAG=""
|
|||||||
|
|
||||||
# ── logging ────────────────────────────────────────────────────────────────
|
# ── logging ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
log() { echo "[release] $*"; }
|
log() { echo "[release] $*" >&2; }
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
local cmd
|
local cmd
|
||||||
@@ -192,18 +192,70 @@ generate_version_files() {
|
|||||||
__VERSION_FILES__
|
__VERSION_FILES__
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── user-provided hooks ────────────────────────────────────────────────────
|
# ── version source (built-in) ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
# Initializes $ROOT_DIR/VERSION from git tags if it doesn't exist.
|
||||||
|
# Must be called outside of any subshell so log output stays on stderr
|
||||||
|
# and never contaminates the stdout of do_read_version.
|
||||||
|
init_version_file() {
|
||||||
|
if [[ -f "$ROOT_DIR/VERSION" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local highest_tag=""
|
||||||
|
while IFS= read -r raw_tag; do
|
||||||
|
local tag="${raw_tag#v}"
|
||||||
|
[[ $tag =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z]+\.[0-9]+)?$ ]] || continue
|
||||||
|
|
||||||
|
if [[ -z $highest_tag ]]; then
|
||||||
|
highest_tag="$tag"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
local cmp_status=0
|
||||||
|
version_cmp "$tag" "$highest_tag" || cmp_status=$?
|
||||||
|
[[ $cmp_status -eq 1 ]] && highest_tag="$tag"
|
||||||
|
done < <(git tag --list)
|
||||||
|
|
||||||
|
[[ -z $highest_tag ]] && highest_tag="0.0.1"
|
||||||
|
|
||||||
|
parse_full_version "$highest_tag"
|
||||||
|
local channel_to_write="$CHANNEL"
|
||||||
|
local n_to_write="${PRERELEASE_NUM:-1}"
|
||||||
|
if [[ $channel_to_write == "stable" || -z $channel_to_write ]]; then
|
||||||
|
channel_to_write="stable"
|
||||||
|
n_to_write="0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%s\n%s\n%s\n' "$BASE_VERSION" "$channel_to_write" "$n_to_write" > "$ROOT_DIR/VERSION"
|
||||||
|
log "Initialized $ROOT_DIR/VERSION from highest tag: v$highest_tag"
|
||||||
|
}
|
||||||
|
|
||||||
do_read_version() {
|
do_read_version() {
|
||||||
:
|
local base_line channel_line n_line
|
||||||
__READ_VERSION__
|
base_line="$(sed -n '1p' "$ROOT_DIR/VERSION" | tr -d '\r')"
|
||||||
|
channel_line="$(sed -n '2p' "$ROOT_DIR/VERSION" | tr -d '\r')"
|
||||||
|
n_line="$(sed -n '3p' "$ROOT_DIR/VERSION" | tr -d '\r')"
|
||||||
|
|
||||||
|
if [[ -z $channel_line || $channel_line == "stable" ]]; then
|
||||||
|
printf '%s\n' "$base_line"
|
||||||
|
else
|
||||||
|
printf '%s-%s.%s\n' "$base_line" "$channel_line" "$n_line"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
do_write_version() {
|
do_write_version() {
|
||||||
:
|
local channel_to_write="$CHANNEL"
|
||||||
__WRITE_VERSION__
|
local n_to_write="${PRERELEASE_NUM:-1}"
|
||||||
|
if [[ $channel_to_write == "stable" || -z $channel_to_write ]]; then
|
||||||
|
channel_to_write="stable"
|
||||||
|
n_to_write="0"
|
||||||
|
fi
|
||||||
|
printf '%s\n%s\n%s\n' "$BASE_VERSION" "$channel_to_write" "$n_to_write" > "$ROOT_DIR/VERSION"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ── user-provided hook ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
do_post_version() {
|
do_post_version() {
|
||||||
:
|
:
|
||||||
__POST_VERSION__
|
__POST_VERSION__
|
||||||
@@ -218,8 +270,16 @@ main() {
|
|||||||
START_HEAD="$(git rev-parse HEAD)"
|
START_HEAD="$(git rev-parse HEAD)"
|
||||||
trap revert_on_failure ERR
|
trap revert_on_failure ERR
|
||||||
|
|
||||||
|
# Initialize VERSION file outside any subshell so log lines never
|
||||||
|
# bleed into the stdout capture below.
|
||||||
|
init_version_file
|
||||||
|
|
||||||
local raw_version
|
local raw_version
|
||||||
raw_version="$(do_read_version)"
|
raw_version="$(do_read_version | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z]+\.[0-9]+)?$' | tail -n1)"
|
||||||
|
if [[ -z $raw_version ]]; then
|
||||||
|
echo "Error: could not determine current version from VERSION source" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
parse_full_version "$raw_version"
|
parse_full_version "$raw_version"
|
||||||
|
|
||||||
log "Current: base=$BASE_VERSION channel=$CHANNEL pre=${PRERELEASE_NUM:-}"
|
log "Current: base=$BASE_VERSION channel=$CHANNEL pre=${PRERELEASE_NUM:-}"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||||
devshell-lib.url = "github:yourorg/devshell-lib";
|
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib";
|
||||||
devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user