markusressel/keel-telegram-bot

View on GitHub
.github/workflows/dockerimage.yml

Summary

Maintainability
Test Coverage
name: Docker Image

on:
  push:
    branches:
      - master
    tags:
      - "*.*.*"
  pull_request:
    branches: [ "master" ]

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  dockerhub:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      # this writes the tag name into GIT_TAG_NAME
      - name: Get tag name
        uses: little-core-labs/get-git-tag@v3.0.2

      # https://github.com/docker/setup-qemu-action
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      # https://github.com/docker/setup-buildx-action
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v3
        #with:
        #  install: true

      - name: Inspect builder
        run: |
          echo "Name:      ${{ steps.buildx.outputs.name }}"
          echo "Endpoint:  ${{ steps.buildx.outputs.endpoint }}"
          echo "Status:    ${{ steps.buildx.outputs.status }}"
          echo "Flags:     ${{ steps.buildx.outputs.flags }}"
          echo "Platforms: ${{ steps.buildx.outputs.platforms }}"

      - name: Figure out release tag
        id: prep
        run: |
          if [ $GITHUB_REF_TYPE == "tag" ]; then
            RELEASE_VERSION=${GITHUB_REF_NAME#*/}
          else
            RELEASE_VERSION='latest'
          fi
          echo ::set-output name=version::${RELEASE_VERSION}

      - name: Log into registry ${{ env.REGISTRY }}
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract Docker metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
          tags: |
            type=raw,value=${{ steps.prep.outputs.version }},enable=${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }}
            type=raw,value=latest,enable={{is_default_branch}}

      - name: Build and push Docker image
        id: build-and-push
        uses: docker/build-push-action@v6
        with:
          context: .
          # linux/arm64 doesn't currently work because cffi doesn't want to build :(
          platforms: linux/amd64
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}