fix?
This commit is contained in:
3 files changed
+64
-81
No files matched your search
+20
-9
@@ -435,11 +435,16 @@ update-wiki:
|
|||||||
tags:
|
tags:
|
||||||
- linux-x86_64
|
- linux-x86_64
|
||||||
needs:
|
needs:
|
||||||
- package-linux
|
- job: package-linux
|
||||||
- package-linux-arm64
|
artifacts: false
|
||||||
- package-windows
|
- job: package-linux-arm64
|
||||||
- package-windows-arm64
|
artifacts: false
|
||||||
|
- job: package-windows
|
||||||
|
artifacts: false
|
||||||
|
- job: package-windows-arm64
|
||||||
|
artifacts: false
|
||||||
- job: package-macos
|
- job: package-macos
|
||||||
|
artifacts: false
|
||||||
optional: true
|
optional: true
|
||||||
script:
|
script:
|
||||||
- |
|
- |
|
||||||
@@ -505,13 +510,19 @@ bump-version:
|
|||||||
tags:
|
tags:
|
||||||
- linux-x86_64
|
- linux-x86_64
|
||||||
needs:
|
needs:
|
||||||
- package-linux
|
- job: package-linux
|
||||||
- package-linux-arm64
|
artifacts: false
|
||||||
- package-windows
|
- job: package-linux-arm64
|
||||||
- package-windows-arm64
|
artifacts: false
|
||||||
|
- job: package-windows
|
||||||
|
artifacts: false
|
||||||
|
- job: package-windows-arm64
|
||||||
|
artifacts: false
|
||||||
- job: package-macos
|
- job: package-macos
|
||||||
|
artifacts: false
|
||||||
optional: true
|
optional: true
|
||||||
- update-wiki
|
- job: update-wiki
|
||||||
|
artifacts: false
|
||||||
script:
|
script:
|
||||||
- chmod +x scripts/bump-version.sh
|
- chmod +x scripts/bump-version.sh
|
||||||
- ./scripts/bump-version.sh
|
- ./scripts/bump-version.sh
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ scripts/start-runner-macos.sh
|
|||||||
- At the end of a successful `master` pipeline (`release` stage, after packaging and `update-wiki`), `bump-version` runs `scripts/bump-version.sh`:
|
- At the end of a successful `master` pipeline (`release` stage, after packaging and `update-wiki`), `bump-version` runs `scripts/bump-version.sh`:
|
||||||
1. Checks `GITLAB_TOKEN` expiration via GitLab API and, if within `TOKEN_ROTATE_THRESHOLD_DAYS` (default `30`) and the `GITLAB_TOKEN` CI/CD variable is API-writable, self-rotates the token and updates the CI/CD variable automatically.
|
1. Checks `GITLAB_TOKEN` expiration via GitLab API and, if within `TOKEN_ROTATE_THRESHOLD_DAYS` (default `30`) and the `GITLAB_TOKEN` CI/CD variable is API-writable, self-rotates the token and updates the CI/CD variable automatically.
|
||||||
2. Creates release tag `vX.Y.Z` at `CI_COMMIT_SHA` via the GitLab Tags API (if absent).
|
2. Creates release tag `vX.Y.Z` at `CI_COMMIT_SHA` via the GitLab Tags API (if absent).
|
||||||
3. Increments `PATCH` in `VERSION` (`X.Y.(Z+1)`), commits `chore: bump version to ... [skip ci]`, and pushes to `master` with `-o ci.skip`. Tag pipelines (`$CI_COMMIT_TAG`) are skipped in `workflow: rules:` to prevent loops.
|
3. Increments `PATCH` in `VERSION` (`X.Y.(Z+1)`), commits `chore: bump version to ... [skip ci]` on `master` via the GitLab Repository Commits API (skipping if remote `VERSION` is already ahead). Tag pipelines (`$CI_COMMIT_TAG`) are skipped in `workflow: rules:` to prevent loops.
|
||||||
|
|
||||||
### VS Code & CMake Presets
|
### VS Code & CMake Presets
|
||||||
Pre-configured tasks, launch configurations, and CMake presets are available:
|
Pre-configured tasks, launch configurations, and CMake presets are available:
|
||||||
|
|||||||
+43
-71
@@ -3,8 +3,8 @@
|
|||||||
# 1. Checks GITLAB_TOKEN expiration and self-rotates + updates the GitLab CI/CD
|
# 1. Checks GITLAB_TOKEN expiration and self-rotates + updates the GitLab CI/CD
|
||||||
# variable if expiry is within TOKEN_ROTATE_THRESHOLD_DAYS (default: 30).
|
# variable if expiry is within TOKEN_ROTATE_THRESHOLD_DAYS (default: 30).
|
||||||
# 2. Creates release Git tag v<BUILT_VERSION> at CI_COMMIT_SHA (if absent).
|
# 2. Creates release Git tag v<BUILT_VERSION> at CI_COMMIT_SHA (if absent).
|
||||||
# 3. Increments patch version in VERSION, commits with [skip ci], and pushes
|
# 3. Increments patch version in VERSION on the target branch via GitLab
|
||||||
# to the target branch (retrying on concurrent pushes).
|
# Repository Commits API with [skip ci].
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -36,21 +36,11 @@ API_ROOT="${CI_API_V4_URL:-https://gitlab.com/api/v4}"
|
|||||||
PROJECT_API="${API_ROOT}/projects/${CI_PROJECT_ID}"
|
PROJECT_API="${API_ROOT}/projects/${CI_PROJECT_ID}"
|
||||||
|
|
||||||
WORK_TMP="$(mktemp -d)"
|
WORK_TMP="$(mktemp -d)"
|
||||||
ASKPASS_SCRIPT="${WORK_TMP}/git-askpass.sh"
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -rf "$WORK_TMP"
|
rm -rf "$WORK_TMP"
|
||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
cat > "$ASKPASS_SCRIPT" <<'EOF'
|
|
||||||
#!/bin/sh
|
|
||||||
case "$1" in
|
|
||||||
*Username*|*username*) printf '%s\n' "oauth2" ;;
|
|
||||||
*) printf '%s\n' "${GITLAB_TOKEN}" ;;
|
|
||||||
esac
|
|
||||||
EOF
|
|
||||||
chmod 700 "$ASKPASS_SCRIPT"
|
|
||||||
|
|
||||||
parse_semver() {
|
parse_semver() {
|
||||||
local v="$1"
|
local v="$1"
|
||||||
if ! [[ "$v" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
if ! [[ "$v" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||||
@@ -253,76 +243,58 @@ create_release_tag() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
bump_and_commit_version() {
|
commit_version_bump() {
|
||||||
local built_version="$1"
|
local built_version="$1"
|
||||||
|
local encoded_branch
|
||||||
|
encoded_branch="$(jq -rn --arg b "${TARGET_BRANCH}" '$b|@uri')"
|
||||||
|
|
||||||
local remote_url="${BUMP_GIT_REMOTE:-}"
|
local base_version="$built_version"
|
||||||
if [ -z "$remote_url" ]; then
|
local remote_ver_file="${WORK_TMP}/remote_version.txt"
|
||||||
if [ -z "${CI_SERVER_HOST:-}" ] || [ -z "${CI_PROJECT_PATH:-}" ]; then
|
local raw_code
|
||||||
echo "ERROR: CI_SERVER_HOST and CI_PROJECT_PATH must be set for git push" >&2
|
raw_code=$(curl -s -o "$remote_ver_file" -w '%{http_code}' \
|
||||||
return 1
|
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||||
fi
|
"${PROJECT_API}/repository/files/VERSION/raw?ref=${encoded_branch}")
|
||||||
remote_url="${CI_SERVER_PROTOCOL:-https}://${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
|
|
||||||
fi
|
|
||||||
|
|
||||||
git config user.name "${GITLAB_USER_NAME:-Asteria CI}"
|
|
||||||
git config user.email "${GITLAB_USER_EMAIL:-ci@asteria-bookreader.local}"
|
|
||||||
|
|
||||||
local push_opts=()
|
|
||||||
if [[ "$remote_url" == http://* ]] || [[ "$remote_url" == https://* ]]; then
|
|
||||||
push_opts+=(-o ci.skip)
|
|
||||||
fi
|
|
||||||
|
|
||||||
local next_version
|
|
||||||
next_version="$(increment_patch "$built_version")"
|
|
||||||
printf '%s\n' "$next_version" > VERSION
|
|
||||||
|
|
||||||
if git diff --quiet VERSION; then
|
|
||||||
echo "VERSION already at ${next_version}; nothing to commit."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
git add VERSION
|
|
||||||
git commit -m "chore: bump version to ${next_version} [skip ci]"
|
|
||||||
|
|
||||||
if GIT_ASKPASS="$ASKPASS_SCRIPT" GIT_TERMINAL_PROMPT=0 \
|
|
||||||
git push ${push_opts[@]+"${push_opts[@]}"} "$remote_url" "HEAD:refs/heads/${TARGET_BRANCH}"; then
|
|
||||||
echo "Bumped VERSION from ${built_version} to ${next_version} and pushed to ${TARGET_BRANCH}."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fallback only if origin moved during the pipeline run
|
|
||||||
local attempt
|
|
||||||
for attempt in 1 2; do
|
|
||||||
echo "Push rejected (remote ${TARGET_BRANCH} moved); fetching latest and retrying (${attempt}/2)..."
|
|
||||||
GIT_ASKPASS="$ASKPASS_SCRIPT" GIT_TERMINAL_PROMPT=0 \
|
|
||||||
git fetch "$remote_url" "$TARGET_BRANCH"
|
|
||||||
git checkout -f -B "$TARGET_BRANCH" FETCH_HEAD
|
|
||||||
|
|
||||||
|
if [ "$raw_code" = "200" ]; then
|
||||||
local remote_version
|
local remote_version
|
||||||
remote_version="$(tr -d '[:space:]' < VERSION)"
|
remote_version="$(tr -d '[:space:]' < "$remote_ver_file")"
|
||||||
parse_semver "$remote_version"
|
parse_semver "$remote_version"
|
||||||
|
|
||||||
if semver_gt "$remote_version" "$built_version"; then
|
if semver_gt "$remote_version" "$built_version"; then
|
||||||
echo "Remote VERSION (${remote_version}) is already ahead of built version (${built_version}); skipping VERSION bump commit."
|
echo "Remote VERSION (${remote_version}) is already ahead of built version (${built_version}); skipping VERSION bump commit."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
base_version="$remote_version"
|
||||||
|
fi
|
||||||
|
|
||||||
next_version="$(increment_patch "$remote_version")"
|
local next_version
|
||||||
printf '%s\n' "$next_version" > VERSION
|
next_version="$(increment_patch "$base_version")"
|
||||||
git add VERSION
|
|
||||||
git commit -m "chore: bump version to ${next_version} [skip ci]"
|
|
||||||
|
|
||||||
if GIT_ASKPASS="$ASKPASS_SCRIPT" GIT_TERMINAL_PROMPT=0 \
|
local commit_resp="${WORK_TMP}/commit_resp.json"
|
||||||
git push ${push_opts[@]+"${push_opts[@]}"} "$remote_url" "HEAD:refs/heads/${TARGET_BRANCH}"; then
|
local commit_code
|
||||||
echo "Bumped VERSION from ${remote_version} to ${next_version} and pushed to ${TARGET_BRANCH}."
|
commit_code=$(jq -n \
|
||||||
return 0
|
--arg branch "${TARGET_BRANCH}" \
|
||||||
fi
|
--arg msg "chore: bump version to ${next_version} [skip ci]" \
|
||||||
sleep 2
|
--arg content "${next_version}"$'\n' \
|
||||||
done
|
'{
|
||||||
|
branch: $branch,
|
||||||
|
commit_message: $msg,
|
||||||
|
actions: [{action: "update", file_path: "VERSION", content: $content}]
|
||||||
|
}' | \
|
||||||
|
curl -s -o "$commit_resp" -w '%{http_code}' -X POST \
|
||||||
|
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||||
|
--header "Content-Type: application/json" \
|
||||||
|
--data-binary @- \
|
||||||
|
"${PROJECT_API}/repository/commits")
|
||||||
|
|
||||||
echo "ERROR: Failed to push bumped VERSION to ${TARGET_BRANCH}." >&2
|
if [ "$commit_code" = "201" ] || [ "$commit_code" = "200" ]; then
|
||||||
return 1
|
local commit_sha
|
||||||
|
commit_sha="$(jq -r '.short_id // .id // "unknown"' "$commit_resp")"
|
||||||
|
echo "Bumped VERSION from ${base_version} to ${next_version} on ${TARGET_BRANCH} (${commit_sha})."
|
||||||
|
else
|
||||||
|
echo "ERROR: Failed to commit VERSION bump to ${TARGET_BRANCH} (HTTP ${commit_code})" >&2
|
||||||
|
cat "$commit_resp" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
BUILT_VERSION="$(tr -d '[:space:]' < VERSION)"
|
BUILT_VERSION="$(tr -d '[:space:]' < VERSION)"
|
||||||
@@ -330,4 +302,4 @@ parse_semver "$BUILT_VERSION"
|
|||||||
|
|
||||||
ensure_fresh_token
|
ensure_fresh_token
|
||||||
create_release_tag "$BUILT_VERSION"
|
create_release_tag "$BUILT_VERSION"
|
||||||
bump_and_commit_version "$BUILT_VERSION"
|
commit_version_bump "$BUILT_VERSION"
|
||||||
Reference in new issue
Block a user