vintage-story-build-latest / Docker prune (vm-docker-build2) (push) Successful in 4s
vintage-story-build-latest / Build and Push latest (push) Successful in 1m5s
vintage-story-build-latest / generate-changelogs (push) Successful in 13s
vintage-story-build-testing / Docker prune (vm-docker-build2) (push) Successful in 3s
vintage-story-build-testing / Build and Push testing (push) Successful in 1m3s
vintage-story-build-latest / generate-build-info (push) Successful in 15s
vintage-story-build-testing / generate-changelogs (push) Successful in 10s
vintage-story-build-testing / generate-build-info (push) Successful in 16s
309 lines
9.7 KiB
YAML
309 lines
9.7 KiB
YAML
name: vintage-story-build-latest
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- '.gitea/workflows/vintage-story-build-server.yml'
|
|
- 'latest/Dockerfile'
|
|
- 'latest/*.sh'
|
|
- '!.cache/*'
|
|
- '!latest/CHANGES.md'
|
|
- '!latest/build-info.json'
|
|
schedule:
|
|
- cron: '5 22 * * 0'
|
|
|
|
env:
|
|
IMAGE_REGISTRY: gitea.fithwum.tech
|
|
IMAGE_ORG: fithwum
|
|
IMAGE_REPO_DEBIAN: debian-base
|
|
IMAGE_REPO_VINTAGE_STORY: vintage-story
|
|
IMAGE_TAG_DEBIAN: bookworm
|
|
DIGEST_FILE: .cache/debian-base.digest
|
|
VERSIONS: latest
|
|
|
|
jobs:
|
|
docker-prune:
|
|
name: Docker prune (${{ matrix.runner }})
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
runner:
|
|
- vm-docker-build2
|
|
steps:
|
|
- name: Prune unused Docker images
|
|
run: |
|
|
echo "[INFO] Pruning Docker images on ${{ matrix.runner }}..."
|
|
docker image prune -a -f || true
|
|
|
|
build-vintage-story-images:
|
|
runs-on: vm-docker-build2
|
|
needs: docker-prune
|
|
strategy:
|
|
matrix:
|
|
version: [latest]
|
|
name: Build and Push ${{ matrix.version }}
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Log in to Gitea Registry
|
|
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login gitea.fithwum.tech -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
|
|
|
|
- name: Clone vintage-story repo (with retries)
|
|
run: |
|
|
GIT_CREDENTIAL="${{ secrets.GIT_TOKEN || secrets.GIT_PASSWORD }}"
|
|
for i in {1..5}; do
|
|
git clone "https://${{ secrets.GIT_USERNAME }}:${GIT_CREDENTIAL}@gitea.fithwum.tech/fithwum/vintage-story.git" upload-repo && break
|
|
echo "[WARN] Clone attempt $i failed. Retrying in 10s..."
|
|
sleep 10
|
|
done
|
|
if [ ! -d upload-repo ]; then
|
|
echo "[ERROR] Failed to clone vintage-story repo after retries."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Clear all build caches
|
|
run: |
|
|
docker builder prune -af || true
|
|
docker buildx prune -af || true
|
|
|
|
- name: Build and push image
|
|
run: |
|
|
IMAGE="$IMAGE_REGISTRY/$IMAGE_ORG/$IMAGE_REPO_VINTAGE_STORY:${{ matrix.version }}"
|
|
docker buildx build --platform linux/amd64 --pull --no-cache --push -t "$IMAGE" "./${{ matrix.version }}"
|
|
|
|
generate-changelogs:
|
|
needs: build-vintage-story-images
|
|
runs-on: vm-docker-build2
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Create temporary changelog workspace
|
|
run: mkdir -p changelogs
|
|
|
|
- name: Clone vintage-story repo
|
|
run: |
|
|
GIT_CREDENTIAL="${{ secrets.GIT_TOKEN || secrets.GIT_PASSWORD }}"
|
|
git clone --depth=3 "https://${{ secrets.GIT_USERNAME }}:${GIT_CREDENTIAL}@gitea.fithwum.tech/fithwum/vintage-story.git" upload-repo
|
|
|
|
- name: Generate changelogs
|
|
run: |
|
|
for version in $VERSIONS; do
|
|
echo "[INFO] Generating changelog for $version"
|
|
changelog="changelogs/$version/CHANGES.md"
|
|
mkdir -p "$(dirname "$changelog")"
|
|
touch "$changelog"
|
|
|
|
cd upload-repo
|
|
infofile="$version/build-info.json"
|
|
last_commit=""
|
|
if [ -f "$infofile" ]; then
|
|
last_commit=$(jq -r '.commit' "$infofile")
|
|
fi
|
|
|
|
echo -e "## $(date -u +'%Y-%m-%dT%H:%M:%SZ')\n" > "../$changelog"
|
|
if [ -n "$last_commit" ]; then
|
|
COMMITS=$(git log "${last_commit}..HEAD" --pretty=format:"- %s (%an)" || true)
|
|
fi
|
|
if [ -z "$COMMITS" ]; then
|
|
echo "[INFO] No new commits since last build. Showing latest 5 instead."
|
|
COMMITS=$(git log -n 5 --pretty=format:"- %s (%an)" || true)
|
|
fi
|
|
echo "$COMMITS" >> "../$changelog"
|
|
cd ..
|
|
done
|
|
|
|
- name: Copy changelogs into repo
|
|
run: |
|
|
for version in $VERSIONS; do
|
|
mkdir -p upload-repo/$version
|
|
cp changelogs/$version/CHANGES.md upload-repo/$version/
|
|
done
|
|
|
|
- name: Commit and push changelogs (temp branch)
|
|
run: |
|
|
cd upload-repo
|
|
|
|
git config user.name "${{ secrets.GIT_USERNAME }}"
|
|
git config user.email "${{ secrets.GIT_EMAIL }}"
|
|
|
|
TEMP_BRANCH="tmp-changelog-$(date +%s)"
|
|
|
|
# Create temporary branch
|
|
git checkout -b "$TEMP_BRANCH"
|
|
|
|
# Stage changes
|
|
git add */CHANGES.md
|
|
|
|
# Nothing changed?
|
|
if git diff --cached --quiet; then
|
|
echo "[INFO] No changelog changes."
|
|
exit 0
|
|
fi
|
|
|
|
git commit -m "Update changelogs on $(date -u +'%Y-%m-%dT%H:%M:%SZ') [skip ci]"
|
|
|
|
# Push temporary branch
|
|
git push origin HEAD:$TEMP_BRANCH
|
|
|
|
# Rebase temp branch onto latest main
|
|
git fetch origin main
|
|
|
|
git checkout "$TEMP_BRANCH"
|
|
|
|
if ! git rebase origin/main; then
|
|
echo "[WARN] Rebase failed, using merge instead."
|
|
git rebase --abort || true
|
|
git merge origin/main --no-edit
|
|
fi
|
|
|
|
git push origin HEAD:$TEMP_BRANCH --force
|
|
|
|
# Fast-forward main
|
|
git checkout main
|
|
git reset --hard origin/main
|
|
|
|
git merge --no-ff "$TEMP_BRANCH" \
|
|
-m "Merge changelog updates"
|
|
|
|
git push origin main
|
|
|
|
git push origin --delete "$TEMP_BRANCH" || true
|
|
|
|
generate-build-info:
|
|
needs: generate-changelogs
|
|
runs-on: vm-docker-build2
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Prepare temporary build-info workspace
|
|
run: mkdir -p buildinfo
|
|
|
|
- name: Clone vintage-story repo
|
|
run: |
|
|
GIT_CREDENTIAL="${{ secrets.GIT_TOKEN || secrets.GIT_PASSWORD }}"
|
|
git clone --depth=1 "https://${{ secrets.GIT_USERNAME }}:${GIT_CREDENTIAL}@gitea.fithwum.tech/fithwum/vintage-story.git" upload-repo
|
|
|
|
- name: Generate build-info files
|
|
run: |
|
|
human_size() {
|
|
local b=$1 d='' s=0 S=(B KB MB GB TB)
|
|
while ((b >= 1024 && s < ${#S[@]}-1)); do
|
|
d=$((b % 1024)); b=$((b / 1024)); s=$((s + 1))
|
|
done
|
|
printf "%s%s\n" "$b" "${S[$s]}"
|
|
}
|
|
|
|
for version in $VERSIONS; do
|
|
echo "[INFO] Generating build-info.json for $version"
|
|
image="${IMAGE_REGISTRY}/${IMAGE_ORG}/${IMAGE_REPO_VINTAGE_STORY}:$version"
|
|
infofile="buildinfo/$version/build-info.json"
|
|
mkdir -p "$(dirname "$infofile")"
|
|
|
|
if ! docker pull "$image"; then
|
|
echo "[WARN] Failed to pull $image — setting fields to unknown/0"
|
|
digest="unknown"
|
|
size_bytes=0
|
|
else
|
|
digest=$(docker inspect --format='{{if .RepoDigests}}{{index .RepoDigests 0}}{{else}}unknown{{end}}' "$image" 2>/dev/null || echo "unknown")
|
|
size_bytes=$(docker image inspect "$image" --format='{{.Size}}' 2>/dev/null || echo "0")
|
|
size_bytes=${size_bytes//[^0-9]/}
|
|
if [[ -z "$size_bytes" ]]; then size_bytes=0; fi
|
|
fi
|
|
|
|
size_human=$(human_size "$size_bytes")
|
|
|
|
cd upload-repo
|
|
commit=$(git rev-parse HEAD)
|
|
cd ..
|
|
|
|
jq -n \
|
|
--arg version "$version" \
|
|
--arg commit "$commit" \
|
|
--arg build_time "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
|
|
--arg image_tag "$image" \
|
|
--arg digest "$digest" \
|
|
--arg image_size "$size_human" \
|
|
--argjson image_size_bytes "$size_bytes" \
|
|
'{
|
|
version: $version,
|
|
commit: $commit,
|
|
build_time: $build_time,
|
|
image_tag: $image_tag,
|
|
digest: $digest,
|
|
image_size: $image_size,
|
|
image_size_bytes: $image_size_bytes
|
|
}' > "$infofile"
|
|
done
|
|
|
|
- name: Copy build-info.json into repo
|
|
run: |
|
|
for version in $VERSIONS; do
|
|
mkdir -p upload-repo/$version
|
|
cp "buildinfo/$version/build-info.json" "upload-repo/$version/"
|
|
done
|
|
|
|
- name: Commit and push build-info (temp branch)
|
|
run: |
|
|
cd upload-repo
|
|
|
|
git config user.name "${{ secrets.GIT_USERNAME }}"
|
|
git config user.email "${{ secrets.GIT_EMAIL }}"
|
|
|
|
TEMP_BRANCH="tmp-buildinfo-$(date +%s)"
|
|
|
|
# Create temporary branch
|
|
git checkout -b "$TEMP_BRANCH"
|
|
|
|
# Stage changes
|
|
git add */build-info.json
|
|
|
|
# Nothing changed?
|
|
if git diff --cached --quiet; then
|
|
echo "[INFO] No build-info changes."
|
|
exit 0
|
|
fi
|
|
|
|
git commit -m "Update build-info on $(date -u +'%Y-%m-%dT%H:%M:%SZ') [skip ci]"
|
|
|
|
# Push temporary branch
|
|
git push origin HEAD:$TEMP_BRANCH
|
|
|
|
# Rebase temp branch onto latest main
|
|
git fetch origin main
|
|
|
|
git checkout "$TEMP_BRANCH"
|
|
|
|
if ! git rebase origin/main; then
|
|
echo "[WARN] Rebase failed, using merge instead."
|
|
git rebase --abort || true
|
|
git merge origin/main --no-edit
|
|
fi
|
|
|
|
git push origin HEAD:$TEMP_BRANCH --force
|
|
|
|
# Merge into main
|
|
git checkout main
|
|
git reset --hard origin/main
|
|
|
|
git merge --no-ff "$TEMP_BRANCH" \
|
|
-m "Merge build-info updates"
|
|
|
|
git push origin main
|
|
|
|
git push origin --delete "$TEMP_BRANCH" || true
|
|
|
|
for version in $VERSIONS; do
|
|
TAG="build-$version"
|
|
|
|
git tag -d "$TAG" 2>/dev/null || true
|
|
git push origin ":refs/tags/$TAG" 2>/dev/null || true
|
|
|
|
git tag "$TAG"
|
|
git push origin "$TAG" --force
|
|
done |