Prune stale dist cache entries before builds

This commit is contained in:
2026-04-27 00:41:00 +02:00
parent 79bdb947f6
commit b0e7f4a816
+18 -9
View File
@@ -43,6 +43,7 @@ resolve_version() {
VERSION=$(resolve_version "${1:-}") VERSION=$(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"
echo "Current version: ${VERSION}" echo "Current version: ${VERSION}"
echo "Version source: ${VERSION_SOURCE}" echo "Version source: ${VERSION_SOURCE}"
@@ -55,17 +56,25 @@ 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")
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 # 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}"
if [[ ! -d "dist/${ARCH}" ]]; then echo "Pruning old cache entries in ${DIST_ROOT}/${ARCH}"
echo "Creating directory dist/${ARCH}" prune_dist_cache "${ARCH}"
mkdir "dist/${ARCH}"
fi
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}"
TARGET_FILE="dist/${ARCH}/${FILE_NAME}" TARGET_FILE="${DIST_ROOT}/${ARCH}/${FILE_NAME}"
if [[ -f "$TARGET_FILE" ]]; then if [[ -f "$TARGET_FILE" ]]; then
echo "✅ File already exists: $TARGET_FILE (Skipping)" echo "✅ File already exists: $TARGET_FILE (Skipping)"
else else
@@ -78,15 +87,15 @@ done
# Verify GPG Signatures # Verify GPG Signatures
for ARCH in "${ARCHS[@]}"; do for ARCH in "${ARCHS[@]}"; do
echo "Verifying GPG signature for ${ARCH}" 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_ROOT}/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.asc" "${DIST_ROOT}/${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.sha256.asc" "${DIST_ROOT}/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz.sha256"
done done
# Verify Checksums # Verify Checksums
for ARCH in "${ARCHS[@]}"; do for ARCH in "${ARCHS[@]}"; do
echo "Verifying SHA256 checksum for ${ARCH}" 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 done
# Stage package contents in a disposable build directory so the repository's # 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" mkdir -p "${PACKAGE_DIR}/opt/gitea/bin"
fi 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 # Verify the extracted file isn't empty
if [[ ! -s "${PACKAGE_DIR}/opt/gitea/bin/gitea" ]]; then if [[ ! -s "${PACKAGE_DIR}/opt/gitea/bin/gitea" ]]; then