Files
virarepo/.gitea/workflows/build-and-push.yml
T
eta 32821d2604
build-and-push / check-branch (push) Successful in 8s
build-and-push / build (amd64, linux/amd64) (push) Successful in 7m51s
set env vars in build and push
2026-08-15 15:02:33 +03:30

120 lines
4.4 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:
- "v*"
env:
REGISTRY_HOST: gitea.viratak.com
REGISTRY_OWNER: bitopa
IMAGE_NAME: mqtt-cert-manager
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 too
run: git fetch origin main:refs/remotes/origin/main
- name: Is this tag's commit part of main?
id: check
run: |
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
build:
needs: check-branch
if: needs.check-branch.outputs.on_main == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
include:
- arch: amd64
platform: linux/amd64
# TEMPORARY: only building amd64 while developing against a
# single Dell thin client — restore these before publishing.
# - 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: Read add-on version
id: version
# Plain shell instead of python3+PyYAML: the runner's Python has
# no yaml module installed, and this value is a simple one-liner
# anyway (version: "0.1.0"), so there's no need for a real YAML
# parser or an extra apt/pip install step just for this.
run: |
VERSION=$(grep '^version:' mqtt-cert-manager/config.yaml | cut -d'"' -f2)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Read base image for this arch from build.yaml
id: base
run: |
BUILD_FROM=$(grep -E "^[[:space:]]*${{ matrix.arch }}:" mqtt-cert-manager/build.yaml | cut -d'"' -f2)
echo "build_from=$BUILD_FROM" >> "$GITHUB_OUTPUT"
- name: Set up QEMU (needed to build non-amd64 targets on an amd64 runner)
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@v5
with:
context: ./mqtt-cert-manager
platforms: ${{ matrix.platform }}
push: true
build-args: |
BUILD_FROM=${{ steps.base.outputs.build_from }}
tags: |
${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:${{ steps.version.outputs.version }}
${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/${{ env.IMAGE_NAME }}-${{ matrix.arch }}:latest