maa123/mastodon

View on GitHub
.github/workflows/build-image.yml

Summary

Maintainability
Test Coverage
name: Build container image
on:
  workflow_dispatch:
  push:
    branches:
      - 'master'
    tags:
      - '*'
  pull_request:
    paths:
      - .github/workflows/build-image.yml
      - Dockerfile
permissions:
  contents: read
  packages: write

jobs:
  build-image:
    runs-on: ubuntu-latest

    concurrency:
      group: ${{ github.ref }}
      cancel-in-progress: true

    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v2
        id: buildx

      - name: Log in to the Github Container registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: maa123
          password: ${{ secrets.GITHUB_TOKEN }}
        if: github.repository == 'maa123/mastodon' && github.event_name != 'pull_request'
      - uses: docker/metadata-action@v4
        id: meta
        with:
          images: ghcr.io/maa123/mastodon
          flavor: |
            latest=auto
          tags: |
            type=edge,branch=master
            type=pep440,pattern={{raw}}
            type=pep440,pattern=v{{major}}.{{minor}}
            type=ref,event=pr

      - name: Generate version suffix
        id: version_vars
        if: github.repository == 'maa123/mastodon' && github.event_name == 'push' && github.ref_name == 'master'
        run: |
          echo mastodon_version_suffix=+edge-$(git rev-parse --short HEAD) >> $GITHUB_OUTPUT

      - uses: docker/build-push-action@v4
        with:
          context: .
          build-args: MASTODON_VERSION_SUFFIX=${{ steps.version_vars.outputs.mastodon_version_suffix }}
          platforms: linux/amd64
          provenance: false
          builder: ${{ steps.buildx.outputs.name }}
          push: ${{ github.repository == 'maa123/mastodon' && github.event_name != 'pull_request' }}
          tags: |
            ghcr.io/maa123/mastodon:latest
            ghcr.io/maa123/mastodon:${{ github.sha }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max