Release Docker #213
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
name: Release Docker | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'The tag that is being released.' | |
required: false | |
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 }} | |
tag: ${{ fromJSON(steps.workflow-run.outputs.artifacts)['release'].files['release.json'].tag || github.event.inputs.tag }} | |
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: . | |
build-args: | | |
VERSION=${{ needs.release.outputs.tag }} | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.tags.outputs.tags }} |