ci: rm version state from repo

This commit is contained in:
Nurul Huda (Apon) 2026-06-07 04:08:36 +06:00
parent b283f19bdb
commit 748ed0197d
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
15 changed files with 144 additions and 89 deletions

View File

@ -22,6 +22,14 @@ on:
options:
- npm
- gh
from:
description: "How to compute the pre-release number when no explicit version is given"
required: false
type: choice
default: commits
options:
- commits
- tag
jobs:
resolve-version:
@ -31,13 +39,21 @@ jobs:
version: ${{ steps.resolve.outputs.version }}
dist-tag: ${{ steps.resolve.outputs.dist_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve and validate version
id: resolve
run: |
RAW_VERSION="${{ inputs.version || github.event.release.tag_name }}"
if [ -z "$RAW_VERSION" ]; then
echo "No version provided, will use version from build.zig.zon"
exit 0
# No explicit version: compute the full version from the numberless
# base in build.zig.zon (e.g. 0.1.0-dev -> 0.1.0-dev.<N>).
FROM="${{ inputs.from || 'commits' }}"
RAW_VERSION=$(bash tools/version --resolve --from="$FROM")
echo "Computed version from --from=$FROM: $RAW_VERSION"
fi
# Trim v prefix
VERSION="${RAW_VERSION#v}"

View File

@ -1,6 +1,6 @@
.{
.name = .ziex,
.version = "0.1.0-dev.1138",
.version = "0.1.0-dev",
.description = "Ziex is a framework for building web applications with Zig.",
.repository = "https://github.com/ziex-dev/ziex",
.homepage = "https://ziex.dev",

View File

@ -2,7 +2,7 @@
"name": "ziex",
"displayName": "Ziex",
"description": "Ziex let's you write HTML within your Zig code.",
"version": "0.1.1138",
"version": "0.1.1140",
"publisher": "ziex",
"icon": "images/zx-icon.png",
"private": true,

View File

@ -1,7 +1,7 @@
id = "ziex"
name = "Ziex"
description = "ZX support."
version = "0.1.0-dev.1138"
version = "0.1.0-dev"
schema_version = 1
authors = ["Nurul Huda (Apon) <me@nurulhudaapon.com>"]
repository = "https://github.com/ziex-dev/ziex"

View File

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-zx"
description = "ZX is a framework for building web applications with Zig."
version = "0.1.0-dev.1138"
version = "0.1.0-dev"
authors = ["Nurul Huda (Apon) <me@nurulhudaapon.com>"]
license = "MIT"
readme = "README.md"

View File

@ -1,7 +1,7 @@
.{
.name = .tree_sitter_mdzx,
.fingerprint = 0xfba737bb8e0d19e0,
.version = "0.1.0-dev.1138",
.version = "0.1.0-dev",
.dependencies = .{
.tree_sitter = .{
.path = "../../vendor/zig-tree-sitter",

View File

@ -1,6 +1,6 @@
{
"name": "tree-sitter-mdzx",
"version": "0.1.0-dev.1138",
"version": "0.1.0-dev",
"description": "ZX is a framework for building web applications with Zig.",
"repository": "https://github.com/nurulhudaapon/mdzx",
"license": "MIT",

View File

@ -14,7 +14,7 @@
}
],
"metadata": {
"version": "0.1.0-dev.1138",
"version": "0.1.0-dev",
"license": "MIT",
"description": "ZX is a framework for building web applications with Zig.",
"authors": [

View File

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-zx"
description = "ZX is a framework for building web applications with Zig."
version = "0.1.0-dev.1138"
version = "0.1.0-dev"
authors = ["Nurul Huda (Apon) <me@nurulhudaapon.com>"]
license = "MIT"
readme = "README.md"

View File

@ -1,7 +1,7 @@
.{
.name = .tree_sitter_zx,
.fingerprint = 0xd3a91e4ba933ca89,
.version = "0.1.0-dev.1138",
.version = "0.1.0-dev",
.dependencies = .{
.tree_sitter = .{
.path = "../../vendor/zig-tree-sitter",

View File

@ -1,6 +1,6 @@
{
"name": "tree-sitter-zx",
"version": "0.1.0-dev.1138",
"version": "0.1.0-dev",
"description": "ZX is a framework for building web applications with Zig.",
"repository": "https://github.com/ziex-dev/ziex",
"license": "MIT",

View File

@ -14,7 +14,7 @@
}
],
"metadata": {
"version": "0.1.0-dev.1138",
"version": "0.1.0-dev",
"license": "MIT",
"description": "ZX is a framework for building web applications with Zig.",
"authors": [

View File

@ -1,7 +1,7 @@
.{
.name = .ziex_js,
.fingerprint = 0x3428b4e119b455bf,
.version = "0.1.0-dev.1138",
.version = "0.1.0-dev",
.minimum_zig_version = "0.16.0",
.paths = .{""},
}

View File

@ -1,6 +1,6 @@
{
"name": "ziex",
"version": "0.1.0-dev.1138",
"version": "0.1.0-dev",
"private": true,
"description": "ZX is a framework for building web applications with Zig.",
"main": "src/index.ts",
@ -44,19 +44,19 @@
"check": "tsc"
},
"dependencies": {
"@ziex/cli": "0.1.0-dev.1138"
"@ziex/cli": "0.1.0-dev"
},
"devDependencies": {
"@types/bun": "latest",
"zzon": "^1.7.1",
"zzon": "^0.1.0-dev",
"jsz": "github:nurulhudaapon/jsz",
"@types/react": "latest",
"@types/react-dom": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0",
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
"typescript": "^0.1.0-dev",
"react": ">=0.1.0-dev",
"react-dom": ">=0.1.0-dev"
},
"peerDependenciesMeta": {
"react": {

View File

@ -1,70 +1,124 @@
#!/bin/bash
# Pre-commit hook to set or increment version number
# Usage: ./version [version | --commit]
# If version is provided, sets that version everywhere
# If --commit is provided, uses git commit count + 1 as the dev number
# If no argument is provided, increments the dev number (e.g., dev.10 -> dev.11)
# Set or resolve the project version.
#
# In the repo, the version is kept WITHOUT a pre-release number, e.g.
# "0.1.0-dev". The full version (e.g. "0.1.0-dev.1138") is only materialized
# during the release process, so there are no "bump version" commits.
#
# Usage:
# ./version <version> Set an explicit version everywhere (e.g. 0.1.0-dev.1138)
# ./version --from=commits Compute N from git commit count, stamp 0.1.0-dev.N
# ./version --from=tag Compute N from the latest matching git tag + 1, stamp 0.1.0-dev.N
# ./version --resolve [--from=commits|tag]
# Print the resolved full version to stdout and exit
# (does not modify any files). Defaults to --from=commits.
# ./version Equivalent to --from=commits (stamp files)
#
# The base version (everything before the pre-release number) is read from
# build.zig.zon and may be either numberless ("0.1.0-dev") or already
# numbered ("0.1.0-dev.123") — both are handled.
BUILD_ZON_FILE="build.zig.zon"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
BUILD_ZON_PATH="$PROJECT_ROOT/$BUILD_ZON_FILE"
# Check if file exists
if [ ! -f "$BUILD_ZON_PATH" ]; then
echo "Error: $BUILD_ZON_FILE not found at $BUILD_ZON_PATH"
echo "Error: $BUILD_ZON_FILE not found at $BUILD_ZON_PATH" >&2
exit 1
fi
# Extract current version
# Extract current version (.version field only, not .jsglue_version etc.)
CURRENT_VERSION=$(grep -E '^\s*\.version\s*=' "$BUILD_ZON_PATH" | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$CURRENT_VERSION" ]; then
echo "Error: Could not find version in $BUILD_ZON_FILE"
echo "Error: Could not find version in $BUILD_ZON_FILE" >&2
exit 1
fi
# Check if --commit flag was provided
if [ "$1" = "--commit" ]; then
# Get total git commit count + 1
COMMIT_COUNT=$(git -C "$PROJECT_ROOT" rev-list --count HEAD 2>/dev/null)
if [ -z "$COMMIT_COUNT" ]; then
echo "Error: Could not get git commit count"
exit 1
fi
NEW_DEV_NUMBER=$((COMMIT_COUNT + 1))
NEW_VERSION=$(echo "$CURRENT_VERSION" | sed -E "s/dev\.[0-9]+/dev.$NEW_DEV_NUMBER/")
# Check if version was provided as argument
elif [ -n "$1" ]; then
NEW_VERSION="$1"
echo "Setting version to: $NEW_VERSION"
EXPLICIT_VERSION=""
FROM="commits"
RESOLVE_ONLY=0
for arg in "$@"; do
case "$arg" in
--resolve) RESOLVE_ONLY=1 ;;
--from=commits) FROM="commits" ;;
--from=tag) FROM="tag" ;;
--commit) FROM="commits" ;; # backwards-compatible alias
--from=*)
echo "Error: unknown --from value: ${arg#--from=} (use commits|tag)" >&2
exit 1
;;
--*)
echo "Error: unknown flag: $arg" >&2
exit 1
;;
*)
EXPLICIT_VERSION="$arg" ;;
esac
done
# Compute the base (version without the pre-release number)
# Strip a trailing ".<number>" pre-release counter if present.
# 0.1.0-dev -> 0.1.0-dev
# 0.1.0-dev.123 -> 0.1.0-dev
# 0.1.0 -> 0.1.0 (no -dev, left as-is)
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/(-[a-zA-Z]+)\.[0-9]+$/\1/')
# Resolve the new full version
if [ -n "$EXPLICIT_VERSION" ]; then
NEW_VERSION="$EXPLICIT_VERSION"
else
# Extract the dev number (e.g., extract 10 from "0.1.0-dev.10")
DEV_NUMBER=$(echo "$CURRENT_VERSION" | grep -oE 'dev\.([0-9]+)' | grep -oE '[0-9]+')
if [ -z "$DEV_NUMBER" ]; then
echo "Error: Could not extract dev number from version: $CURRENT_VERSION"
exit 1
fi
# Increment the dev number
NEW_DEV_NUMBER=$((DEV_NUMBER + 1))
# Create new version string (replace dev.XX with dev.NEW_NUMBER)
NEW_VERSION=$(echo "$CURRENT_VERSION" | sed -E "s/dev\.$DEV_NUMBER/dev.$NEW_DEV_NUMBER/")
case "$FROM" in
commits)
N=$(git -C "$PROJECT_ROOT" rev-list --count HEAD 2>/dev/null)
if [ -z "$N" ]; then
echo "Error: Could not get git commit count" >&2
exit 1
fi
;;
tag)
# Find the highest existing tag matching v<base>.<n> and increment n.
# E.g. base 0.1.0-dev -> match v0.1.0-dev.*, take the max n, +1.
ESCAPED_BASE=$(printf '%s' "$BASE_VERSION" | sed -E 's/[.[\*^$()+?{}|]/\\&/g')
LAST_N=$(git -C "$PROJECT_ROOT" tag --list "v${BASE_VERSION}.*" \
| sed -E "s/^v${ESCAPED_BASE}\.([0-9]+)$/\1/" \
| grep -E '^[0-9]+$' \
| sort -n \
| tail -1)
if [ -z "$LAST_N" ]; then
N=1
else
N=$((LAST_N + 1))
fi
;;
esac
NEW_VERSION="${BASE_VERSION}.${N}"
fi
# Version pattern to match any dev version (e.g., 0.1.0-dev.XXX)
VERSION_PATTERN="0\\.1\\.0-dev\\.[0-9]+"
# --resolve: just print and exit, touching nothing.
if [ "$RESOLVE_ONLY" -eq 1 ]; then
echo "$NEW_VERSION"
exit 0
fi
# Update build.zig.zon (only .version field, not .jsglue_version)
echo "Version: $CURRENT_VERSION -> $NEW_VERSION"
# Stamp the new version into all version-bearing files
# Match any X.Y.Z[-pre[.N]] version string for in-place replacement.
VERSION_PATTERN='[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z]+(\.[0-9]+)?)?'
# Root build.zig.zon (.version field only)
sed -i.bak -E "/^[[:space:]]*\.version[[:space:]]*=/s/$VERSION_PATTERN/$NEW_VERSION/" "$BUILD_ZON_PATH"
rm -f "$BUILD_ZON_PATH.bak"
echo "Version: $CURRENT_VERSION -> $NEW_VERSION"
echo "Updated $BUILD_ZON_FILE"
# Update pkg/ziex/build.zig.zon version
# pkg/ziex/build.zig.zon
ZIEX_BUILD_ZON="$PROJECT_ROOT/pkg/ziex/build.zig.zon"
if [ -f "$ZIEX_BUILD_ZON" ]; then
sed -i.bak -E "/^[[:space:]]*\.version[[:space:]]*=/s/$VERSION_PATTERN/$NEW_VERSION/" "$ZIEX_BUILD_ZON"
@ -72,7 +126,7 @@ if [ -f "$ZIEX_BUILD_ZON" ]; then
echo "Updated pkg/ziex/build.zig.zon"
fi
# Update pkg/ziex/package.json version
# pkg/ziex/package.json
ZIEX_PACKAGE_JSON="$PROJECT_ROOT/pkg/ziex/package.json"
if [ -f "$ZIEX_PACKAGE_JSON" ]; then
sed -i.bak -E "s/$VERSION_PATTERN/$NEW_VERSION/" "$ZIEX_PACKAGE_JSON"
@ -80,19 +134,18 @@ if [ -f "$ZIEX_PACKAGE_JSON" ]; then
echo "Updated pkg/ziex/package.json"
fi
# Update ide/zed/extension.toml version
# ide/zed/extension.toml
ZED_EXTENSION_TOML="$PROJECT_ROOT/ide/zed/extension.toml"
if [ -f "$ZED_EXTENSION_TOML" ]; then
sed -i.bak -E "s/$VERSION_PATTERN/$NEW_VERSION/" "$ZED_EXTENSION_TOML"
sed -i.bak -E "/^[[:space:]]*version[[:space:]]*=/s/$VERSION_PATTERN/$NEW_VERSION/" "$ZED_EXTENSION_TOML"
rm -f "$ZED_EXTENSION_TOML.bak"
echo "Updated ide/zed/extension.toml"
fi
# Update ide/vscode/package.json version (uses 0.1.X format since VSCode doesn't support prerelease versions)
# ide/vscode/package.json (uses 0.1.N format since VSCode rejects prerelease tags)
VSCODE_PACKAGE_JSON="$PROJECT_ROOT/ide/vscode/package.json"
if [ -f "$VSCODE_PACKAGE_JSON" ]; then
# Extract the dev number from the new version (e.g., 357 from 0.1.0-dev.357)
VSCODE_DEV_NUMBER=$(echo "$NEW_VERSION" | grep -oE 'dev\.([0-9]+)' | grep -oE '[0-9]+')
VSCODE_DEV_NUMBER=$(echo "$NEW_VERSION" | grep -oE '[a-zA-Z]+\.([0-9]+)$' | grep -oE '[0-9]+$')
if [ -n "$VSCODE_DEV_NUMBER" ]; then
VSCODE_VERSION="0.1.$VSCODE_DEV_NUMBER"
sed -i.bak -E "s/\"version\": \"0\\.1\\.[0-9]+\"/\"version\": \"$VSCODE_VERSION\"/" "$VSCODE_PACKAGE_JSON"
@ -101,26 +154,12 @@ if [ -f "$VSCODE_PACKAGE_JSON" ]; then
fi
fi
# Stage the updated files for commit
git add "$BUILD_ZON_PATH"
git add "$ZIEX_BUILD_ZON" 2>/dev/null || true
git add "$ZIEX_PACKAGE_JSON" 2>/dev/null || true
git add "$ZED_EXTENSION_TOML" 2>/dev/null || true
git add "$VSCODE_PACKAGE_JSON" 2>/dev/null || true
# Update tree-sitter-zx version (ignore errors)
TREE_SITTER_DIR="$PROJECT_ROOT/pkg/tree-sitter-zx"
if [ -d "$TREE_SITTER_DIR" ]; then
(cd "$TREE_SITTER_DIR" && tree-sitter version "$NEW_VERSION") 2>/dev/null || true
git add "$TREE_SITTER_DIR" 2>/dev/null || true
fi
# Update tree-sitter-mdzx version (ignore errors)
TREE_SITTER_DIR="$PROJECT_ROOT/pkg/tree-sitter-mdzx"
if [ -d "$TREE_SITTER_DIR" ]; then
(cd "$TREE_SITTER_DIR" && tree-sitter version "$NEW_VERSION") 2>/dev/null || true
git add "$TREE_SITTER_DIR" 2>/dev/null || true
fi
# tree-sitter grammars
for TS in tree-sitter-zx tree-sitter-mdzx; do
TREE_SITTER_DIR="$PROJECT_ROOT/pkg/$TS"
if [ -d "$TREE_SITTER_DIR" ]; then
(cd "$TREE_SITTER_DIR" && tree-sitter version "$NEW_VERSION") 2>/dev/null || true
fi
done
exit 0