From b0e7f4a81612a017f02c30dc599bb02be4893710 Mon Sep 17 00:00:00 2001 From: tracer Date: Mon, 27 Apr 2026 00:41:00 +0200 Subject: [PATCH] Prune stale dist cache entries before builds --- build.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index 5cd2b9a..db8ac62 100755 --- a/build.sh +++ b/build.sh @@ -43,6 +43,7 @@ resolve_version() { VERSION=$(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}" @@ -55,17 +56,25 @@ fi ARCHS=("amd64" "arm64") FILES=("xz" "xz.asc" "xz.sha256" "xz.sha256.asc") +prune_dist_cache() { + local arch="$1" + local dist_dir="${DIST_ROOT}/${arch}" + local keep_prefix="gitea-${VERSION}-linux-${arch}." + + mkdir -p "${dist_dir}" + + find "${dist_dir}" -maxdepth 1 -type f -name 'gitea-*' ! -name "${keep_prefix}*" -print -delete +} + # Download Gitea Binaries and Signatures for ARCH in "${ARCHS[@]}"; do echo "Downloading Gitea ${VERSION} for ${ARCH} …" - if [[ ! -d "dist/${ARCH}" ]]; then - echo "Creating directory dist/${ARCH}" - mkdir "dist/${ARCH}" - fi + 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}" - TARGET_FILE="dist/${ARCH}/${FILE_NAME}" + TARGET_FILE="${DIST_ROOT}/${ARCH}/${FILE_NAME}" if [[ -f "$TARGET_FILE" ]]; then echo "✅ File already exists: $TARGET_FILE (Skipping)" else @@ -78,15 +87,15 @@ done # Verify GPG Signatures for ARCH in "${ARCHS[@]}"; do echo "Verifying GPG signature for ${ARCH} …" - gpg --verify "dist/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.asc" "dist/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz" - gpg --verify "dist/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.sha256.asc" "dist/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.sha256" + gpg --verify "${DIST_ROOT}/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.asc" "${DIST_ROOT}/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz" + gpg --verify "${DIST_ROOT}/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.sha256.asc" "${DIST_ROOT}/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.sha256" done # Verify Checksums for ARCH in "${ARCHS[@]}"; do echo "Verifying SHA256 checksum for ${ARCH} …" - (cd "dist/${ARCH}" && sha256sum -c gitea-${VERSION}-linux-${ARCH}.xz.sha256) + (cd "${DIST_ROOT}/${ARCH}" && sha256sum -c gitea-${VERSION}-linux-${ARCH}.xz.sha256) done # Stage package contents in a disposable build directory so the repository's @@ -106,7 +115,7 @@ for ARCH in "${ARCHS[@]}"; do mkdir -p "${PACKAGE_DIR}/opt/gitea/bin" fi - xz -dc "dist/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz" > "${PACKAGE_DIR}/opt/gitea/bin/gitea" || { echo "❌ Extraction failed for ${ARCH}"; exit 1; } + xz -dc "${DIST_ROOT}/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz" > "${PACKAGE_DIR}/opt/gitea/bin/gitea" || { echo "❌ Extraction failed for ${ARCH}"; exit 1; } # Verify the extracted file isn't empty if [[ ! -s "${PACKAGE_DIR}/opt/gitea/bin/gitea" ]]; then