Skip to content

Various CI improvements #747

Various CI improvements

Various CI improvements #747

Workflow file for this run

---
name: meta
env:
GHCR_URL: "ghcr.io/${{ github.repository }}"
on:
pull_request:
push:
branches:
- 'main'
- 'release/**'
tags:
- '*'
jobs:
trigger_workflow:
name: trigger workflow based on changed files
runs-on: ubuntu-22.04
outputs:
base_container_image: ${{ steps.base_container.outputs.image }}
container_any_changed: ${{ steps.paths.outputs.container }}
image_any_changed: ${{ steps.paths.outputs.image }}
metadata_json: ${{ steps.metadata.outputs.json }}
metadata_labels: ${{ steps.metadata.outputs.labels }}
metadata_tags: ${{ steps.metadata.outputs.tags }}
steps:
- name: lowercase GHCR_URL
id: lower
run: |
echo "ghcr_url=${GHCR_URL@L}" >> $GITHUB_OUTPUT
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Compare pull requests with their base and pushes with their previous head.
fetch-depth: 0
- name: detect changed build inputs
uses: dorny/paths-filter@7b450fff21473bca461d4b92ce414b9d0420d706 # v4.0.2
if: ${{ github.ref_type != 'tag' }}
id: paths
with:
base: ${{ github.ref_name }}
filters: |
container:
- '.github/workflows/build-container.yml'
- 'Dockerfile'
- 'container.gitconfig'
image:
- '**'
- '!**/*.md'
- '!ha/**'
- '!misc/**'
- name: extract metadata
id: metadata
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ steps.lower.outputs.ghcr_url }}
tags: |
type=ref,event=tag
type=ref,event=pr
type=ref,event=branch
- name: select base branch container
id: base_container
if: ${{ steps.paths.outputs.container == 'false' && steps.paths.outputs.image == 'true' }}
env:
BASE_REF: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
REGISTRY_IMAGE: ${{ steps.lower.outputs.ghcr_url }}
run: |
tag=$(printf '%s' "$BASE_REF" | sed 's/[^A-Za-z0-9_.-]/-/g')
image="$REGISTRY_IMAGE:$tag"
if ! docker manifest inspect "$image" >/dev/null 2>&1; then
image="$REGISTRY_IMAGE:main"
fi
echo "image=$image" >> "$GITHUB_OUTPUT"
build_container:
if: ${{ needs.trigger_workflow.outputs.container_any_changed == 'true' || github.ref_type == 'tag' }}
uses: ./.github/workflows/build-container.yml
needs: trigger_workflow
with:
container-image: ${{ fromJSON(needs.trigger_workflow.outputs.metadata_json).tags[0] }}
labels: ${{ needs.trigger_workflow.outputs.metadata_labels }}
tags: ${{ needs.trigger_workflow.outputs.metadata_tags }}
build_willow:
if: ${{ needs.trigger_workflow.outputs.container_any_changed == 'false' && needs.trigger_workflow.outputs.image_any_changed == 'true' }}
uses: ./.github/workflows/build-willow.yml
needs: trigger_workflow
with:
container-image: ${{ needs.trigger_workflow.outputs.base_container_image }}