Fix Gitea build version source and stop tracking built binaries
This commit is contained in:
@@ -5,7 +5,13 @@ dist/
|
||||
*.deb
|
||||
build/
|
||||
tmp/
|
||||
amd64/opt/gitea/bin/gitea
|
||||
arm64/opt/gitea/bin/gitea
|
||||
|
||||
# Ignore common system files
|
||||
.DS_Store
|
||||
*.swp
|
||||
|
||||
# Local Codex state
|
||||
.codex
|
||||
.codex/
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-04-27
|
||||
|
||||
- Switched automatic Gitea version detection to prefer the official GitHub releases API.
|
||||
- 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 runtime logging so `build.sh` prints which version source was used.
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,51 @@
|
||||
#!/bin/bash
|
||||
set -e # Exit on error
|
||||
|
||||
# Set Variables
|
||||
VERSION=$(curl -s https://dl.gitea.com/gitea/version.json | jq -r '.latest.version')
|
||||
# Resolve the target version from an explicit override first, then from the
|
||||
# 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"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -n "${GITEA_VERSION:-}" ]]; then
|
||||
VERSION_SOURCE="GITEA_VERSION environment variable"
|
||||
echo "${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
|
||||
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
|
||||
VERSION_SOURCE="dl.gitea.com version.json fallback"
|
||||
echo "$version"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "❌ Unable to determine the latest Gitea version. Set GITEA_VERSION or pass a version as the first argument." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
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}"
|
||||
|
||||
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."
|
||||
@@ -11,7 +53,6 @@ if [[ -f "../gitea-deb/gitea_${VERSION}_amd64.deb" ]] && [[ -f "../gitea-deb/git
|
||||
fi
|
||||
|
||||
ARCHS=("amd64" "arm64")
|
||||
GITEA_BASE_URL="https://dl.gitea.com/gitea/${VERSION}"
|
||||
FILES=("xz" "xz.asc" "xz.sha256" "xz.sha256.asc")
|
||||
|
||||
# Download Gitea Binaries and Signatures
|
||||
@@ -23,7 +64,7 @@ for ARCH in "${ARCHS[@]}"; do
|
||||
fi
|
||||
for FILE in "${FILES[@]}"; do
|
||||
FILE_NAME="gitea-${VERSION}-linux-${ARCH}.${FILE}"
|
||||
FILE_URL="${GITEA_BASE_URL}/${FILE_NAME}"
|
||||
FILE_URL="${DOWNLOAD_BASE_URL}/${FILE_NAME}"
|
||||
TARGET_FILE="dist/${ARCH}/${FILE_NAME}"
|
||||
if [[ -f "$TARGET_FILE" ]]; then
|
||||
echo "✅ File already exists: $TARGET_FILE (Skipping)"
|
||||
@@ -48,27 +89,39 @@ for ARCH in "${ARCHS[@]}"; do
|
||||
(cd "dist/${ARCH}" && sha256sum -c gitea-${VERSION}-linux-${ARCH}.xz.sha256)
|
||||
done
|
||||
|
||||
# expand the Gitea binary to the target
|
||||
# Stage package contents in a disposable build directory so the repository's
|
||||
# tracked packaging files do not get modified during a build.
|
||||
for ARCH in "${ARCHS[@]}"; do
|
||||
if [[ ! -d "${ARCH}/opt/gitea/bin" ]]; then
|
||||
echo "Creating directory ${ARCH}/opt/gitea/bin"
|
||||
mkdir -p "${ARCH}/opt/gitea/bin"
|
||||
PACKAGE_DIR="${BUILD_ROOT}/${ARCH}"
|
||||
|
||||
if [[ ! -d "${PACKAGE_DIR}" ]]; then
|
||||
echo "Creating staging directory ${PACKAGE_DIR}"
|
||||
mkdir -p "${PACKAGE_DIR}"
|
||||
fi
|
||||
xz -dc "dist/${ARCH}/gitea-${VERSION}-linux-${ARCH}.xz" > "${ARCH}/opt/gitea/bin/gitea" || { echo "❌ Extraction failed for ${ARCH}"; exit 1; }
|
||||
|
||||
cp -a "${ARCH}/." "${PACKAGE_DIR}/"
|
||||
|
||||
if [[ ! -d "${PACKAGE_DIR}/opt/gitea/bin" ]]; then
|
||||
echo "Creating directory ${PACKAGE_DIR}/opt/gitea/bin"
|
||||
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; }
|
||||
|
||||
# Verify the extracted file isn't empty
|
||||
if [[ ! -s "${ARCH}/opt/gitea/bin/gitea" ]]; then
|
||||
if [[ ! -s "${PACKAGE_DIR}/opt/gitea/bin/gitea" ]]; then
|
||||
echo "❌ Extracted file is empty for ${ARCH}. Something went wrong!"
|
||||
exit 1
|
||||
fi
|
||||
chmod +x "${ARCH}/opt/gitea/bin/gitea"
|
||||
chmod +x "${PACKAGE_DIR}/opt/gitea/bin/gitea"
|
||||
done
|
||||
|
||||
# Build Debian Packages
|
||||
for ARCH in "${ARCHS[@]}"; do
|
||||
echo "Building package for ${ARCH} …"
|
||||
sed -i "s/^Version: .*/Version: ${VERSION}/" "${ARCH}/DEBIAN/control"
|
||||
dpkg-deb --build "${ARCH}" "gitea_${VERSION}_${ARCH}.deb"
|
||||
PACKAGE_DIR="${BUILD_ROOT}/${ARCH}"
|
||||
sed -i "s/^Version: .*/Version: ${VERSION}/" "${PACKAGE_DIR}/DEBIAN/control"
|
||||
dpkg-deb --build "${PACKAGE_DIR}" "gitea_${VERSION}_${ARCH}.deb"
|
||||
done
|
||||
|
||||
echo "All packages built successfully:"
|
||||
@@ -96,4 +149,3 @@ mv gitea_${VERSION}_*.deb ../gitea-deb/
|
||||
echo "No changes to commit."
|
||||
fi
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user