Simplify docker-publish.yml workflow and update badges
#6
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: Docker | |
| on: | |
| push: | |
| branches: [ beta ] | |
| tags: [ 'magg/v*' ] | |
| pull_request: | |
| branches: [ main, beta ] | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| test-dev-container: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| python-version: ['3.12', '3.13'] | |
| fail-fast: false | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch,suffix=-dev-py${{ matrix.python-version }} | |
| type=ref,event=pr,suffix=-dev-py${{ matrix.python-version }} | |
| type=semver,pattern={{version}},suffix=-dev-py${{ matrix.python-version }} | |
| type=semver,pattern={{major}}.{{minor}},suffix=-dev-py${{ matrix.python-version }} | |
| type=raw,value=latest,enable={{is_default_branch}},suffix=-dev-py${{ matrix.python-version }} | |
| - name: Build dev image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./dockerfile | |
| target: dev | |
| push: false | |
| tags: ${{ steps.meta.outputs.tags }} | |
| # labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| PYTHON_VERSION=${{ matrix.python-version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| load: true | |
| provenance: false | |
| sbom: false | |
| - name: Run tests in container | |
| run: | | |
| docker run --rm \ | |
| -e MAGG_LOG_LEVEL= \ | |
| ${{ steps.meta.outputs.tags }} \ | |
| pytest -v | |
| - name: Push dev image | |
| if: github.event_name != 'pull_request' | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./dockerfile | |
| target: dev | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| # labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| PYTHON_VERSION=${{ matrix.python-version }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false | |
| sbom: false | |
| build-and-push: | |
| needs: test-dev-container | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| include: | |
| - target: pre | |
| suffix: "-pre" | |
| - target: pro | |
| suffix: "" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch,suffix=${{ matrix.suffix }} | |
| type=ref,event=pr,suffix=${{ matrix.suffix }} | |
| type=semver,pattern={{version}},suffix=${{ matrix.suffix }} | |
| type=semver,pattern={{major}}.{{minor}},suffix=${{ matrix.suffix }} | |
| type=raw,value=latest,enable={{is_default_branch}},suffix=${{ matrix.suffix }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./dockerfile | |
| target: ${{ matrix.target }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| # labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| provenance: false | |
| sbom: false | |
| cleanup-untagged: | |
| needs: [test-dev-container, build-and-push] | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' | |
| permissions: | |
| packages: write | |
| steps: | |
| - name: Delete untagged images | |
| uses: actions/delete-package-versions@v5 | |
| with: | |
| package-name: 'magg' | |
| package-type: 'container' | |
| delete-only-untagged-versions: 'true' | |
| min-versions-to-keep: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} |