Skip to content

Release Docker

Release Docker #69

name: Release Docker
on:
workflow_dispatch:
inputs:
tags:
description: 'Comma separated list of tags to apply to the image.'
required: false
artifacts-url:
description: |
The URL of the artifacts to download.
If provided, we'll try to retrieve the tags from the release.json file of the release artifact.
required: false
ref:
description: GitHub Ref
required: false
default: main
workflow_run:
workflows: [Release]
types:
- completed
jobs:
release:
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
outputs:
draft: ${{ fromJSON(steps.workflow-run.outputs.artifacts)['release'].files['release.json'].draft || false }}
tags: ${{ fromJSON(steps.workflow-run.outputs.artifacts)['release'].files['release.json'].tags || github.event.inputs.tags }}
steps:
# This step will download the release artifact either from the workflow
# run that triggered this workflow or from the artifacts-url input. It
# will also parse the release.json file.
- id: workflow-run
if: github.event.workflow_run.artifacts_url != '' || github.event.inputs.artifacts-url != ''
uses: pl-strflt/rich-workflow-run@v1
with:
artifacts-url: ${{ github.event.workflow_run.artifacts_url || github.event.inputs.artifacts-url }}
artifact-names: release
docker:
needs: [release]
if: needs.release.outputs.tags != '' && needs.release.outputs.draft == 'false'
name: Docker
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
# This step will add ghcr.io/<repository> prefix to each <tag>.
- id: tags
env:
REPOSITORY: ${{ github.repository }}
TAGS: ${{ needs.release.outputs.tags }}
run: jq -Rr 'split(",") | map(gsub("^\\s+|\\s+$";"") | "ghcr.io/\(env.REPOSITORY):\(.)") | join(",") | "tags=\(.)"' <<< "$TAGS" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_sha || github.event.inputs.ref }}
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.tags.outputs.tags }}