161 lines
5.3 KiB
YAML
161 lines
5.3 KiB
YAML
# Builds mqtt-cert-manager for every arch in config.yaml and pushes each
|
|
# as its own tag to Gitea's container registry, matching the {arch}
|
|
# template in config.yaml's `image:` field.
|
|
#
|
|
# Setup required before this will work:
|
|
# 1. In Gitea: Settings (your user, top-right avatar) > Applications >
|
|
# Generate New Token, scope "write:package" (and "read:package").
|
|
# The auto-injected Gitea Actions token does NOT reliably work for
|
|
# pushing to the container registry (known upstream issue), so this
|
|
# manual PAT is necessary, not optional.
|
|
# 2. In this repo: Settings > Actions > Secrets > add a secret named
|
|
# REGISTRY_TOKEN with that PAT's value.
|
|
# 3. Edit REGISTRY_HOST and REGISTRY_OWNER below to match your Gitea
|
|
# instance and username/org.
|
|
# 4. Bump `version:` in mqtt-cert-manager/config.yaml before every
|
|
# release — Supervisor pulls the image tag matching that version
|
|
# exactly, so an unbumped version means it silently keeps using the
|
|
# old image.
|
|
#
|
|
# Triggers only on pushed tags matching "v*", and only builds if that
|
|
# tag's commit is actually part of main's history (see check-branch job).
|
|
|
|
name: build-and-push
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "mqtt-cert-manager/v*"
|
|
- "visquitto/v*"
|
|
workflow_dispatch:
|
|
inputs:
|
|
addon:
|
|
description: "Which add-on to build"
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- mqtt-cert-manager
|
|
- visquitto
|
|
version:
|
|
description: "Version (e.g. 0.4.0) — leave empty to read from config.yaml"
|
|
required: false
|
|
default: ""
|
|
|
|
env:
|
|
REGISTRY_HOST: gitea.viratak.com
|
|
REGISTRY_OWNER: bitopa
|
|
|
|
jobs:
|
|
check-branch:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
on_main: ${{ steps.check.outputs.on_main }}
|
|
steps:
|
|
- name: Checkout (full history)
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Make sure we have main's history
|
|
run: git fetch origin main:refs/remotes/origin/main
|
|
|
|
- name: Is this tag's commit part of main?
|
|
id: check
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
echo "on_main=true" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
if git merge-base --is-ancestor HEAD origin/main; then
|
|
echo "on_main=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "on_main=false" >> "$GITHUB_OUTPUT"
|
|
echo "Tag $GITHUB_REF_NAME points to a commit that is not on main — skipping build."
|
|
fi
|
|
|
|
prepare:
|
|
needs: check-branch
|
|
if: needs.check-branch.outputs.on_main == 'true'
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
addon: ${{ steps.meta.outputs.addon }}
|
|
version: ${{ steps.meta.outputs.version }}
|
|
image: ${{ steps.meta.outputs.image }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Determine add-on and version
|
|
id: meta
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
ADDON="${{ inputs.addon }}"
|
|
VERSION="${{ inputs.version }}"
|
|
else
|
|
# tag format: mqtt-cert-manager/v0.3.0 or visquitto/v0.4.0
|
|
ADDON=$(echo "${{ github.ref_name }}" | cut -d/ -f1)
|
|
VERSION=$(echo "${{ github.ref_name }}" | cut -d/ -f2 | sed 's/^v//')
|
|
fi
|
|
|
|
# Fallback: read version from config.yaml if not provided
|
|
if [ -z "$VERSION" ]; then
|
|
VERSION=$(grep '^version:' "$ADDON/config.yaml" | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
|
|
fi
|
|
|
|
if [ -z "$ADDON" ] || [ -z "$VERSION" ]; then
|
|
echo "Could not determine add-on or version"
|
|
exit 1
|
|
fi
|
|
|
|
echo "addon=$ADDON" >> "$GITHUB_OUTPUT"
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "image=${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/$ADDON" >> "$GITHUB_OUTPUT"
|
|
|
|
echo "Building $ADDON version $VERSION"
|
|
|
|
build:
|
|
needs: prepare
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- arch: amd64
|
|
platform: linux/amd64
|
|
# Uncomment when you are ready for multi-arch:
|
|
# - arch: aarch64
|
|
# platform: linux/arm64
|
|
# - arch: armv7
|
|
# platform: linux/arm/v7
|
|
# - arch: armhf
|
|
# platform: linux/arm/v6
|
|
# - arch: i386
|
|
# platform: linux/386
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
# - name: Set up QEMU
|
|
# uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea container registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY_HOST }}
|
|
username: ${{ env.REGISTRY_OWNER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./${{ needs.prepare.outputs.addon }}
|
|
platforms: ${{ matrix.platform }}
|
|
push: true
|
|
# No BUILD_FROM needed anymore — modern Dockerfiles have a direct FROM
|
|
tags: |
|
|
${{ needs.prepare.outputs.image }}-${{ matrix.arch }}:${{ needs.prepare.outputs.version }}
|
|
${{ needs.prepare.outputs.image }}-${{ matrix.arch }}:latest |