|
| 1 | +name: gr26 |
| 2 | +run-name: Triggered by ${{ github.event_name }} to ${{ github.ref }} by @${{ github.actor }} |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - "**" |
| 8 | + tags: |
| 9 | + - "**" |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ${{ matrix.runner }} |
| 14 | + name: Build ${{ matrix.platform }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - platform: linux/amd64 |
| 20 | + runner: ubuntu-24.04 |
| 21 | + - platform: linux/arm64 |
| 22 | + runner: ubuntu-24.04-arm |
| 23 | + |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + packages: write |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@v3 |
| 34 | + |
| 35 | + - name: Log in to GitHub Container Registry |
| 36 | + uses: docker/login-action@v3 |
| 37 | + with: |
| 38 | + registry: ghcr.io |
| 39 | + username: ${{ github.actor }} |
| 40 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + |
| 42 | + - name: Generate platform pair |
| 43 | + id: platform |
| 44 | + run: | |
| 45 | + platform=${{ matrix.platform }} |
| 46 | + echo "pair=${platform//\//-}" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - name: Build and push by digest |
| 49 | + id: build |
| 50 | + uses: docker/build-push-action@v5 |
| 51 | + with: |
| 52 | + context: gr26 |
| 53 | + platforms: ${{ matrix.platform }} |
| 54 | + outputs: type=image,name=ghcr.io/gaucho-racing/mapache/gr26,push-by-digest=true,name-canonical=true,push=true |
| 55 | + cache-from: type=gha,scope=build-${{ steps.platform.outputs.pair }} |
| 56 | + cache-to: type=gha,scope=build-${{ steps.platform.outputs.pair }},mode=max |
| 57 | + |
| 58 | + - name: Export digest |
| 59 | + run: | |
| 60 | + mkdir -p /tmp/digests |
| 61 | + digest="${{ steps.build.outputs.digest }}" |
| 62 | + touch "/tmp/digests/${digest#sha256:}" |
| 63 | +
|
| 64 | + - name: Upload digest |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: digests-${{ steps.platform.outputs.pair }} |
| 68 | + path: /tmp/digests/* |
| 69 | + if-no-files-found: error |
| 70 | + retention-days: 1 |
| 71 | + |
| 72 | + merge: |
| 73 | + runs-on: ubuntu-latest |
| 74 | + name: Merge manifests |
| 75 | + needs: build |
| 76 | + |
| 77 | + permissions: |
| 78 | + contents: read |
| 79 | + packages: write |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Checkout code |
| 83 | + uses: actions/checkout@v4 |
| 84 | + with: |
| 85 | + fetch-depth: 0 |
| 86 | + fetch-tags: true |
| 87 | + |
| 88 | + - name: Download digests |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: |
| 91 | + path: /tmp/digests |
| 92 | + pattern: digests-* |
| 93 | + merge-multiple: true |
| 94 | + |
| 95 | + - name: Set up Docker Buildx |
| 96 | + uses: docker/setup-buildx-action@v3 |
| 97 | + |
| 98 | + - name: Log in to GitHub Container Registry |
| 99 | + uses: docker/login-action@v3 |
| 100 | + with: |
| 101 | + registry: ghcr.io |
| 102 | + username: ${{ github.actor }} |
| 103 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + |
| 105 | + - name: Check if this commit has a release tag |
| 106 | + id: release |
| 107 | + run: | |
| 108 | + tag=$(git tag --points-at HEAD | grep '^v' | head -n1) |
| 109 | + if [ -n "$tag" ]; then |
| 110 | + echo "Found tag: $tag" |
| 111 | + if gh release view "$tag" --json tagName > /dev/null 2>&1; then |
| 112 | + echo "release_tag=$tag" >> $GITHUB_OUTPUT |
| 113 | + echo "is_release=true" >> $GITHUB_OUTPUT |
| 114 | + exit 0 |
| 115 | + fi |
| 116 | + fi |
| 117 | + echo "is_release=false" >> $GITHUB_OUTPUT |
| 118 | + env: |
| 119 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + |
| 121 | + - name: Generate tag list |
| 122 | + id: tags |
| 123 | + shell: bash |
| 124 | + run: | |
| 125 | + TAGS="type=sha" |
| 126 | +
|
| 127 | + if [ "${GITHUB_REF_TYPE}" = "branch" ] && [ "${GITHUB_REF_NAME}" = "main" ]; then |
| 128 | + TAGS="${TAGS}\ntype=raw,value=latest" |
| 129 | + fi |
| 130 | +
|
| 131 | + if [ "${{ steps.release.outputs.is_release }}" = "true" ]; then |
| 132 | + CLEAN_TAG=$(echo "${{ steps.release.outputs.release_tag }}" | sed 's/^v//') |
| 133 | + TAGS="${TAGS}\ntype=raw,value=${CLEAN_TAG}" |
| 134 | + fi |
| 135 | +
|
| 136 | + echo -e "tags<<EOF\n$TAGS\nEOF" >> $GITHUB_OUTPUT |
| 137 | +
|
| 138 | + - name: Extract image metadata |
| 139 | + id: meta |
| 140 | + uses: docker/metadata-action@v5 |
| 141 | + with: |
| 142 | + images: ghcr.io/gaucho-racing/mapache/gr26 |
| 143 | + tags: ${{ steps.tags.outputs.tags }} |
| 144 | + |
| 145 | + - name: Create manifest list and push |
| 146 | + working-directory: /tmp/digests |
| 147 | + run: | |
| 148 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 149 | + $(printf 'ghcr.io/gaucho-racing/mapache/gr26@sha256:%s ' *) |
| 150 | +
|
| 151 | + - name: Inspect image |
| 152 | + run: | |
| 153 | + docker buildx imagetools inspect ghcr.io/gaucho-racing/mapache/gr26:${{ steps.meta.outputs.version }} |
0 commit comments