From daba0d704e2a71ad674ec8ebe2575545faa5461f Mon Sep 17 00:00:00 2001 From: InkerBot Date: Thu, 5 Mar 2026 15:48:21 +0800 Subject: [PATCH] ensure rev sync --- bin/apply | 29 +++++++++++++++++++++++++++-- bin/apply.ps1 | 36 ++++++++++++++++++++++++++++++++++-- bin/update | 7 ++++++- bin/update.ps1 | 7 ++++++- works/rev | 1 + 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 works/rev diff --git a/bin/apply b/bin/apply index c0e74e9..b7ce712 100755 --- a/bin/apply +++ b/bin/apply @@ -6,10 +6,35 @@ ROOT="$(dirname "$SCRIPT_DIR")" SING_BOX="$ROOT/works/sing-box" PATCH_DIR="$ROOT/works/patch" OUTPUT="$ROOT/works/core" +REV_FILE="$ROOT/works/rev" +# defaults +REPO_URL="git@git.inker.bot:arknights/sing-box.git" +UPSTREAM_BRANCH="main" + +CONFIG="$ROOT/works/config" +if [ -f "$CONFIG" ]; then + . "$CONFIG" +fi + +# Clone if not present if [ ! -d "$SING_BOX/.git" ]; then - echo "Error: works/sing-box not found. Run update first." >&2 - exit 1 + echo "Cloning sing-box..." + if [ -n "$UPSTREAM_BRANCH" ]; then + git clone -b "$UPSTREAM_BRANCH" "$REPO_URL" "$SING_BOX" + else + git clone "$REPO_URL" "$SING_BOX" + fi +fi + +# Checkout stored rev +if [ -f "$REV_FILE" ]; then + REV="$(cat "$REV_FILE" | tr -d '[:space:]')" + echo "Checking out stored rev: $REV" + git -C "$SING_BOX" fetch --all + git -C "$SING_BOX" checkout "$REV" +else + echo "Warning: works/rev not found, using current HEAD." >&2 fi echo "Initializing works/core/..." diff --git a/bin/apply.ps1 b/bin/apply.ps1 index 238ffbd..c7d8017 100644 --- a/bin/apply.ps1 +++ b/bin/apply.ps1 @@ -5,10 +5,42 @@ $Root = Split-Path -Parent $ScriptDir $SingBox = Join-Path $Root 'works/sing-box' $PatchDir = Join-Path $Root 'works/patch' $Output = Join-Path $Root 'works/core' +$RevFile = Join-Path $Root 'works/rev' +# defaults +$RepoUrl = 'git@git.inker.bot:arknights/sing-box.git' +$UpstreamBranch = 'main' + +$ConfigFile = Join-Path $Root 'works/config' +if (Test-Path $ConfigFile) { + Get-Content $ConfigFile | ForEach-Object { + if ($_ -match '^([^#=]+)=(.*)$') { + $key = $Matches[1].Trim() + $val = $Matches[2].Trim() + if ($key -eq 'REPO_URL') { $RepoUrl = $val } + elseif ($key -eq 'UPSTREAM_BRANCH') { $UpstreamBranch = $val } + } + } +} + +# Clone if not present if (-not (Test-Path (Join-Path $SingBox '.git'))) { - Write-Error 'works/sing-box not found. Run update first.' - exit 1 + Write-Host 'Cloning sing-box...' + if ($UpstreamBranch) { + git clone -b $UpstreamBranch $RepoUrl $SingBox + } else { + git clone $RepoUrl $SingBox + } +} + +# Checkout stored rev +if (Test-Path $RevFile) { + $Rev = (Get-Content $RevFile -Raw).Trim() + Write-Host "Checking out stored rev: $Rev" + git -C $SingBox fetch --all + git -C $SingBox checkout $Rev +} else { + Write-Host 'Warning: works/rev not found, using current HEAD.' -ForegroundColor Yellow } Write-Host 'Initializing works/core/...' diff --git a/bin/update b/bin/update index 40292d0..c64512a 100755 --- a/bin/update +++ b/bin/update @@ -4,6 +4,7 @@ set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" ROOT="$(dirname "$SCRIPT_DIR")" SING_BOX="$ROOT/works/sing-box" +REV_FILE="$ROOT/works/rev" # defaults REPO_URL="git@git.inker.bot:arknights/sing-box.git" @@ -30,4 +31,8 @@ else fi fi -echo "Done. Version: $(git -C "$SING_BOX" describe --tags --always 2>/dev/null || git -C "$SING_BOX" rev-parse --short HEAD)" +REV="$(git -C "$SING_BOX" rev-parse HEAD)" +echo "$REV" > "$REV_FILE" + +echo "Done. Version: $(git -C "$SING_BOX" describe --tags --always 2>/dev/null || echo "$REV")" +echo "Stored rev: $REV" diff --git a/bin/update.ps1 b/bin/update.ps1 index d06b218..9f364ba 100644 --- a/bin/update.ps1 +++ b/bin/update.ps1 @@ -3,6 +3,7 @@ $ErrorActionPreference = 'Stop' $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $Root = Split-Path -Parent $ScriptDir $SingBox = Join-Path $Root 'works/sing-box' +$RevFile = Join-Path $Root 'works/rev' # defaults $RepoUrl = 'git@git.inker.bot:arknights/sing-box.git' @@ -34,6 +35,10 @@ if (Test-Path (Join-Path $SingBox '.git')) { } } +$Rev = git -C $SingBox rev-parse HEAD +Set-Content -Path $RevFile -Value $Rev -NoNewline + $version = git -C $SingBox describe --tags --always 2>$null -if (-not $version) { $version = git -C $SingBox rev-parse --short HEAD } +if (-not $version) { $version = $Rev.Substring(0, 7) } Write-Host "Done. Version: $version" +Write-Host "Stored rev: $Rev" diff --git a/works/rev b/works/rev new file mode 100644 index 0000000..73ccf24 --- /dev/null +++ b/works/rev @@ -0,0 +1 @@ +da4738272e5cdb8b2c904a9b07c7464cb379921d