mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-18 01:36:21 +08:00
ci(version): make VERSION bump PR-aware and CI-safe
- detect CI env and handle pull_request by diffing VERSION against base - auto-run develop version update when PR doesn't change VERSION - avoid staged-file checks in CI; keep them for local commits - resolve/fetch base branch for shallow clones to compute diffs - switch release workflow to trigger on push tags (v*) - remove Tauri cargo-check from pre-commit hooks
This commit is contained in:
parent
716fecc8cd
commit
b05904ba09
4 changed files with 68 additions and 14 deletions
2
.github/workflows/version.yml
vendored
2
.github/workflows/version.yml
vendored
|
@ -1,7 +1,7 @@
|
|||
name: Version Release
|
||||
|
||||
on:
|
||||
create:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
|
||||
|
|
|
@ -43,11 +43,3 @@ repos:
|
|||
language: script
|
||||
pass_filenames: false
|
||||
stages: [pre-commit]
|
||||
- id: cargo-check
|
||||
name: Cargo check for Tauri desktop app
|
||||
entry: bash -c "cd desktop/tauri/src-tauri && cargo check"
|
||||
language: system
|
||||
pass_filenames: false
|
||||
files: ^desktop/tauri/src-tauri/.*\.(rs|toml|lock|json)$
|
||||
stages: [pre-commit]
|
||||
types_or: [rust, toml, json]
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
4.5.5-develop8
|
||||
4.5.5-develop9
|
||||
|
|
|
@ -1,7 +1,71 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Check if there are any changes staged for commit
|
||||
if [[ -z $(git diff --cached --name-only) ]]; then
|
||||
# Detect if running in CI (e.g., GitHub Actions or pre-commit.ci)
|
||||
if [[ -n "$GITHUB_ACTIONS" || -n "$CI" || -n "$PRE_COMMIT_CI" ]]; then
|
||||
IN_CI=true
|
||||
else
|
||||
IN_CI=false
|
||||
fi
|
||||
# CI: For pull_request events, check if the PR itself changes VERSION.
|
||||
# If not, run the develop version updater. This avoids relying on staged files.
|
||||
if [[ "$IN_CI" == "true" ]]; then
|
||||
BASE_REF="${GITHUB_BASE_REF:-}"
|
||||
|
||||
# If BASE_REF not provided (e.g., pre-commit.ci), infer remote default branch
|
||||
if [[ -z "$BASE_REF" ]]; then
|
||||
DEFAULT_BASE="$(git symbolic-ref -q --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##')"
|
||||
if [[ -z "$DEFAULT_BASE" ]]; then
|
||||
DEFAULT_BASE="$(git remote show origin 2>/dev/null | sed -n 's/.*HEAD branch: //p' | head -n1)"
|
||||
fi
|
||||
BASE_REF="$DEFAULT_BASE"
|
||||
fi
|
||||
|
||||
# Resolve a usable base ref
|
||||
CANDIDATES=()
|
||||
if [[ -n "$BASE_REF" ]]; then
|
||||
CANDIDATES+=("refs/remotes/origin/$BASE_REF")
|
||||
CANDIDATES+=("refs/heads/$BASE_REF")
|
||||
fi
|
||||
|
||||
BASE_RESOLVED=""
|
||||
for ref in "${CANDIDATES[@]}"; do
|
||||
if git rev-parse --verify -q "$ref" >/dev/null; then
|
||||
BASE_RESOLVED="$ref"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Attempt to fetch the remote-tracking base if missing (handles shallow clones)
|
||||
if [[ -z "$BASE_RESOLVED" && -n "$BASE_REF" ]]; then
|
||||
git fetch --no-tags --depth=100 origin "refs/heads/$BASE_REF:refs/remotes/origin/$BASE_REF" >/dev/null 2>&1 || true
|
||||
if git rev-parse --verify -q "refs/remotes/origin/$BASE_REF" >/dev/null; then
|
||||
BASE_RESOLVED="refs/remotes/origin/$BASE_REF"
|
||||
elif git rev-parse --verify -q "refs/heads/$BASE_REF" >/dev/null; then
|
||||
BASE_RESOLVED="refs/heads/$BASE_REF"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$BASE_RESOLVED" ]]; then
|
||||
echo "Warning: Could not resolve PR base ref for '$BASE_REF'."
|
||||
echo "Hint: ensure the base ref is available (e.g., full fetch)."
|
||||
echo "Skipping version update because PR base could not be resolved."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If diff is quiet, there were no changes to VERSION between base and head.
|
||||
if git diff --quiet "$BASE_RESOLVED...HEAD" -- VERSION; then
|
||||
echo "No VERSION bump detected in PR range ($BASE_RESOLVED...HEAD). Updating develop version."
|
||||
source "$(dirname "$0")/update_develop_version.sh"
|
||||
else
|
||||
echo "PR includes a VERSION change. Skipping version update."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# When running locally during an actual commit, skip if nothing is staged.
|
||||
# In CI, pre-commit typically runs outside of a commit with no staged files,
|
||||
# so we must not early-exit there.
|
||||
if [[ "$IN_CI" != "true" && -z $(git diff --cached --name-only) ]]; then
|
||||
echo "There are no changes staged for commit. Skipping version update."
|
||||
exit 0
|
||||
fi
|
||||
|
@ -16,5 +80,3 @@ elif git diff --name-only | grep -q "VERSION"; then
|
|||
elif ! git show --name-only HEAD | grep -q "VERSION"; then
|
||||
source "$(dirname "$0")/update_develop_version.sh"
|
||||
fi
|
||||
|
||||
source "$(dirname "$0")/update_develop_version.sh"
|
||||
|
|
Loading…
Add table
Reference in a new issue