284 lines
12 KiB
YAML
284 lines
12 KiB
YAML
name: release
|
|
|
|
# Baut das Abbild und legt es unter
|
|
# git.aimighty.olares.de/aimighty/lunch-app:<version> ab (Gitea-Registry,
|
|
# Organisation aimighty, öffentlich: Die Box zieht ohne Anmeldung). Dazu das
|
|
# gepackte Chart als Anhang am Release — die Datei, die in den Markt geht.
|
|
# Vorbild: aimighty/rocket .github/workflows/release.yml.
|
|
#
|
|
# Auslöser:
|
|
# - **Merge nach main mit neuer Version** in olares/Chart.yaml: bauen, danach
|
|
# Tag `v<version>` samt Release über die Gitea-API — erst nach
|
|
# erfolgreichem Bau. Gibt es den Tag schon, passiert nichts.
|
|
# - **PR**, der Dockerfile, Abhängigkeiten oder diesen Workflow ändert: Chart
|
|
# prüfen und packen, Abbild bauen, nichts hochladen.
|
|
# - **Run workflow** mit Version: bauen und hochladen, ohne Tag.
|
|
#
|
|
# Kein Auslöser auf Tags: Tags setzt nur dieser Workflow selbst.
|
|
# Gitea-Besonderheiten: ein Runner; Helm aus aimighty/ci-tools; der
|
|
# Docker-Daemon sitzt hinter dem Bridge-Gateway; gebaut wird nur amd64.
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- Dockerfile
|
|
- package-lock.json
|
|
- .github/workflows/release.yml
|
|
push:
|
|
branches: [main]
|
|
# Auch der Workflow selbst: Wer ihn ändert, soll sehen, dass er läuft
|
|
# — und eine noch nicht getaggte Version wird dabei veröffentlicht.
|
|
paths: [olares/Chart.yaml, .github/workflows/release.yml]
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: "Image tag without leading v (e.g. 26.10.26); empty = olares/Chart.yaml"
|
|
required: false
|
|
|
|
# Die Probe eines PR: nur sein neuester Push zählt. Ein Release auf main
|
|
# bekommt eine eigene Gruppe (run_id) und wird nie abgebrochen (Kai,
|
|
# 14.10.2026).
|
|
concurrency:
|
|
group: release-${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
version:
|
|
name: which version
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.v.outputs.version }}
|
|
proceed: ${{ steps.v.outputs.proceed }}
|
|
push: ${{ steps.v.outputs.push }}
|
|
create_tag: ${{ steps.v.outputs.create_tag }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # die Tags gehören zur Entscheidung
|
|
|
|
- id: v
|
|
run: |
|
|
CHART_VERSION="$(grep -E '^version:' olares/Chart.yaml | head -1 | awk '{print $2}' | tr -d '"')"
|
|
PROCEED=true; PUSH=true; CREATE=false
|
|
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
V="$CHART_VERSION"; PUSH=false
|
|
echo "### PR: Chart $V prüfen und packen, Abbilder bauen ohne Hochladen" >> "$GITHUB_STEP_SUMMARY"
|
|
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
V="${{ inputs.version }}"; [ -n "$V" ] || V="$CHART_VERSION"
|
|
else
|
|
V="$CHART_VERSION"
|
|
if git rev-parse -q --verify "refs/tags/v$V" >/dev/null; then
|
|
PROCEED=false
|
|
echo "### v$V ist schon getaggt — kein Release" >> "$GITHUB_STEP_SUMMARY"
|
|
else
|
|
CREATE=true
|
|
echo "### Neue Version $V — bauen, dann v$V taggen" >> "$GITHUB_STEP_SUMMARY"
|
|
fi
|
|
fi
|
|
echo "version=$V" >> "$GITHUB_OUTPUT"
|
|
echo "proceed=$PROCEED" >> "$GITHUB_OUTPUT"
|
|
echo "push=$PUSH" >> "$GITHUB_OUTPUT"
|
|
echo "create_tag=$CREATE" >> "$GITHUB_OUTPUT"
|
|
echo "version=$V proceed=$PROCEED push=$PUSH create_tag=$CREATE"
|
|
|
|
preflight:
|
|
name: olares chart · sanity
|
|
needs: version
|
|
if: needs.version.outputs.proceed == 'true'
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
build_images: ${{ steps.decide.outputs.build_images }}
|
|
env:
|
|
VERSION: ${{ needs.version.outputs.version }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
# get.helm.sh ist vom Gitea-Runner nicht erreichbar: Helm liegt als
|
|
# Release-Anhang in aimighty/ci-tools, get.helm.sh bleibt Rückfall.
|
|
- name: install helm 3.16.2
|
|
run: |
|
|
for url in \
|
|
"https://git.aimighty.olares.de/aimighty/ci-tools/releases/download/helm-3.16.2/helm-v3.16.2-linux-amd64.tar.gz" \
|
|
"https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz"; do
|
|
echo "hole $url"
|
|
if curl -fsSL --retry 3 --retry-all-errors --max-time 180 -o /tmp/helm.tgz "$url" \
|
|
&& tar -tzf /tmp/helm.tgz >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
done
|
|
tar -C /tmp -xzf /tmp/helm.tgz
|
|
install -m 0755 /tmp/linux-amd64/helm /usr/local/bin/helm
|
|
helm version --short
|
|
|
|
- name: codified Olares lessons (scripts/check-chart.sh)
|
|
run: bash scripts/check-chart.sh
|
|
|
|
- name: chart version must match the version to release
|
|
if: github.event_name == 'push'
|
|
run: |
|
|
CHART_VERSION="$(grep -E '^version:' olares/Chart.yaml | head -1 | awk '{print $2}' | tr -d '"')"
|
|
if [ "$VERSION" != "$CHART_VERSION" ]; then
|
|
echo "::error::version $VERSION does not match olares/Chart.yaml version $CHART_VERSION"
|
|
exit 1
|
|
fi
|
|
echo "version $VERSION matches the chart"
|
|
|
|
# Ein leerer Tag in values.yaml heißt „folgt Chart.AppVersion" — der
|
|
# Normalfall, das Chart referenziert dann genau diesen Tag. Ein
|
|
# gesetzter Tag ist ein Pin auf eine Vorversion: Die Abbilder gibt es
|
|
# schon, nichts bauen.
|
|
- name: are images needed for this version?
|
|
id: decide
|
|
run: |
|
|
BUILD=true
|
|
PINS="$(grep -E "^[[:space:]]+tag:" olares/values.yaml | grep -vE 'tag:[[:space:]]*(""|'"''"')[[:space:]]*$' || true)"
|
|
if [ -n "$PINS" ] \
|
|
&& ! grep -qE "^[[:space:]]+tag:[[:space:]]*[\"']?${VERSION}[\"']?[[:space:]]*$" olares/values.yaml; then
|
|
BUILD=false
|
|
fi
|
|
echo "build_images=$BUILD" >> "$GITHUB_OUTPUT"
|
|
if [ "$BUILD" = "true" ]; then
|
|
echo "### Abbilder werden gebaut ($VERSION)" >> "$GITHUB_STEP_SUMMARY"
|
|
else
|
|
echo "### Abbild-Bau übersprungen — values.yaml pinnt eine Vorversion" >> "$GITHUB_STEP_SUMMARY"
|
|
fi
|
|
|
|
- name: package chart
|
|
run: |
|
|
mkdir -p dist
|
|
helm package olares -d dist
|
|
ls -la dist
|
|
|
|
- uses: actions/upload-artifact@v4
|
|
with:
|
|
name: chart
|
|
path: dist/*.tgz
|
|
if-no-files-found: error
|
|
|
|
build:
|
|
name: ${{ matrix.service }}
|
|
needs: [version, preflight]
|
|
if: needs.preflight.outputs.build_images == 'true' || github.event_name == 'workflow_dispatch'
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
# Ein Runner, ein Daemon: nacheinander.
|
|
max-parallel: 1
|
|
matrix:
|
|
include:
|
|
- service: app
|
|
context: .
|
|
dockerfile: ./Dockerfile
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
# Der Docker-Daemon des Runners ist ein dind-InitContainer im
|
|
# Runner-Pod (privileged, :2375). Aus dem Job-Container erreicht man
|
|
# weder den Socket noch 127.0.0.1, nur das Bridge-Gateway des
|
|
# Job-Netzes (aimighty/insilo UEBERGABE.md). `ip` fehlt im
|
|
# act-Container: das Gateway steht in /proc/net/route.
|
|
- name: find the runner's Docker daemon (dind at the bridge gateway)
|
|
run: |
|
|
read -r _ dest gw _ < <(awk '$2=="00000000" {print; exit}' /proc/net/route)
|
|
GW="$(printf "%d.%d.%d.%d" 0x${gw:6:2} 0x${gw:4:2} 0x${gw:2:2} 0x${gw:0:2})"
|
|
ok=0
|
|
for KANDIDAT in "$GW" "172.17.0.1"; do
|
|
[ -n "$KANDIDAT" ] || continue
|
|
if DOCKER_HOST="tcp://$KANDIDAT:2375" docker version >/dev/null 2>&1; then
|
|
echo "DOCKER_HOST=tcp://$KANDIDAT:2375" >> "$GITHUB_ENV"
|
|
echo "Daemon erreichbar unter tcp://$KANDIDAT:2375"
|
|
ok=1
|
|
break
|
|
fi
|
|
done
|
|
[ "$ok" = "1" ] || { echo "::error::kein Docker-Daemon am Bridge-Gateway gefunden"; exit 1; }
|
|
|
|
- uses: docker/setup-buildx-action@v3
|
|
|
|
# REGISTRY_TOKEN (Organisations-Geheimnis in aimighty): ein Gitea-Token
|
|
# mit package Lesen und Schreiben eines Kontos, das in der Organisation
|
|
# Pakete anlegen darf.
|
|
- name: Log in to the Gitea registry
|
|
if: needs.version.outputs.push == 'true'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: git.aimighty.olares.de
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
# Nur amd64 — das Manifest verspricht auch nur das. Ein Next.js-Bau
|
|
# unter QEMU für arm64 dauert eine halbe Stunde, und keine Box, die
|
|
# diese App bekommt, ist eine ARM-Maschine.
|
|
- name: Build (and push)
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ${{ matrix.context }}
|
|
file: ${{ matrix.dockerfile }}
|
|
platforms: linux/amd64
|
|
push: ${{ needs.version.outputs.push == 'true' }}
|
|
tags: |
|
|
git.aimighty.olares.de/aimighty/lunch-${{ matrix.service }}:${{ needs.version.outputs.version }}
|
|
git.aimighty.olares.de/aimighty/lunch-${{ matrix.service }}:latest
|
|
|
|
# Erst wenn das Abbild draußen ist: Tag und Release, mit dem Chart
|
|
# als Anhang — dieselbe Datei, die in den Markt geht.
|
|
release:
|
|
name: tag and release
|
|
needs: [version, preflight, build]
|
|
# Gitea meldet einen übersprungenen Job nicht verlässlich als „skipped":
|
|
# laufen, sobald ein Tag fällig ist, und das Ergebnis selbst prüfen.
|
|
if: always() && needs.version.outputs.create_tag == 'true'
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
VERSION: ${{ needs.version.outputs.version }}
|
|
GITEA_API: https://git.aimighty.olares.de/api/v1
|
|
steps:
|
|
- name: chart and images ready?
|
|
env:
|
|
PREFLIGHT: ${{ needs.preflight.result }}
|
|
BUILD: ${{ needs.build.result }}
|
|
BUILD_IMAGES: ${{ needs.preflight.outputs.build_images }}
|
|
run: |
|
|
echo "preflight '$PREFLIGHT', build '$BUILD', build_images '$BUILD_IMAGES'"
|
|
[ "$PREFLIGHT" = "success" ] || { echo "::error::Chart nicht geprüft ($PREFLIGHT) — kein Tag, kein Release"; exit 1; }
|
|
if [ "$BUILD_IMAGES" = "true" ]; then
|
|
[ "$BUILD" = "success" ] || { echo "::error::Abbilder nicht gebaut ($BUILD) — kein Tag, kein Release"; exit 1; }
|
|
else
|
|
# Release nur mit Chart: ein absichtlich übersprungener Bau ist in
|
|
# Ordnung, ein gescheiterter oder abgebrochener nicht.
|
|
case "$BUILD" in failure|cancelled) echo "::error::Bau $BUILD"; exit 1 ;; esac
|
|
fi
|
|
|
|
- uses: actions/download-artifact@v4
|
|
with:
|
|
name: chart
|
|
path: dist
|
|
|
|
- name: create tag and release (Gitea API)
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.MARKT_TOKEN }}
|
|
run: |
|
|
[ -n "$GITEA_TOKEN" ] || { echo "::error::Geheimnis MARKT_TOKEN fehlt"; exit 1; }
|
|
NOTES="Lunch $VERSION — Abbild git.aimighty.olares.de/aimighty/lunch-app:$VERSION, Chart im Anhang. Automatisch nach dem Merge angelegt."
|
|
BODY=$(python3 -c 'import json,sys; print(json.dumps({"tag_name":"v"+sys.argv[1],"target_commitish":sys.argv[2],"name":"v"+sys.argv[1],"body":sys.argv[3]}))' "$VERSION" "${{ github.sha }}" "$NOTES")
|
|
RESP=$(curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
|
|
"$GITEA_API/repos/$GITHUB_REPOSITORY/releases" -d "$BODY")
|
|
RID=$(printf '%s' "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id') or '')")
|
|
[ -n "$RID" ] || { echo "::error::Release-Anlage fehlgeschlagen"; printf '%s\n' "$RESP" | head -c 300; exit 1; }
|
|
curl -fsS -X POST -H "Authorization: token $GITEA_TOKEN" -F "attachment=@dist/lunch-$VERSION.tgz" \
|
|
"$GITEA_API/repos/$GITHUB_REPOSITORY/releases/$RID/assets?name=lunch-$VERSION.tgz" > /dev/null
|
|
echo "Tag und Release v$VERSION angelegt"
|
|
echo "### Tag und Release v$VERSION angelegt" >> "${GITHUB_STEP_SUMMARY:-/dev/null}"
|
|
|
|
# Nur ein echtes Release startet markt.yml, mit seiner Version.
|
|
- name: start markt for this version
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.MARKT_TOKEN }}
|
|
run: |
|
|
curl -fsS -X POST -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
|
|
"$GITEA_API/repos/$GITHUB_REPOSITORY/actions/workflows/markt.yml/dispatches" \
|
|
-d "{\"ref\":\"main\",\"inputs\":{\"probe\":\"false\",\"version\":\"$VERSION\"}}"
|
|
echo "markt für $VERSION angestoßen" | tee -a "${GITHUB_STEP_SUMMARY:-/dev/null}"
|