Skip to content

Publish daemons

Publish daemons #45

name: Publish daemons
# portions from gemini pro and fast
on:
schedule:
- cron: '30 3,12 * * *'
push:
branches: [ master ]
# Publish semver tags as releases.
tags: [ '*-v*.*.*' ]
paths: [ 'daemons/**' ]
pull_request:
branches: [ master ]
paths: [ 'daemons/**' ]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Testing the container build mechanism'
env:
REGISTRY: ghcr.io
jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has_jobs: ${{ steps.set-matrix.outputs.has_jobs }}
steps:
- id: set-matrix
uses: actions/github-script@v8
env:
REF_NAME: ${{ github.ref_name }}
with:
script: |
const allContainers = [
'apphandler',
'authhandler',
'avsdispatcher',
'housekeeping',
'ltihandler',
'notepadhandler',
'noteshandler',
'staticserver'
]
const allContainersWithContext = allContainers.map((container) => ({
container,
context: './daemons/' + container
}))
const isTag = context.ref.startsWith('refs/tags/');
const refName = process.env.REF_NAME;
let activeContainers = allContainersWithContext;
if (isTag) {
activeContainers = allContainersWithContext.filter(c => refName.includes(c.container));
}
core.setOutput('has_jobs', activeContainers.length > 0);
core.setOutput('matrix', JSON.stringify({ include: activeContainers }));
build:
needs: setup-matrix
runs-on: ubuntu-latest
if: ${{ needs.setup-matrix.outputs.has_jobs == 'true' }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Check for changes in ${{ matrix.context }}
id: changed
if: github.event_name == 'push' || github.event_name == 'pull_request'
uses: dorny/paths-filter@v4
with:
filters: |
src:
- '${{ matrix.context }}/**'
- name: Determine Build Status
id: check
run: |
# Default: Don't build
BUILD="false"
CLEAN_VER=""
if [[ "${{ github.event_name }}" == "schedule" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "Trigger: Schedule/Manual -> Building."
BUILD="true"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "Trigger: Tag -> Building."
BUILD="true"
# Extract clean version (apphandler-v1.2.3 -> 1.2.3)
CLEAN_VER=$(echo "${{ github.ref_name }}" | sed 's/.*-v//')
elif [[ "${{ steps.changed.outputs.src }}" == "true" ]]; then
echo "Trigger: Push with changes -> Building."
BUILD="true"
else
echo "Trigger: Push but no changes -> Skipping."
fi
# Export to GITHUB_ENV so all next steps can see it simply
echo "SHOULD_BUILD=$BUILD" >> $GITHUB_ENV
echo "VERSION_TAG=$CLEAN_VER" >> $GITHUB_ENV
- name: Log into registry ${{ env.REGISTRY }}
if: env.SHOULD_BUILD == 'true' && github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
if: env.SHOULD_BUILD == 'true'
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.container }}
labels: |
org.opencontainers.image.title=${{ matrix.container }}
org.opencontainers.image.description=Component ${{ matrix.container }} from the fancy-lectures monorepo
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern=v{{version}},value=${{ env.VERSION_TAG }}
type=semver,pattern=v{{major}}.{{minor}},value=${{ env.VERSION_TAG }}
type=semver,pattern=v{{major}},value=${{ env.VERSION_TAG }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
if: env.SHOULD_BUILD == 'true'
uses: docker/build-push-action@v7
with:
context: .
file: ./${{ matrix.context }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max