Fixed GitHub workflow manifest push not supporting single quotes #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow is based on work from asterisk-hass-addons | |
# Copyright (c) 2021 TECH Fox, under MIT license | |
name: Build and publish image to GitHub Package Registry | |
on: | |
push: | |
branches: [ master, 'release/*' ] | |
tags: [ 'v*' ] | |
workflow_dispatch: ~ | |
repository_dispatch: | |
types: [ dependency_commit ] | |
env: | |
REGISTRY_REPOSITORY_NAME: hangar-maven-bridge | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get lowercase GitHub username | |
id: repository_owner | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: ${{ github.repository_owner }} | |
- name: Set outputs | |
id: set-outputs | |
run: | | |
echo 'image=ghcr.io/${{ steps.repository_owner.outputs.lowercase }}/${{ env.REGISTRY_REPOSITORY_NAME }}' >> "${GITHUB_OUTPUT}" | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ steps.set-outputs.outputs.image }} | |
flavor: latest=auto | |
tags: | | |
type=schedule,pattern=nightly | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=ref,event=branch,enable=${{ github.ref != 'refs/heads/master' }} | |
type=ref,event=pr | |
type=edge,enable=true | |
type=sha,enable=true,prefix={{branch}}-,format=short | |
outputs: | |
image: ${{ steps.set-outputs.outputs.image }} | |
meta-version: ${{ steps.meta.outputs.version }} | |
meta-labels: ${{ steps.meta.outputs.labels }} | |
meta-json: ${{ steps.meta.outputs.json }} | |
meta-tags: ${{ steps.meta.outputs.tags }} | |
build: | |
needs: | |
- prepare | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- linux/amd64 | |
- linux/arm64/v8 | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to image repository | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set cache flags | |
id: cache-flags | |
run: | | |
# Set the cache-to output | |
echo 'cache-to=type=gha,scope=${{ github.ref_name }}-${{ matrix.platform }}' >> "${GITHUB_OUTPUT}" | |
# Set the cache-from output | |
if [[ '${{ github.ref }}' == 'refs/tags/v'* ]]; then | |
# Use cache from the branch when building a tag | |
branch="$(git branch -r --contains '${{ github.ref }}')" | |
branch="${branch##*/}" | |
echo "cache-from=type=gha,scope=${branch}-${{ matrix.platform }}" >> "${GITHUB_OUTPUT}" | |
else | |
# Use cache from the same branch when not building a tag | |
echo 'cache-from=type=gha,scope=${{ github.ref_name }}-${{ matrix.platform }}' >> "${GITHUB_OUTPUT}" | |
fi | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile | |
platforms: ${{ matrix.platform }} | |
labels: ${{ needs.prepare.outputs.meta-labels }} | |
outputs: | | |
type=image,name=${{ needs.prepare.outputs.image }},push-by-digest=true,name-canonical=true,push=true | |
cache-from: | | |
${{ steps.cache-flags.outputs.cache-from }} | |
cache-to: | | |
${{ steps.cache-flags.outputs.cache-to }} | |
secrets: | | |
"AUTH_TOKEN=${{ secrets.AUTH_TOKEN }}" | |
- name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest='${{ steps.build.outputs.digest }}' | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
uses: actions/upload-artifact@v3 | |
with: | |
name: digests | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
push: | |
needs: | |
- prepare | |
- build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@v3 | |
with: | |
name: digests | |
path: /tmp/digests | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(echo "${{ needs.prepare.outputs.meta-tags }}" | sed 's/^/-t /' | tr '\n' ' ') \ | |
$(printf '${{ needs.prepare.outputs.image }}@sha256:%s ' *) | |
- name: Inspect image | |
run: | | |
docker buildx imagetools inspect '${{ needs.prepare.outputs.image }}:${{ needs.prepare.outputs.meta-version }}' |