Prune dist cache before early exit and fix source logging

This commit is contained in:
2026-04-27 00:45:01 +02:00
parent b0e7f4a816
commit 1a64595ed2
2 changed files with 23 additions and 19 deletions
+4
View File
@@ -6,3 +6,7 @@
- Kept `https://dl.gitea.com/gitea/version.json` as a fallback because it may lag behind published releases. - 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 <version>` or `GITEA_VERSION=<version> ./build.sh`. - Added explicit support for overriding the target version with `./build.sh <version>` or `GITEA_VERSION=<version> ./build.sh`.
- Added runtime logging so `build.sh` prints which version source was used. - Added runtime logging so `build.sh` prints which version source was used.
- Changed `build.sh` to stage package contents in `build/<version>/...` 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/<arch>/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.
+19 -19
View File
@@ -5,33 +5,29 @@ set -e # Exit on error
# latest published GitHub release. The dl.gitea.com version JSON can lag # latest published GitHub release. The dl.gitea.com version JSON can lag
# behind actual releases, so it is only used as a fallback. # behind actual releases, so it is only used as a fallback.
resolve_version() { resolve_version() {
local version=""
if [[ -n "${1:-}" ]]; then if [[ -n "${1:-}" ]]; then
VERSION_SOURCE="command line argument" VERSION_SOURCE="command line argument"
echo "$1" VERSION="$1"
return 0 return 0
fi fi
if [[ -n "${GITEA_VERSION:-}" ]]; then if [[ -n "${GITEA_VERSION:-}" ]]; then
VERSION_SOURCE="GITEA_VERSION environment variable" VERSION_SOURCE="GITEA_VERSION environment variable"
echo "${GITEA_VERSION}" VERSION="${GITEA_VERSION}"
return 0 return 0
fi 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 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}" VERSION="${VERSION#v}"
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
VERSION_SOURCE="GitHub releases API" VERSION_SOURCE="GitHub releases API"
echo "$version"
return 0 return 0
fi fi
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=$(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" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
VERSION_SOURCE="dl.gitea.com version.json fallback" VERSION_SOURCE="dl.gitea.com version.json fallback"
echo "$version"
return 0 return 0
fi fi
fi fi
@@ -40,18 +36,13 @@ resolve_version() {
exit 1 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}}" DOWNLOAD_BASE_URL="${GITEA_DOWNLOAD_BASE_URL:-https://github.com/go-gitea/gitea/releases/download/v${VERSION}}"
BUILD_ROOT="build/${VERSION}" BUILD_ROOT="build/${VERSION}"
DIST_ROOT="dist" DIST_ROOT="dist"
echo "Current version: ${VERSION}" echo "Current version: ${VERSION}"
echo "Version source: ${VERSION_SOURCE}" 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") ARCHS=("amd64" "arm64")
FILES=("xz" "xz.asc" "xz.sha256" "xz.sha256.asc") 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 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 # Download Gitea Binaries and Signatures
for ARCH in "${ARCHS[@]}"; do for ARCH in "${ARCHS[@]}"; do
echo "Downloading Gitea ${VERSION} for ${ARCH}" echo "Downloading Gitea ${VERSION} for ${ARCH}"
echo "Pruning old cache entries in ${DIST_ROOT}/${ARCH}"
prune_dist_cache "${ARCH}"
for FILE in "${FILES[@]}"; do for FILE in "${FILES[@]}"; do
FILE_NAME="gitea-${VERSION}-linux-${ARCH}.${FILE}" FILE_NAME="gitea-${VERSION}-linux-${ARCH}.${FILE}"
FILE_URL="${DOWNLOAD_BASE_URL}/${FILE_NAME}" FILE_URL="${DOWNLOAD_BASE_URL}/${FILE_NAME}"