action
- updated auto builder
This commit is contained in:
@@ -21,15 +21,29 @@
|
||||
# tag's commit is actually part of main's history (see check-branch job).
|
||||
|
||||
name: build-and-push
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
- "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
|
||||
IMAGE_NAME: mqtt-cert-manager
|
||||
|
||||
jobs:
|
||||
check-branch:
|
||||
@@ -42,12 +56,17 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Make sure we have main's history too
|
||||
- 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
|
||||
@@ -55,17 +74,56 @@ jobs:
|
||||
echo "Tag $GITHUB_REF_NAME points to a commit that is not on main — skipping build."
|
||||
fi
|
||||
|
||||
build:
|
||||
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
|
||||
# TEMPORARY: only building amd64 while developing against a
|
||||
# single Dell thin client — restore these before publishing.
|
||||
# Uncomment when you are ready for multi-arch:
|
||||
# - arch: aarch64
|
||||
# platform: linux/arm64
|
||||
# - arch: armv7
|
||||
@@ -78,23 +136,7 @@ jobs:
|
||||
- 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)
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
@@ -108,13 +150,12 @@ jobs:
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./mqtt-cert-manager
|
||||
context: ./${{ needs.prepare.outputs.addon }}
|
||||
platforms: ${{ matrix.platform }}
|
||||
push: true
|
||||
build-args: |
|
||||
BUILD_FROM=${{ steps.base.outputs.build_from }}
|
||||
# No BUILD_FROM needed anymore — modern Dockerfiles have a direct 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
|
||||
${{ needs.prepare.outputs.image }}-${{ matrix.arch }}:${{ needs.prepare.outputs.version }}
|
||||
${{ needs.prepare.outputs.image }}-${{ matrix.arch }}:latest
|
||||
Reference in New Issue
Block a user