From 748ed0197dcc04b7801660e4e51b03c03aaada3d Mon Sep 17 00:00:00 2001 From: "Nurul Huda (Apon)" Date: Sun, 7 Jun 2026 04:08:36 +0600 Subject: [PATCH] ci: rm version state from repo --- .github/workflows/release.yml | 20 ++- build.zig.zon | 2 +- ide/vscode/package.json | 2 +- ide/zed/extension.toml | 2 +- pkg/tree-sitter-mdzx/Cargo.toml | 2 +- pkg/tree-sitter-mdzx/build.zig.zon | 2 +- pkg/tree-sitter-mdzx/package.json | 2 +- pkg/tree-sitter-mdzx/tree-sitter.json | 2 +- pkg/tree-sitter-zx/Cargo.toml | 2 +- pkg/tree-sitter-zx/build.zig.zon | 2 +- pkg/tree-sitter-zx/package.json | 2 +- pkg/tree-sitter-zx/tree-sitter.json | 2 +- pkg/ziex/build.zig.zon | 2 +- pkg/ziex/package.json | 12 +- tools/version | 177 ++++++++++++++++---------- 15 files changed, 144 insertions(+), 89 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ebb6c16a..ed43b2bf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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.). + 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}" diff --git a/build.zig.zon b/build.zig.zon index 51a39146..448778ff 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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", diff --git a/ide/vscode/package.json b/ide/vscode/package.json index 26743293..4ed68b32 100644 --- a/ide/vscode/package.json +++ b/ide/vscode/package.json @@ -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, diff --git a/ide/zed/extension.toml b/ide/zed/extension.toml index 27f57162..08c2b779 100644 --- a/ide/zed/extension.toml +++ b/ide/zed/extension.toml @@ -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) "] repository = "https://github.com/ziex-dev/ziex" diff --git a/pkg/tree-sitter-mdzx/Cargo.toml b/pkg/tree-sitter-mdzx/Cargo.toml index 50495e93..6c2f885f 100644 --- a/pkg/tree-sitter-mdzx/Cargo.toml +++ b/pkg/tree-sitter-mdzx/Cargo.toml @@ -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) "] license = "MIT" readme = "README.md" diff --git a/pkg/tree-sitter-mdzx/build.zig.zon b/pkg/tree-sitter-mdzx/build.zig.zon index 58461c53..71d771b9 100644 --- a/pkg/tree-sitter-mdzx/build.zig.zon +++ b/pkg/tree-sitter-mdzx/build.zig.zon @@ -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", diff --git a/pkg/tree-sitter-mdzx/package.json b/pkg/tree-sitter-mdzx/package.json index 84e5678d..b7e0bb0b 100644 --- a/pkg/tree-sitter-mdzx/package.json +++ b/pkg/tree-sitter-mdzx/package.json @@ -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", diff --git a/pkg/tree-sitter-mdzx/tree-sitter.json b/pkg/tree-sitter-mdzx/tree-sitter.json index 0d7aaa6a..1354b38f 100644 --- a/pkg/tree-sitter-mdzx/tree-sitter.json +++ b/pkg/tree-sitter-mdzx/tree-sitter.json @@ -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": [ diff --git a/pkg/tree-sitter-zx/Cargo.toml b/pkg/tree-sitter-zx/Cargo.toml index 50495e93..6c2f885f 100644 --- a/pkg/tree-sitter-zx/Cargo.toml +++ b/pkg/tree-sitter-zx/Cargo.toml @@ -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) "] license = "MIT" readme = "README.md" diff --git a/pkg/tree-sitter-zx/build.zig.zon b/pkg/tree-sitter-zx/build.zig.zon index 6da704f7..2e40260b 100644 --- a/pkg/tree-sitter-zx/build.zig.zon +++ b/pkg/tree-sitter-zx/build.zig.zon @@ -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", diff --git a/pkg/tree-sitter-zx/package.json b/pkg/tree-sitter-zx/package.json index 6c28377e..06a9bc21 100644 --- a/pkg/tree-sitter-zx/package.json +++ b/pkg/tree-sitter-zx/package.json @@ -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", diff --git a/pkg/tree-sitter-zx/tree-sitter.json b/pkg/tree-sitter-zx/tree-sitter.json index 7b97a900..91211f6d 100644 --- a/pkg/tree-sitter-zx/tree-sitter.json +++ b/pkg/tree-sitter-zx/tree-sitter.json @@ -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": [ diff --git a/pkg/ziex/build.zig.zon b/pkg/ziex/build.zig.zon index d088d932..2303971f 100644 --- a/pkg/ziex/build.zig.zon +++ b/pkg/ziex/build.zig.zon @@ -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 = .{""}, } diff --git a/pkg/ziex/package.json b/pkg/ziex/package.json index f6e1a675..858a5a07 100644 --- a/pkg/ziex/package.json +++ b/pkg/ziex/package.json @@ -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": { diff --git a/tools/version b/tools/version index 49c07c62..40dc8217 100755 --- a/tools/version +++ b/tools/version @@ -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 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 "." 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. 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 -