Files
pyMC_Repeater/.github/workflows/docker-publish.yml
T
yellowcooln c14d8b2226 fix: refresh bundled console in docker builds
Invalidate the Docker cache layer that downloads the bundled Console release when the latest release changes, and allow manual builds to pin a Console tag.

Co-Authored-By: Warp <agent@warp.dev>
2026-07-07 21:35:13 -04:00

140 lines
4.7 KiB
YAML

name: Publish Docker Image
on:
push:
branches:
- main
- dev
workflow_dispatch:
inputs:
image_repository:
description: "Docker image repository to publish to"
required: false
default: ""
pymc_console_version:
description: "PyMC Console release to bundle (latest or a tag such as v0.9.333)"
required: false
default: "latest"
jobs:
docker:
if: |
github.event_name == 'workflow_dispatch' ||
github.repository == 'openhop-dev/openhop_repeater' ||
github.repository_owner == 'yellowcooln'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Compute package version
id: package_version
run: |
python -m pip install --disable-pip-version-check setuptools_scm
version="$(python -m setuptools_scm)"
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine image repository
id: image_repo
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.image_repository }}" ]; then
image_repository="${{ inputs.image_repository }}"
elif [ "${{ github.repository_owner }}" = "yellowcooln" ]; then
image_repository="yellowcooln/pymc-repeater"
else
image_repository="openhop/openhop-repeater"
fi
echo "Using image repository: ${image_repository}"
echo "image_repository=${image_repository}" >> "$GITHUB_OUTPUT"
- name: Resolve bundled Console release
id: console_release
shell: bash
env:
REQUESTED_CONSOLE_VERSION: ${{ inputs.pymc_console_version || 'latest' }}
run: |
set -euo pipefail
if [ "${REQUESTED_CONSOLE_VERSION}" = "latest" ]; then
release_json="$(curl -fsSL https://api.github.com/repos/Treehouse-00/pymc_console-dist/releases/latest)"
tag="$(jq -r '.tag_name' <<<"${release_json}")"
published_at="$(jq -r '.published_at' <<<"${release_json}")"
cache_bust="${tag}@${published_at}"
else
tag="${REQUESTED_CONSOLE_VERSION}"
cache_bust="${REQUESTED_CONSOLE_VERSION}"
fi
echo "Bundling PyMC Console ${tag}"
echo "version=${REQUESTED_CONSOLE_VERSION}" >> "$GITHUB_OUTPUT"
echo "cache_bust=${cache_bust}" >> "$GITHUB_OUTPUT"
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image_repo.outputs.image_repository }}
tags: |
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
type=sha,format=short
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./dockerfile
platforms: linux/amd64,linux/arm64
push: true
build-args: |
PACKAGE_VERSION=${{ steps.package_version.outputs.version }}
PYMC_CONSOLE_VERSION=${{ steps.console_release.outputs.version }}
PYMC_CONSOLE_CACHE_BUST=${{ steps.console_release.outputs.cache_bust }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Notify Home Assistant add-on repository
if: github.repository == 'openhop-dev/openhop_repeater'
env:
DISPATCH_TOKEN: ${{ secrets.HA_ADDON_REPO_DISPATCH_TOKEN }}
CHANNEL: ${{ github.ref_name }}
REVISION: ${{ github.sha }}
run: |
if [ -z "${DISPATCH_TOKEN}" ]; then
echo "HA_ADDON_REPO_DISPATCH_TOKEN is not set" >&2
exit 1
fi
curl -fsSL \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${DISPATCH_TOKEN}" \
https://api.github.com/repos/openhop-dev/openHop-HA-Add-on/dispatches \
-d "{\"event_type\":\"sync-upstream-channel\",\"client_payload\":{\"channel\":\"${CHANNEL}\",\"revision\":\"${REVISION}\"}}"