swtich to gitea
Asteria Qt CI / rebuild-images (linux-x86_64) (push) Skipped
Asteria Qt CI / rebuild-images (windows-arm64) (push) Skipped
Asteria Qt CI / rebuild-images (windows-x86_64) (push) Skipped
Asteria Qt CI / build-linux (push) Canceled after 0s
Asteria Qt CI / build-linux-arm64 (push) Canceled after 0s
Asteria Qt CI / build-windows (push) Canceled after 0s
Asteria Qt CI / build-windows-arm64 (push) Canceled after 0s
Asteria Qt CI / build-macos (push) Canceled after 0s
Asteria Qt CI / test-linux (push) Canceled after 0s
Asteria Qt CI / test-macos (push) Canceled after 0s
Asteria Qt CI / package-linux (push) Canceled after 0s
Asteria Qt CI / package-linux-arm64 (push) Canceled after 0s
Asteria Qt CI / rebuild-images (linux-arm64) (push) Skipped
Asteria Qt CI / package-windows (push) Canceled after 0s
Asteria Qt CI / package-windows-arm64 (push) Canceled after 0s
Asteria Qt CI / package-macos (push) Canceled after 0s
Asteria Qt CI / release (push) Canceled after 0s
Asteria Qt CI / rebuild-images (linux-x86_64) (push) Skipped
Asteria Qt CI / rebuild-images (windows-arm64) (push) Skipped
Asteria Qt CI / rebuild-images (windows-x86_64) (push) Skipped
Asteria Qt CI / build-linux (push) Canceled after 0s
Asteria Qt CI / build-linux-arm64 (push) Canceled after 0s
Asteria Qt CI / build-windows (push) Canceled after 0s
Asteria Qt CI / build-windows-arm64 (push) Canceled after 0s
Asteria Qt CI / build-macos (push) Canceled after 0s
Asteria Qt CI / test-linux (push) Canceled after 0s
Asteria Qt CI / test-macos (push) Canceled after 0s
Asteria Qt CI / package-linux (push) Canceled after 0s
Asteria Qt CI / package-linux-arm64 (push) Canceled after 0s
Asteria Qt CI / rebuild-images (linux-arm64) (push) Skipped
Asteria Qt CI / package-windows (push) Canceled after 0s
Asteria Qt CI / package-windows-arm64 (push) Canceled after 0s
Asteria Qt CI / package-macos (push) Canceled after 0s
Asteria Qt CI / release (push) Canceled after 0s
This commit is contained in:
14 files changed
+981
-841
No files matched your search
+218
-198
@@ -1,10 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
# End-of-pipeline release automation for Asteria Qt (master branch only):
|
||||
# 1. Checks GITLAB_TOKEN expiration and self-rotates + updates the GitLab CI/CD
|
||||
# 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).
|
||||
# 3. Increments patch version in VERSION on the target branch via GitLab
|
||||
# Repository Commits API with [skip ci].
|
||||
# End-of-pipeline release automation for Asteria Qt on Gitea (master branch only):
|
||||
# 1. Creates Gitea Release + Git tag v<BUILT_VERSION> at target commit (if absent).
|
||||
# 2. Uploads packaged binaries from --assets-dir to the Gitea Release.
|
||||
# 3. Increments patch version in VERSION on the target branch via Gitea Contents
|
||||
# API with [skip ci].
|
||||
#
|
||||
# Usage:
|
||||
# scripts/bump-version.sh [--assets-dir <dir>] [--attach-if-released]
|
||||
#
|
||||
# Required environment:
|
||||
# BUILD_TOKEN Gitea token with write:repository (and write:package)
|
||||
#
|
||||
# Optional environment (auto-populated by Gitea Actions):
|
||||
# GITHUB_SERVER_URL Default: https://gitea.agel.dev
|
||||
# GITHUB_REPOSITORY Default: Asteria/asteria-qt
|
||||
# GITHUB_REF_NAME Branch name (must be master unless overridden)
|
||||
# GITHUB_SHA Commit SHA to tag for the release
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -12,28 +23,60 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
ASSETS_DIR="${RELEASE_ASSETS_DIR:-}"
|
||||
ATTACH_IF_RELEASED=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--assets-dir)
|
||||
ASSETS_DIR="${2:?Missing value for --assets-dir}"
|
||||
shift 2
|
||||
;;
|
||||
--attach-if-released)
|
||||
ATTACH_IF_RELEASED=true
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
sed -n '2,18p' "$0" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: Unknown argument: $1" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
DEFAULT_BRANCH="${CI_DEFAULT_BRANCH:-master}"
|
||||
TARGET_BRANCH="${CI_COMMIT_BRANCH:-}"
|
||||
TOKEN_ROTATE_THRESHOLD_DAYS="${TOKEN_ROTATE_THRESHOLD_DAYS:-30}"
|
||||
TOKEN_ROTATE_LIFETIME_DAYS="${TOKEN_ROTATE_LIFETIME_DAYS:-360}"
|
||||
TARGET_BRANCH="${GITHUB_REF_NAME:-${CI_COMMIT_BRANCH:-}}"
|
||||
if [ -z "$TARGET_BRANCH" ] && command -v git >/dev/null 2>&1; then
|
||||
TARGET_BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
|
||||
fi
|
||||
|
||||
if [ "$TARGET_BRANCH" != "$DEFAULT_BRANCH" ] && [ "$TARGET_BRANCH" != "master" ]; then
|
||||
echo "Skipping version bump: branch is '${TARGET_BRANCH:-unknown}', not '${DEFAULT_BRANCH}'."
|
||||
echo "Skipping release/version bump: branch is '${TARGET_BRANCH:-unknown}', not '${DEFAULT_BRANCH}'."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -z "${GITLAB_TOKEN:-}" ]; then
|
||||
echo "ERROR: GITLAB_TOKEN CI/CD variable is not set" >&2
|
||||
TOKEN="${BUILD_TOKEN:-${GITEA_TOKEN:-}}"
|
||||
if [ -z "$TOKEN" ]; then
|
||||
echo "ERROR: BUILD_TOKEN secret is not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${CI_PROJECT_ID:-}" ] || [ -z "${CI_COMMIT_SHA:-}" ]; then
|
||||
echo "ERROR: CI_PROJECT_ID and CI_COMMIT_SHA must be set" >&2
|
||||
COMMIT_SHA="${GITHUB_SHA:-${CI_COMMIT_SHA:-}}"
|
||||
if [ -z "$COMMIT_SHA" ] && command -v git >/dev/null 2>&1; then
|
||||
COMMIT_SHA="$(git rev-parse HEAD 2>/dev/null || true)"
|
||||
fi
|
||||
if [ -z "$COMMIT_SHA" ]; then
|
||||
echo "ERROR: GITHUB_SHA / COMMIT_SHA is not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
API_ROOT="${CI_API_V4_URL:-https://gitlab.com/api/v4}"
|
||||
PROJECT_API="${API_ROOT}/projects/${CI_PROJECT_ID}"
|
||||
SERVER_URL="${GITHUB_SERVER_URL:-https://gitea.agel.dev}"
|
||||
SERVER_URL="${SERVER_URL%/}"
|
||||
REPO_PATH="${GITHUB_REPOSITORY:-Asteria/asteria-qt}"
|
||||
API_URL="${SERVER_URL}/api/v1/repos/${REPO_PATH}"
|
||||
|
||||
WORK_TMP="$(mktemp -d)"
|
||||
cleanup() {
|
||||
@@ -74,172 +117,125 @@ increment_patch() {
|
||||
echo "${major}.${minor}.$((patch + 1))"
|
||||
}
|
||||
|
||||
ensure_fresh_token() {
|
||||
local info_file="${WORK_TMP}/token_self.json"
|
||||
local info_code
|
||||
info_code=$(curl -s -o "$info_file" -w '%{http_code}' \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
"${API_ROOT}/personal_access_tokens/self")
|
||||
|
||||
if [ "$info_code" != "200" ]; then
|
||||
echo "WARNING: Could not query token expiry (HTTP ${info_code}); proceeding with current GITLAB_TOKEN."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local expires_at
|
||||
expires_at="$(jq -r '.expires_at // empty' "$info_file")"
|
||||
if [ -z "$expires_at" ]; then
|
||||
echo "GITLAB_TOKEN has no expiration date; skipping rotation."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local days_left
|
||||
days_left="$(python3 - "$expires_at" <<'PY'
|
||||
from datetime import date
|
||||
import sys
|
||||
exp = date.fromisoformat(sys.argv[1][:10])
|
||||
print((exp - date.today()).days)
|
||||
PY
|
||||
)"
|
||||
echo "GITLAB_TOKEN expires on ${expires_at} (${days_left} days remaining)."
|
||||
|
||||
if [ "$days_left" -gt "$TOKEN_ROTATE_THRESHOLD_DAYS" ]; then
|
||||
echo "Token valid for more than ${TOKEN_ROTATE_THRESHOLD_DAYS} days; no rotation needed."
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Token expires within ${TOKEN_ROTATE_THRESHOLD_DAYS} days; checking CI/CD variable write access before rotating..."
|
||||
|
||||
local var_update_url=""
|
||||
local group_id=""
|
||||
local proj_var_code
|
||||
proj_var_code=$(curl -s -o /dev/null -w '%{http_code}' \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
"${PROJECT_API}/variables/GITLAB_TOKEN")
|
||||
|
||||
if [ "$proj_var_code" = "200" ]; then
|
||||
var_update_url="${PROJECT_API}/variables/GITLAB_TOKEN"
|
||||
else
|
||||
local proj_info="${WORK_TMP}/project.json"
|
||||
local proj_code
|
||||
proj_code=$(curl -s -o "$proj_info" -w '%{http_code}' \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
"${PROJECT_API}")
|
||||
if [ "$proj_code" = "200" ]; then
|
||||
local ns_kind
|
||||
ns_kind="$(jq -r '.namespace.kind // empty' "$proj_info")"
|
||||
if [ "$ns_kind" = "group" ]; then
|
||||
group_id="$(jq -r '.namespace.id // empty' "$proj_info")"
|
||||
if [ -n "$group_id" ]; then
|
||||
local grp_var_code
|
||||
grp_var_code=$(curl -s -o /dev/null -w '%{http_code}' \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
"${API_ROOT}/groups/${group_id}/variables/GITLAB_TOKEN")
|
||||
if [ "$grp_var_code" = "200" ]; then
|
||||
var_update_url="${API_ROOT}/groups/${group_id}/variables/GITLAB_TOKEN"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$var_update_url" ]; then
|
||||
echo "WARNING: GITLAB_TOKEN CI/CD variable is not accessible via API (project check HTTP ${proj_var_code}). Skipping rotation to avoid losing the rotated token."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local new_expires_at
|
||||
new_expires_at="$(python3 - "$TOKEN_ROTATE_LIFETIME_DAYS" <<'PY'
|
||||
from datetime import date, timedelta
|
||||
import sys
|
||||
days = int(sys.argv[1])
|
||||
print((date.today() + timedelta(days=days)).isoformat())
|
||||
PY
|
||||
)"
|
||||
|
||||
local rotate_urls=("${PROJECT_API}/access_tokens/self/rotate?expires_at=${new_expires_at}")
|
||||
if [ -n "$group_id" ]; then
|
||||
rotate_urls+=("${API_ROOT}/groups/${group_id}/access_tokens/self/rotate?expires_at=${new_expires_at}")
|
||||
fi
|
||||
rotate_urls+=("${API_ROOT}/personal_access_tokens/self/rotate?expires_at=${new_expires_at}")
|
||||
|
||||
local rotated_token=""
|
||||
local rot_file="${WORK_TMP}/rotate_resp.json"
|
||||
local rot_code=""
|
||||
local url
|
||||
for url in "${rotate_urls[@]}"; do
|
||||
rot_code=$(curl -s -o "$rot_file" -w '%{http_code}' -X POST \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
"$url")
|
||||
if [ "$rot_code" = "200" ] || [ "$rot_code" = "201" ]; then
|
||||
rotated_token="$(jq -r '.token // empty' "$rot_file")"
|
||||
if [ -n "$rotated_token" ]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$rotated_token" ]; then
|
||||
echo "ERROR: Failed to self-rotate GITLAB_TOKEN (last HTTP ${rot_code}):" >&2
|
||||
jq 'del(.token)' "$rot_file" >&2 || true
|
||||
return 1
|
||||
fi
|
||||
|
||||
export GITLAB_TOKEN="$rotated_token"
|
||||
|
||||
local put_file="${WORK_TMP}/var_put.json"
|
||||
local put_code
|
||||
put_code=$(jq -n --arg v "${GITLAB_TOKEN}" '{value: $v}' | \
|
||||
curl -s -o "$put_file" -w '%{http_code}' -X PUT \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data-binary @- \
|
||||
"$var_update_url")
|
||||
|
||||
if [ "$put_code" != "200" ]; then
|
||||
echo "ERROR: Rotated GITLAB_TOKEN, but failed to persist new value to CI/CD variable (HTTP ${put_code}):" >&2
|
||||
cat "$put_file" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Successfully self-rotated GITLAB_TOKEN (new expiry: ${new_expires_at}) and updated CI/CD variable."
|
||||
}
|
||||
|
||||
create_release_tag() {
|
||||
find_or_create_release() {
|
||||
local built_version="$1"
|
||||
local create_if_missing="$2"
|
||||
local tag_name="v${built_version}"
|
||||
local encoded_tag
|
||||
encoded_tag="$(jq -rn --arg t "${tag_name}" '$t|@uri')"
|
||||
local rel_file="${WORK_TMP}/release.json"
|
||||
|
||||
local exists_code
|
||||
exists_code=$(curl -s -o /dev/null -w '%{http_code}' \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
"${PROJECT_API}/repository/tags/${encoded_tag}")
|
||||
local get_code
|
||||
get_code=$(curl -s -o "$rel_file" -w '%{http_code}' \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--header "Accept: application/json" \
|
||||
"${API_URL}/releases/tags/${tag_name}")
|
||||
|
||||
if [ "$exists_code" = "200" ]; then
|
||||
echo "Tag ${tag_name} already exists; skipping tag creation."
|
||||
return 0
|
||||
if [ "$get_code" = "200" ]; then
|
||||
local rel_id
|
||||
rel_id="$(jq -r '.id // empty' "$rel_file")"
|
||||
if [ -n "$rel_id" ]; then
|
||||
echo "Found existing Gitea release ${tag_name} (id=${rel_id})." >&2
|
||||
printf '%s\n' "$rel_id"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
local tag_resp="${WORK_TMP}/tag_resp.json"
|
||||
if [ "$create_if_missing" != "true" ]; then
|
||||
echo "Release ${tag_name} does not exist yet (HTTP ${get_code}); skipping asset upload." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local run_id="${GITHUB_RUN_ID:-0}"
|
||||
local run_url="${SERVER_URL}/${REPO_PATH}/actions/runs/${run_id}"
|
||||
local body
|
||||
body="Automated build from \`${TARGET_BRANCH}\` @ \`${COMMIT_SHA:0:7}\` (run [#${run_id}](${run_url}))."
|
||||
|
||||
local create_code
|
||||
create_code=$(jq -n \
|
||||
--arg tag "${tag_name}" \
|
||||
--arg ref "${CI_COMMIT_SHA}" \
|
||||
--arg msg "Release ${tag_name} (pipeline #${CI_PIPELINE_ID:-0})" \
|
||||
'{tag_name: $tag, ref: $ref, message: $msg}' | \
|
||||
curl -s -o "$tag_resp" -w '%{http_code}' -X POST \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
--arg target "${COMMIT_SHA}" \
|
||||
--arg name "Asteria ${tag_name}" \
|
||||
--arg body "${body}" \
|
||||
'{
|
||||
tag_name: $tag,
|
||||
target_commitish: $target,
|
||||
name: $name,
|
||||
body: $body,
|
||||
draft: false,
|
||||
prerelease: false
|
||||
}' | \
|
||||
curl -s -o "$rel_file" -w '%{http_code}' -X POST \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--header "Content-Type: application/json" \
|
||||
--header "Accept: application/json" \
|
||||
--data-binary @- \
|
||||
"${PROJECT_API}/repository/tags")
|
||||
"${API_URL}/releases")
|
||||
|
||||
if [ "$create_code" = "201" ] || [ "$create_code" = "200" ]; then
|
||||
echo "Created release tag ${tag_name} at ${CI_COMMIT_SHA}"
|
||||
else
|
||||
echo "ERROR: Failed to create tag ${tag_name} (HTTP ${create_code})" >&2
|
||||
cat "$tag_resp" >&2
|
||||
return 1
|
||||
local rel_id
|
||||
rel_id="$(jq -r '.id // empty' "$rel_file")"
|
||||
echo "Created Gitea release ${tag_name} at ${COMMIT_SHA:0:7} (id=${rel_id})." >&2
|
||||
printf '%s\n' "$rel_id"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "ERROR: Failed to create release ${tag_name} (HTTP ${create_code}):" >&2
|
||||
cat "$rel_file" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
upload_release_assets() {
|
||||
local release_id="$1"
|
||||
local dir="$2"
|
||||
|
||||
if [ -z "$dir" ] || [ ! -d "$dir" ]; then
|
||||
echo "No assets directory provided or directory missing; skipping asset upload."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local existing_assets="${WORK_TMP}/assets.json"
|
||||
local list_code
|
||||
list_code=$(curl -s -o "$existing_assets" -w '%{http_code}' \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--header "Accept: application/json" \
|
||||
"${API_URL}/releases/${release_id}/assets")
|
||||
|
||||
local uploaded=0
|
||||
local file
|
||||
while IFS= read -r -d '' file; do
|
||||
local fname
|
||||
fname="$(basename "$file")"
|
||||
|
||||
# Delete pre-existing asset with same name so re-runs are idempotent
|
||||
if [ "$list_code" = "200" ]; then
|
||||
local existing_id
|
||||
existing_id="$(jq -r --arg n "$fname" '.[] | select(.name == $n) | .id' "$existing_assets" | head -n1 || true)"
|
||||
if [ -n "$existing_id" ]; then
|
||||
curl -s -o /dev/null -X DELETE \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
"${API_URL}/releases/${release_id}/assets/${existing_id}" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
local up_resp="${WORK_TMP}/upload_resp.json"
|
||||
local up_code
|
||||
up_code=$(curl -s -o "$up_resp" -w '%{http_code}' -X POST \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--header "Accept: application/json" \
|
||||
-F "attachment=@${file};filename=${fname}" \
|
||||
"${API_URL}/releases/${release_id}/assets")
|
||||
|
||||
if [ "$up_code" = "201" ] || [ "$up_code" = "200" ]; then
|
||||
echo "Uploaded release asset: ${fname}"
|
||||
uploaded=$((uploaded + 1))
|
||||
else
|
||||
echo "ERROR: Failed to upload asset ${fname} (HTTP ${up_code}):" >&2
|
||||
cat "$up_resp" >&2
|
||||
return 1
|
||||
fi
|
||||
done < <(find "$dir" -maxdepth 2 -type f \( -name '*.tar.gz' -o -name '*.AppImage' -o -name '*.zip' -o -name '*.dmg' \) -print0 | sort -z)
|
||||
|
||||
if [ "$uploaded" -eq 0 ]; then
|
||||
echo "WARNING: No release binary files found in ${dir}" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -248,50 +244,67 @@ commit_version_bump() {
|
||||
local encoded_branch
|
||||
encoded_branch="$(jq -rn --arg b "${TARGET_BRANCH}" '$b|@uri')"
|
||||
|
||||
local base_version="$built_version"
|
||||
local remote_ver_file="${WORK_TMP}/remote_version.txt"
|
||||
local raw_code
|
||||
raw_code=$(curl -s -o "$remote_ver_file" -w '%{http_code}' \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
"${PROJECT_API}/repository/files/VERSION/raw?ref=${encoded_branch}")
|
||||
local content_file="${WORK_TMP}/version_content.json"
|
||||
local get_code
|
||||
get_code=$(curl -s -o "$content_file" -w '%{http_code}' \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--header "Accept: application/json" \
|
||||
"${API_URL}/contents/VERSION?ref=${encoded_branch}")
|
||||
|
||||
if [ "$raw_code" = "200" ]; then
|
||||
local remote_version
|
||||
remote_version="$(tr -d '[:space:]' < "$remote_ver_file")"
|
||||
parse_semver "$remote_version"
|
||||
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."
|
||||
return 0
|
||||
fi
|
||||
base_version="$remote_version"
|
||||
if [ "$get_code" != "200" ]; then
|
||||
echo "ERROR: Failed to read remote VERSION from ${TARGET_BRANCH} (HTTP ${get_code}):" >&2
|
||||
cat "$content_file" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local file_sha remote_b64 remote_version
|
||||
file_sha="$(jq -r '.sha // empty' "$content_file")"
|
||||
remote_b64="$(jq -r '.content // empty' "$content_file" | tr -d '\n\r ')"
|
||||
remote_version="$(printf '%s' "$remote_b64" | (base64 -d 2>/dev/null || base64 -D) | tr -d '[:space:]')"
|
||||
|
||||
if [ -z "$file_sha" ] || [ -z "$remote_version" ]; then
|
||||
echo "ERROR: Unexpected Gitea contents response for VERSION" >&2
|
||||
cat "$content_file" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
parse_semver "$remote_version"
|
||||
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."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local next_version
|
||||
next_version="$(increment_patch "$base_version")"
|
||||
next_version="$(increment_patch "$remote_version")"
|
||||
local next_b64
|
||||
next_b64="$(printf '%s\n' "$next_version" | base64 | tr -d '\n\r')"
|
||||
|
||||
local commit_resp="${WORK_TMP}/commit_resp.json"
|
||||
local commit_code
|
||||
commit_code=$(jq -n \
|
||||
--arg branch "${TARGET_BRANCH}" \
|
||||
--arg msg "chore: bump version to ${next_version} [skip ci]" \
|
||||
--arg content "${next_version}"$'\n' \
|
||||
--arg content "${next_b64}" \
|
||||
--arg sha "${file_sha}" \
|
||||
'{
|
||||
branch: $branch,
|
||||
commit_message: $msg,
|
||||
actions: [{action: "update", file_path: "VERSION", content: $content}]
|
||||
message: $msg,
|
||||
content: $content,
|
||||
sha: $sha
|
||||
}' | \
|
||||
curl -s -o "$commit_resp" -w '%{http_code}' -X POST \
|
||||
--header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
|
||||
curl -s -o "$commit_resp" -w '%{http_code}' -X PUT \
|
||||
--header "Authorization: token ${TOKEN}" \
|
||||
--header "Content-Type: application/json" \
|
||||
--header "Accept: application/json" \
|
||||
--data-binary @- \
|
||||
"${PROJECT_API}/repository/commits")
|
||||
"${API_URL}/contents/VERSION")
|
||||
|
||||
if [ "$commit_code" = "201" ] || [ "$commit_code" = "200" ]; then
|
||||
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})."
|
||||
if [ "$commit_code" = "200" ] || [ "$commit_code" = "201" ]; then
|
||||
local new_sha
|
||||
new_sha="$(jq -r '.commit.sha // "unknown"' "$commit_resp")"
|
||||
echo "Bumped VERSION from ${remote_version} to ${next_version} on ${TARGET_BRANCH} (${new_sha:0:7})."
|
||||
else
|
||||
echo "ERROR: Failed to commit VERSION bump to ${TARGET_BRANCH} (HTTP ${commit_code})" >&2
|
||||
echo "ERROR: Failed to commit VERSION bump to ${TARGET_BRANCH} (HTTP ${commit_code}):" >&2
|
||||
cat "$commit_resp" >&2
|
||||
return 1
|
||||
fi
|
||||
@@ -300,6 +313,13 @@ commit_version_bump() {
|
||||
BUILT_VERSION="$(tr -d '[:space:]' < VERSION)"
|
||||
parse_semver "$BUILT_VERSION"
|
||||
|
||||
ensure_fresh_token
|
||||
create_release_tag "$BUILT_VERSION"
|
||||
if [ "$ATTACH_IF_RELEASED" = true ]; then
|
||||
if RELEASE_ID="$(find_or_create_release "$BUILT_VERSION" "false")"; then
|
||||
upload_release_assets "$RELEASE_ID" "$ASSETS_DIR"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RELEASE_ID="$(find_or_create_release "$BUILT_VERSION" "true")"
|
||||
upload_release_assets "$RELEASE_ID" "$ASSETS_DIR"
|
||||
commit_version_bump "$BUILT_VERSION"
|
||||
@@ -58,8 +58,19 @@ MINOR="${BASH_REMATCH[2]}"
|
||||
PATCH="${BASH_REMATCH[3]}"
|
||||
|
||||
# Determine current branch and short SHA
|
||||
BRANCH="${OVERRIDE_BRANCH:-${CI_COMMIT_BRANCH:-${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:-${CI_COMMIT_REF_NAME:-}}}}"
|
||||
SHORT_SHA="${OVERRIDE_SHA:-${CI_COMMIT_SHORT_SHA:-}}"
|
||||
GITEA_BRANCH=""
|
||||
if [ -n "${GITHUB_HEAD_REF:-}" ]; then
|
||||
GITEA_BRANCH="${GITHUB_HEAD_REF}"
|
||||
elif [ "${GITHUB_REF_TYPE:-}" != "tag" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then
|
||||
GITEA_BRANCH="${GITHUB_REF_NAME}"
|
||||
fi
|
||||
GITEA_SHORT_SHA=""
|
||||
if [ -n "${GITHUB_SHA:-}" ]; then
|
||||
GITEA_SHORT_SHA="${GITHUB_SHA:0:7}"
|
||||
fi
|
||||
|
||||
BRANCH="${OVERRIDE_BRANCH:-${GITEA_BRANCH:-${CI_COMMIT_BRANCH:-${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:-${CI_COMMIT_REF_NAME:-}}}}}"
|
||||
SHORT_SHA="${OVERRIDE_SHA:-${GITEA_SHORT_SHA:-${CI_COMMIT_SHORT_SHA:-}}}"
|
||||
|
||||
HAS_GIT=false
|
||||
if command -v git >/dev/null 2>&1 && git -C "$PROJECT_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
brew update
|
||||
brew install cmake ninja pkg-config uchardet minizip libarchive gitlab-runner
|
||||
brew install cmake ninja pkg-config uchardet minizip libarchive gitea-runner
|
||||
|
||||
echo ""
|
||||
echo "Installing Qt 6.12.0 via aqtinstall → /opt/qt ..."
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# Start a local GitLab Runner for macOS builds (shell executor).
|
||||
# Start a local Gitea Actions Runner for macOS builds (host mode).
|
||||
#
|
||||
# First-time registration usage:
|
||||
# RUNNER_TOKEN="glrt-..." ./scripts/start-runner-macos.sh
|
||||
# or with a legacy registration token:
|
||||
# REGISTRATION_TOKEN="..." ./scripts/start-runner-macos.sh
|
||||
# RUNNER_TOKEN="..." ./scripts/start-runner-macos.sh
|
||||
#
|
||||
# Subsequent runs (once config.toml exists):
|
||||
# Subsequent runs (once .runner exists):
|
||||
# ./scripts/start-runner-macos.sh
|
||||
|
||||
set -euo pipefail
|
||||
@@ -18,21 +16,32 @@ fi
|
||||
|
||||
export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"
|
||||
|
||||
if ! command -v gitlab-runner >/dev/null 2>&1; then
|
||||
RUNNER_BIN=""
|
||||
if command -v gitea-runner >/dev/null 2>&1; then
|
||||
RUNNER_BIN="gitea-runner"
|
||||
elif command -v act_runner >/dev/null 2>&1; then
|
||||
RUNNER_BIN="act_runner"
|
||||
else
|
||||
if ! command -v brew >/dev/null 2>&1; then
|
||||
echo "ERROR: Homebrew is required to install gitlab-runner. Please install Homebrew from https://brew.sh" >&2
|
||||
echo "ERROR: Homebrew is required to install gitea-runner. Please install Homebrew from https://brew.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "gitlab-runner not found. Installing via Homebrew..."
|
||||
brew install gitlab-runner
|
||||
echo "gitea-runner not found. Installing via Homebrew..."
|
||||
brew install gitea-runner
|
||||
if command -v gitea-runner >/dev/null 2>&1; then
|
||||
RUNNER_BIN="gitea-runner"
|
||||
else
|
||||
RUNNER_BIN="act_runner"
|
||||
fi
|
||||
fi
|
||||
|
||||
RUNNER_CONFIG_DIR="${RUNNER_CONFIG_DIR:-$HOME/.gitlab-runner}"
|
||||
CONFIG_FILE="${RUNNER_CONFIG_DIR}/config.toml"
|
||||
RUNNER_CONFIG_DIR="${RUNNER_CONFIG_DIR:-$HOME/.gitea-runner}"
|
||||
CONFIG_FILE="${RUNNER_CONFIG_DIR}/config.yaml"
|
||||
RUNNER_FILE="${RUNNER_CONFIG_DIR}/.runner"
|
||||
RUNNER_WORKDIR="${RUNNER_WORKDIR:-${RUNNER_CONFIG_DIR}/builds}"
|
||||
CI_SERVER_URL="${CI_SERVER_URL:-https://gitlab.com}"
|
||||
GITEA_INSTANCE_URL="${GITEA_INSTANCE_URL:-${CI_SERVER_URL:-https://gitea.agel.dev}}"
|
||||
RUNNER_NAME="${RUNNER_NAME:-asteria-qt-macos-runner}"
|
||||
RUNNER_TAGS="${RUNNER_TAGS:-macos-qt}"
|
||||
RUNNER_LABELS="${RUNNER_LABELS:-${RUNNER_TAGS:-macos-qt:host}}"
|
||||
|
||||
export QT_MACOS_DIR="${QT_MACOS_DIR:-/opt/qt/6.12.0/macos}"
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
@@ -43,39 +52,48 @@ if command -v brew >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
mkdir -p "${RUNNER_CONFIG_DIR}" "${RUNNER_WORKDIR}"
|
||||
cd "${RUNNER_CONFIG_DIR}"
|
||||
|
||||
if [ ! -f "${CONFIG_FILE}" ]; then
|
||||
if [ -n "${RUNNER_TOKEN:-}" ]; then
|
||||
echo "Registering runner with authentication token..."
|
||||
echo "NOTE: Ensure the runner in GitLab has the tag '${RUNNER_TAGS}' assigned."
|
||||
gitlab-runner register \
|
||||
--non-interactive \
|
||||
cat > "${CONFIG_FILE}" <<EOF
|
||||
log:
|
||||
level: info
|
||||
|
||||
runner:
|
||||
file: ${RUNNER_FILE}
|
||||
capacity: 1
|
||||
timeout: 3h
|
||||
insecure: false
|
||||
fetch_timeout: 5s
|
||||
fetch_interval: 2s
|
||||
labels:
|
||||
- "${RUNNER_LABELS}"
|
||||
|
||||
cache:
|
||||
enabled: true
|
||||
dir: ${RUNNER_CONFIG_DIR}/cache
|
||||
|
||||
host:
|
||||
workdir_parent: ${RUNNER_WORKDIR}
|
||||
EOF
|
||||
|
||||
if [ ! -f "${RUNNER_FILE}" ]; then
|
||||
TOKEN="${RUNNER_TOKEN:-${GITEA_RUNNER_REGISTRATION_TOKEN:-${REGISTRATION_TOKEN:-}}}"
|
||||
if [ -n "${TOKEN}" ]; then
|
||||
echo "Registering Gitea runner '${RUNNER_NAME}' at '${GITEA_INSTANCE_URL}' with labels '${RUNNER_LABELS}'..."
|
||||
"${RUNNER_BIN}" register \
|
||||
--no-interactive \
|
||||
--config "${CONFIG_FILE}" \
|
||||
--url "${CI_SERVER_URL}" \
|
||||
--token "${RUNNER_TOKEN}" \
|
||||
--executor shell \
|
||||
--shell bash \
|
||||
--name "${RUNNER_NAME}"
|
||||
elif [ -n "${REGISTRATION_TOKEN:-}" ]; then
|
||||
echo "Registering runner with legacy registration token and tags '${RUNNER_TAGS}'..."
|
||||
gitlab-runner register \
|
||||
--non-interactive \
|
||||
--config "${CONFIG_FILE}" \
|
||||
--url "${CI_SERVER_URL}" \
|
||||
--registration-token "${REGISTRATION_TOKEN}" \
|
||||
--executor shell \
|
||||
--shell bash \
|
||||
--instance "${GITEA_INSTANCE_URL}" \
|
||||
--token "${TOKEN}" \
|
||||
--name "${RUNNER_NAME}" \
|
||||
--tag-list "${RUNNER_TAGS}" \
|
||||
--run-untagged="${RUNNER_RUN_UNTAGGED:-false}" \
|
||||
--locked="${RUNNER_LOCKED:-false}"
|
||||
--labels "${RUNNER_LABELS}"
|
||||
else
|
||||
echo "ERROR: No runner configuration found at ${CONFIG_FILE}." >&2
|
||||
echo "Provide RUNNER_TOKEN (glrt-...) or REGISTRATION_TOKEN to register first:" >&2
|
||||
echo " RUNNER_TOKEN=glrt-... $0" >&2
|
||||
echo "ERROR: No runner registration found at ${RUNNER_FILE}." >&2
|
||||
echo "Provide RUNNER_TOKEN from Gitea (Org/Repo Settings -> Actions -> Runners) to register first:" >&2
|
||||
echo " RUNNER_TOKEN=<token> $0" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Starting local macOS GitLab Runner (config: ${CONFIG_FILE}, workdir: ${RUNNER_WORKDIR})..."
|
||||
exec gitlab-runner run --config "${CONFIG_FILE}" --working-directory "${RUNNER_WORKDIR}"
|
||||
echo "Starting local macOS Gitea Runner (bin: ${RUNNER_BIN}, config: ${CONFIG_FILE}, workdir: ${RUNNER_WORKDIR})..."
|
||||
exec "${RUNNER_BIN}" daemon --config "${CONFIG_FILE}"
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Run Linux CI build/test/package jobs locally using podman or docker.
|
||||
# Usage: test-ci-linux.sh [--build-image] [--image <tag>] [--arm64] [--only-arm64]
|
||||
# Usage: test-ci-linux.sh [--build-image] [--push] [--image <tag>] [--arm64] [--only-arm64]
|
||||
set -euo pipefail
|
||||
|
||||
export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
|
||||
@@ -9,15 +9,17 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
OUTPUT_DIR="$PROJECT_DIR/ci-output"
|
||||
DOCKERFILE="$PROJECT_DIR/docker/Dockerfile.build"
|
||||
IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-registry.gitlab.com/asteria-bookreader/asteria-qt}"
|
||||
IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-gitea.agel.dev/asteria}"
|
||||
CUSTOM_IMAGE=""
|
||||
BUILD_IMAGE=false
|
||||
PUSH_IMAGE=false
|
||||
RUN_X86_64=true
|
||||
RUN_ARM64=false
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--build-image) BUILD_IMAGE=true; shift ;;
|
||||
--push) PUSH_IMAGE=true; BUILD_IMAGE=true; shift ;;
|
||||
--image) CUSTOM_IMAGE="$2"; shift 2 ;;
|
||||
--image=*) CUSTOM_IMAGE="${1#*=}"; shift ;;
|
||||
--arm64) RUN_ARM64=true; shift ;;
|
||||
@@ -37,11 +39,22 @@ else
|
||||
fi
|
||||
echo "Using container runtime: $RUNTIME"
|
||||
|
||||
resolve_image_tag() {
|
||||
local target="$1"
|
||||
if [ -n "$CUSTOM_IMAGE" ]; then
|
||||
echo "$CUSTOM_IMAGE"
|
||||
elif [ "$BUILD_IMAGE" = true ] && [ "$PUSH_IMAGE" = false ]; then
|
||||
echo "asteria-qt-ci-${target}:latest"
|
||||
else
|
||||
echo "${IMAGE_PREFIX}/build-${target}:latest"
|
||||
fi
|
||||
}
|
||||
|
||||
prepare_image() {
|
||||
local target="$1"
|
||||
local image_tag="${CUSTOM_IMAGE:-${IMAGE_PREFIX}/build-${target}:latest}"
|
||||
local image_tag
|
||||
image_tag="$(resolve_image_tag "$target")"
|
||||
if [ "$BUILD_IMAGE" = true ]; then
|
||||
image_tag="${CUSTOM_IMAGE:-asteria-qt-ci-${target}:latest}"
|
||||
echo "==> Building CI image target '$target' ($image_tag) from $DOCKERFILE"
|
||||
DOCKER_BUILDKIT=1 "$RUNTIME" build \
|
||||
--platform linux/amd64 \
|
||||
@@ -50,6 +63,10 @@ prepare_image() {
|
||||
-t "$image_tag" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
if [ "$PUSH_IMAGE" = true ]; then
|
||||
echo "==> Pushing CI image: $image_tag"
|
||||
"$RUNTIME" push "$image_tag"
|
||||
fi
|
||||
elif ! "$RUNTIME" image inspect "$image_tag" &>/dev/null; then
|
||||
echo "==> Pulling prebuilt CI image: $image_tag"
|
||||
"$RUNTIME" pull --platform linux/amd64 "$image_tag"
|
||||
@@ -81,8 +98,7 @@ run_in_container() {
|
||||
# ── Linux x86_64 build, test, and package ────────────────────────────────────
|
||||
if [ "$RUN_X86_64" = true ]; then
|
||||
prepare_image "linux-x86_64"
|
||||
X64_IMAGE="${CUSTOM_IMAGE:-${IMAGE_PREFIX}/build-linux-x86_64:latest}"
|
||||
[ "$BUILD_IMAGE" = true ] && X64_IMAGE="${CUSTOM_IMAGE:-asteria-qt-ci-linux-x86_64:latest}"
|
||||
X64_IMAGE="$(resolve_image_tag "linux-x86_64")"
|
||||
|
||||
echo "==> build-linux & test-linux (x86_64)"
|
||||
CI_SCRIPT='
|
||||
@@ -106,8 +122,7 @@ fi
|
||||
# ── Linux ARM64 build and package ────────────────────────────────────────────
|
||||
if [ "$RUN_ARM64" = true ]; then
|
||||
prepare_image "linux-arm64"
|
||||
ARM64_IMAGE="${CUSTOM_IMAGE:-${IMAGE_PREFIX}/build-linux-arm64:latest}"
|
||||
[ "$BUILD_IMAGE" = true ] && ARM64_IMAGE="${CUSTOM_IMAGE:-asteria-qt-ci-linux-arm64:latest}"
|
||||
ARM64_IMAGE="$(resolve_image_tag "linux-arm64")"
|
||||
|
||||
echo "==> build-linux-arm64"
|
||||
CI_SCRIPT='
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
# Run CI build/package jobs locally using podman or docker.
|
||||
# Usage: test-ci-windows.sh [--build-image] [--image <tag>] [--linux] [--arm64] [--only-arm64]
|
||||
# Usage: test-ci-windows.sh [--build-image] [--push] [--image <tag>] [--linux] [--arm64] [--only-arm64]
|
||||
# --build-image build the CI image target(s) from Dockerfile instead of pulling prebuilt ones
|
||||
# --push build and push the CI image target(s) to IMAGE_PREFIX (implies --build-image)
|
||||
# --linux also run build-linux + package-linux (and arm64 if --arm64 is passed)
|
||||
# --arm64 also run arm64 build + package jobs
|
||||
# --only-arm64 run only arm64 build + package jobs
|
||||
@@ -13,9 +14,10 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
OUTPUT_DIR="$PROJECT_DIR/ci-output"
|
||||
DOCKERFILE="$PROJECT_DIR/docker/Dockerfile.build"
|
||||
IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-registry.gitlab.com/asteria-bookreader/asteria-qt}"
|
||||
IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-gitea.agel.dev/asteria}"
|
||||
CUSTOM_IMAGE=""
|
||||
BUILD_IMAGE=false
|
||||
PUSH_IMAGE=false
|
||||
RUN_LINUX=false
|
||||
RUN_X86_64=true
|
||||
RUN_ARM64=false
|
||||
@@ -23,6 +25,7 @@ RUN_ARM64=false
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--build-image) BUILD_IMAGE=true; shift ;;
|
||||
--push) PUSH_IMAGE=true; BUILD_IMAGE=true; shift ;;
|
||||
--image) CUSTOM_IMAGE="$2"; shift 2 ;;
|
||||
--image=*) CUSTOM_IMAGE="${1#*=}"; shift ;;
|
||||
--linux) RUN_LINUX=true; shift ;;
|
||||
@@ -47,7 +50,7 @@ resolve_image_tag() {
|
||||
local target="$1"
|
||||
if [ -n "$CUSTOM_IMAGE" ]; then
|
||||
echo "$CUSTOM_IMAGE"
|
||||
elif [ "$BUILD_IMAGE" = true ]; then
|
||||
elif [ "$BUILD_IMAGE" = true ] && [ "$PUSH_IMAGE" = false ]; then
|
||||
echo "asteria-qt-ci-${target}:latest"
|
||||
else
|
||||
echo "${IMAGE_PREFIX}/build-${target}:latest"
|
||||
@@ -67,6 +70,10 @@ prepare_image() {
|
||||
-t "$image_tag" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
if [ "$PUSH_IMAGE" = true ]; then
|
||||
echo "==> Pushing CI image: $image_tag"
|
||||
"$RUNTIME" push "$image_tag"
|
||||
fi
|
||||
elif ! "$RUNTIME" image inspect "$image_tag" &>/dev/null; then
|
||||
echo "==> Pulling prebuilt CI image: $image_tag"
|
||||
"$RUNTIME" pull --platform linux/amd64 "$image_tag"
|
||||
|
||||
Reference in new issue
Block a user