|
| 1 | +name: Docker build & push image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [v4] |
| 6 | + tags: ["v*"] |
| 7 | + pull_request: |
| 8 | + branches: [v4] |
| 9 | + paths: |
| 10 | + - .github/workflows/docker-build-push.yaml |
| 11 | + - quartz/** |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + if: ${{ github.repository == 'jackyzha0/quartz' }} # Comment this out if you want to publish your own images on a fork! |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Set lowercase repository owner environment variable |
| 20 | + run: | |
| 21 | + echo "OWNER_LOWERCASE=${OWNER,,}" >> ${GITHUB_ENV} |
| 22 | + env: |
| 23 | + OWNER: "${{ github.repository_owner }}" |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 1 |
| 27 | + - name: Inject slug/short variables |
| 28 | + uses: rlespinasse/github-slug-action@v4.4.1 |
| 29 | + - name: Set up QEMU |
| 30 | + uses: docker/setup-qemu-action@v3 |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v3 |
| 33 | + with: |
| 34 | + install: true |
| 35 | + driver-opts: | |
| 36 | + image=moby/buildkit:master |
| 37 | + network=host |
| 38 | + - name: Install cosign |
| 39 | + if: github.event_name != 'pull_request' |
| 40 | + uses: sigstore/cosign-installer@v3.7.0 |
| 41 | + - name: Login to GitHub Container Registry |
| 42 | + uses: docker/#-action@v3 |
| 43 | + if: github.event_name != 'pull_request' |
| 44 | + with: |
| 45 | + registry: ghcr.io |
| 46 | + username: ${{ github.actor }} |
| 47 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + - name: Extract metadata tags and labels on PRs |
| 50 | + if: github.event_name == 'pull_request' |
| 51 | + id: meta-pr |
| 52 | + uses: docker/metadata-action@v5 |
| 53 | + with: |
| 54 | + images: ghcr.io/${{ env.OWNER_LOWERCASE }}/quartz |
| 55 | + tags: | |
| 56 | + type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }} |
| 57 | + labels: | |
| 58 | + org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/quartz" |
| 59 | + - name: Extract metadata tags and labels for main, release or tag |
| 60 | + if: github.event_name != 'pull_request' |
| 61 | + id: meta |
| 62 | + uses: docker/metadata-action@v5 |
| 63 | + with: |
| 64 | + flavor: | |
| 65 | + latest=auto |
| 66 | + images: ghcr.io/${{ env.OWNER_LOWERCASE }}/quartz |
| 67 | + tags: | |
| 68 | + type=semver,pattern={{version}} |
| 69 | + type=semver,pattern={{major}}.{{minor}} |
| 70 | + type=semver,pattern={{major}}.{{minor}}.{{patch}} |
| 71 | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} |
| 72 | + type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }} |
| 73 | + labels: | |
| 74 | + maintainer=${{ github.repository_owner }} |
| 75 | + org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/quartz" |
| 76 | +
|
| 77 | + - name: Build and push Docker image |
| 78 | + id: build-and-push |
| 79 | + uses: docker/build-push-action@v6 |
| 80 | + with: |
| 81 | + push: ${{ github.event_name != 'pull_request' }} |
| 82 | + build-args: | |
| 83 | + GIT_SHA=${{ env.GITHUB_SHA }} |
| 84 | + DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }} |
| 85 | + tags: ${{ steps.meta.outputs.tags || steps.meta-pr.outputs.tags }} |
| 86 | + labels: ${{ steps.meta.outputs.labels || steps.meta-pr.outputs.labels }} |
| 87 | + cache-from: type=gha |
| 88 | + cache-to: type=gha |
0 commit comments