From 1a64595ed2ae28d778d0b2aa17d9b0d0b6314f3a Mon Sep 17 00:00:00 2001 From: tracer Date: Mon, 27 Apr 2026 00:45:01 +0200 Subject: [PATCH] Prune dist cache before early exit and fix source logging --- CHANGELOG.md | 4 ++++ build.sh | 38 +++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5244c64..b990eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,7 @@ - Kept `https://dl.gitea.com/gitea/version.json` as a fallback because it may lag behind published releases. - Added explicit support for overriding the target version with `./build.sh ` or `GITEA_VERSION= ./build.sh`. - Added runtime logging so `build.sh` prints which version source was used. +- Changed `build.sh` to stage package contents in `build//...` so repository files are not modified during a build. +- Removed tracked Gitea binaries and PhpStorm project files from the repository and added ignore rules for local-only files. +- Added pruning of stale `dist//gitea-*` cache files before each run, including runs that abort because the current release is already built. +- Fixed version-source logging after cache pruning so `Version source:` is populated correctly again. diff --git a/build.sh b/build.sh index db8ac62..972037b 100755 --- a/build.sh +++ b/build.sh @@ -5,33 +5,29 @@ set -e # Exit on error # latest published GitHub release. The dl.gitea.com version JSON can lag # behind actual releases, so it is only used as a fallback. resolve_version() { - local version="" - if [[ -n "${1:-}" ]]; then VERSION_SOURCE="command line argument" - echo "$1" + VERSION="$1" return 0 fi if [[ -n "${GITEA_VERSION:-}" ]]; then VERSION_SOURCE="GITEA_VERSION environment variable" - echo "${GITEA_VERSION}" + VERSION="${GITEA_VERSION}" return 0 fi - if version=$(curl -fsSL https://api.github.com/repos/go-gitea/gitea/releases/latest 2>/dev/null | jq -r '.tag_name // empty' 2>/dev/null); then - version="${version#v}" - if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + if VERSION=$(curl -fsSL https://api.github.com/repos/go-gitea/gitea/releases/latest 2>/dev/null | jq -r '.tag_name // empty' 2>/dev/null); then + VERSION="${VERSION#v}" + if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then VERSION_SOURCE="GitHub releases API" - echo "$version" return 0 fi fi - if version=$(curl -fsSL https://dl.gitea.com/gitea/version.json 2>/dev/null | jq -r '.latest.version // empty' 2>/dev/null); then - if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + if VERSION=$(curl -fsSL https://dl.gitea.com/gitea/version.json 2>/dev/null | jq -r '.latest.version // empty' 2>/dev/null); then + if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then VERSION_SOURCE="dl.gitea.com version.json fallback" - echo "$version" return 0 fi fi @@ -40,18 +36,13 @@ resolve_version() { exit 1 } -VERSION=$(resolve_version "${1:-}") +resolve_version "${1:-}" DOWNLOAD_BASE_URL="${GITEA_DOWNLOAD_BASE_URL:-https://github.com/go-gitea/gitea/releases/download/v${VERSION}}" BUILD_ROOT="build/${VERSION}" DIST_ROOT="dist" echo "Current version: ${VERSION}" echo "Version source: ${VERSION_SOURCE}" -# Check if this version is already built -if [[ -f "../gitea-deb/gitea_${VERSION}_amd64.deb" ]] && [[ -f "../gitea-deb/gitea_${VERSION}_arm64.deb" ]]; then - echo "✅ Version ${VERSION} already built and present in release repo. Aborting." - exit 0 -fi ARCHS=("amd64" "arm64") FILES=("xz" "xz.asc" "xz.sha256" "xz.sha256.asc") @@ -66,11 +57,20 @@ prune_dist_cache() { find "${dist_dir}" -maxdepth 1 -type f -name 'gitea-*' ! -name "${keep_prefix}*" -print -delete } +for ARCH in "${ARCHS[@]}"; do + echo "Pruning old cache entries in ${DIST_ROOT}/${ARCH}" + prune_dist_cache "${ARCH}" +done + +# Check if this version is already built +if [[ -f "../gitea-deb/gitea_${VERSION}_amd64.deb" ]] && [[ -f "../gitea-deb/gitea_${VERSION}_arm64.deb" ]]; then + echo "✅ Version ${VERSION} already built and present in release repo. Aborting." + exit 0 +fi + # Download Gitea Binaries and Signatures for ARCH in "${ARCHS[@]}"; do echo "Downloading Gitea ${VERSION} for ${ARCH} …" - echo "Pruning old cache entries in ${DIST_ROOT}/${ARCH}" - prune_dist_cache "${ARCH}" for FILE in "${FILES[@]}"; do FILE_NAME="gitea-${VERSION}-linux-${ARCH}.${FILE}" FILE_URL="${DOWNLOAD_BASE_URL}/${FILE_NAME}"