Publish Container Image #2
This file contains hidden or 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: Publish Container Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: Release tag to publish (for example wootty-v0.2.0 or v0.2.0) | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| publish: | |
| name: Build and Publish GHCR Image | |
| if: github.ref_name == 'main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Prepare metadata | |
| id: prepare | |
| env: | |
| INPUT_TAG: ${{ github.event.inputs.tag || '' }} | |
| run: | | |
| set -euo pipefail | |
| tag="${INPUT_TAG}" | |
| tag="${tag#refs/tags/}" | |
| if [[ -z "$tag" ]]; then | |
| echo "Missing release tag. Provide workflow_dispatch input 'tag'." | |
| exit 1 | |
| fi | |
| release_tag="$tag" | |
| semver_tag="$tag" | |
| if [[ "$release_tag" != wootty-* && "$release_tag" == v* ]]; then | |
| release_tag="wootty-$release_tag" | |
| fi | |
| if [[ "$release_tag" == wootty-v* ]]; then | |
| semver_tag="${release_tag#wootty-}" | |
| fi | |
| publish_latest=true | |
| push=true | |
| platforms="linux/amd64,linux/arm64" | |
| if [[ "${ACT:-}" == "true" ]]; then | |
| push=false | |
| platforms="linux/arm64" | |
| fi | |
| nov_tag="$semver_tag" | |
| has_v_prefix=false | |
| if [[ "$semver_tag" == v* ]]; then | |
| nov_tag="${semver_tag#v}" | |
| has_v_prefix=true | |
| fi | |
| echo "release_tag=$release_tag" >>"$GITHUB_OUTPUT" | |
| echo "checkout_ref=refs/tags/$release_tag" >>"$GITHUB_OUTPUT" | |
| echo "version_tag=$semver_tag" >>"$GITHUB_OUTPUT" | |
| echo "noversion_tag=$nov_tag" >>"$GITHUB_OUTPUT" | |
| echo "has_v_prefix=$has_v_prefix" >>"$GITHUB_OUTPUT" | |
| echo "publish_latest=$publish_latest" >>"$GITHUB_OUTPUT" | |
| echo "push=$push" >>"$GITHUB_OUTPUT" | |
| echo "platforms=$platforms" >>"$GITHUB_OUTPUT" | |
| - name: Checkout release tag | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ steps.prepare.outputs.checkout_ref }} | |
| - name: Set up QEMU | |
| if: steps.prepare.outputs.push == 'true' | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| if: steps.prepare.outputs.push == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=raw,value=${{ steps.prepare.outputs.version_tag }} | |
| type=raw,value=${{ steps.prepare.outputs.noversion_tag }},enable=${{ steps.prepare.outputs.has_v_prefix == 'true' }} | |
| type=raw,value=latest,enable=${{ steps.prepare.outputs.publish_latest == 'true' }} | |
| - name: Build and publish image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: ${{ steps.prepare.outputs.platforms }} | |
| push: ${{ steps.prepare.outputs.push == 'true' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |