Refactor GitHub Actions Workflows #4
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
| # SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and IronCore contributors | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: Container Image | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| branches: | |
| - main | |
| paths-ignore: | |
| - 'docs/**' | |
| - '**/*.md' | |
| pull_request: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - 'docs/**' | |
| - '**/*.md' | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-push-image: | |
| name: Build and Push Docker Image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| # https://github.com/docker/metadata-action#typeedge | |
| type=edge | |
| # https://github.com/docker/metadata-action#latest-tag | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| # https://github.com/docker/metadata-action#typesemver | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| # https://github.com/docker/metadata-action#typeref | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| # https://github.com/docker/metadata-action#typesha | |
| type=sha,format=long | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| id: setup-buildx | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Go Build Cache for Docker | |
| uses: actions/cache@v4 | |
| id: cache | |
| with: | |
| path: go-build-cache | |
| key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} | |
| - name: Inject go-build-cache | |
| uses: reproducible-containers/buildkit-cache-dance@v3 | |
| with: | |
| cache-dir: go-build-cache | |
| skip-extraction: ${{ steps.cache.outputs.cache-hit }} | |
| builder: ${{ steps.setup-buildx.outputs.name }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-to: type=gha,mode=max | |
| cache-from: type=gha |