cargo-msrv 0.19.3

Find your minimum supported Rust version (MSRV)!
Documentation
name: "ci-docker"

on:
  push:
    branches: [main]
    tags:
      - 'v*.*.*'
  pull_request:
    branches: [main]
  merge_group:
jobs:
  docker-build:
    name: Docker Build (${{ matrix.platform }})
    runs-on: ubuntu-latest
    strategy:
      matrix:
        platform: [linux/amd64, linux/arm64]
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v4

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v4

      - name: Cache Docker layers
        uses: actions/cache@v4
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ matrix.platform }}-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-${{ matrix.platform }}-

      - name: Login to Docker Hub
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v4
        with:
          username: foresterre
          password: ${{ secrets.DOCKER_TOKEN }}

      - name: Login to GHCR
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push by digest
        id: docker_build
        uses: docker/build-push-action@v7
        with:
          context: ./
          file: ./Dockerfile
          builder: ${{ steps.buildx.outputs.name }}
          platforms: ${{ matrix.platform }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache
          outputs: type=image,name=foresterre/cargo-msrv,push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}

      - name: Export digest
        if: github.event_name != 'pull_request'
        run: |
          mkdir -p /tmp/digests
          digest="${{ steps.docker_build.outputs.digest }}"
          touch "/tmp/digests/${digest#sha256:}"

      - name: Upload digest
        if: github.event_name != 'pull_request'
        uses: actions/upload-artifact@v7
        with:
          name: digests-${{ strategy.job-index }}
          path: /tmp/digests/*
          if-no-files-found: error
          retention-days: 1

      # This step has been failing for a while, for unknown reasons
      #- name: Update Docker Hub description
      #  if: github.event_name != 'pull_request'
      #  uses: peter-evans/dockerhub-description@v4
      #  with:
      #    username: foresterre
      #    password: ${{ secrets.DOCKER_TOKEN }}

      - name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}

  docker-merge:
    name: Docker Merge Manifests
    runs-on: ubuntu-latest
    needs: docker-build
    if: github.event_name != 'pull_request'
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Download digests
        uses: actions/download-artifact@v8
        with:
          path: /tmp/digests
          pattern: digests-*
          merge-multiple: true

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v4

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v6
        with:
          images: |
            foresterre/cargo-msrv
            ghcr.io/${{ github.repository_owner }}/cargo-msrv
          tags: |
            type=schedule
            type=ref,event=branch
            type=ref,event=pr
            type=sha
            type=raw,value=latest,enable={{is_default_branch}}
            type=semver,pattern={{version}}

      - name: Login to Docker Hub
        uses: docker/login-action@v4
        with:
          username: foresterre
          password: ${{ secrets.DOCKER_TOKEN }}

      - name: Login to GHCR
        uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Create manifest list and push
        working-directory: /tmp/digests
        run: |
          tags=()
          while IFS= read -r tag; do
            tags+=("--tag" "$tag")
          done <<< "${{ steps.meta.outputs.tags }}"
          docker buildx imagetools create "${tags[@]}" \
            $(printf 'foresterre/cargo-msrv@sha256:%s ' *)

      - name: Inspect image
        run: |
          docker buildx imagetools inspect foresterre/cargo-msrv:${{ steps.meta.outputs.version }}