diff --git a/.gitea/workflows/container.yml b/.gitea/workflows/container.yml index 49b591b..90e0ab8 100644 --- a/.gitea/workflows/container.yml +++ b/.gitea/workflows/container.yml @@ -9,6 +9,7 @@ on: env: IMAGE: registry.brunner.ninja/feedc0de/php-apache + GITOPS_REPOSITORY: feedc0de/homelab-gitops jobs: publish: @@ -17,8 +18,10 @@ jobs: timeout-minutes: 30 steps: - - name: Check out source + - name: Check out source and tags uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Helm uses: azure/setup-helm@v4 @@ -125,11 +128,8 @@ jobs: test -n "${php_version}" version_tag="${apache_version}-${php_version}" printf 'VERSION_TAG=%s\n' "${version_tag}" >> "${GITHUB_ENV}" - run_attempt="${GITHUB_RUN_ATTEMPT:-1}" - test -n "${GITHUB_RUN_NUMBER}" - chart_version="0.${GITHUB_RUN_NUMBER}.${run_attempt}" + chart_version="$(./scripts/chart-version.sh)" printf 'CHART_VERSION=%s\n' "${chart_version}" >> "${GITHUB_ENV}" - printf 'BUILD_TAG=chart-%s\n' "${chart_version}" >> "${GITHUB_ENV}" - name: Push commit tag if: gitea.event_name == 'push' @@ -143,15 +143,13 @@ jobs: COMMIT_SHA: ${{ gitea.sha }} run: | set -euo pipefail - docker tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:${BUILD_TAG}" docker tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:${VERSION_TAG}" docker tag "${IMAGE}:${COMMIT_SHA}" "${IMAGE}:latest" - docker push "${IMAGE}:${BUILD_TAG}" docker push "${IMAGE}:${VERSION_TAG}" docker push "${IMAGE}:latest" - name: Publish Helm chart - if: gitea.ref == 'refs/heads/main' || gitea.event_name == 'schedule' + if: gitea.ref == 'refs/heads/main' env: PACKAGE_USERNAME: ${{ secrets.PACKAGE_USERNAME }} PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }} @@ -163,7 +161,7 @@ jobs: helm package helm/php-homepage \ --destination .chart-packages \ --version "${CHART_VERSION}" \ - --app-version "${BUILD_TAG}" + --app-version "${COMMIT_SHA}" chart_file=".chart-packages/php-homepage-${CHART_VERSION}.tgz" test -f "${chart_file}" curl --fail --silent --show-error \ @@ -171,3 +169,29 @@ jobs: --request POST \ --upload-file "${chart_file}" \ https://code.brunner.ninja/api/packages/feedc0de/helm/api/charts + + - name: Check out GitOps repository + if: gitea.ref == 'refs/heads/main' + uses: actions/checkout@v4 + with: + repository: ${{ env.GITOPS_REPOSITORY }} + ref: main + token: ${{ secrets.GITOPS_TOKEN }} + path: homelab-gitops + + - name: Promote the exact chart to every homepage application + if: gitea.ref == 'refs/heads/main' + working-directory: homelab-gitops + run: | + set -euo pipefail + for application in \ + brgkepler-com brunner-ninja gschissenes-equipment \ + immich-crack pfostendynamics-com watschn-studio; do + ./scripts/update-chart-version.sh "${application}" "${CHART_VERSION}" + git add "bootstrap/${application}.yaml" + done + git config user.name "feedc0de" + git config user.email "feedc0de@users.noreply.code.brunner.ninja" + if git diff --cached --quiet; then exit 0; fi + git commit -m "Deploy php-homepage chart ${CHART_VERSION}" + git push origin HEAD:main diff --git a/scripts/chart-version.sh b/scripts/chart-version.sh new file mode 100755 index 0000000..a20feb6 --- /dev/null +++ b/scripts/chart-version.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +description=$(git describe --tags --long --match 'v[0-9]*' --dirty) +case "$description" in + *-dirty) echo "refusing to package a dirty tree" >&2; exit 1 ;; +esac +version=${description#v} +case "$version" in + *-0-g*) version=${version%%-0-g*} ;; +esac +printf '%s\n' "$version"