|
| 1 | +name: Go Build & Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + tags-ignore: |
| 10 | + - "*" |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + packages: write |
| 15 | + issues: write |
| 16 | + id-token: write |
| 17 | + |
| 18 | +env: |
| 19 | + REGISTRY: ghcr.io |
| 20 | + IMAGE_NAME: ${{ github.repository }} |
| 21 | + |
| 22 | +jobs: |
| 23 | + goreleaser: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Set up Go |
| 32 | + uses: actions/setup-go@v5 |
| 33 | + with: |
| 34 | + go-version: stable |
| 35 | + |
| 36 | + # More assembly might be required: Docker logins, GPG, etc. |
| 37 | + # It all depends on your needs. |
| 38 | + - name: Run GoReleaser |
| 39 | + uses: goreleaser/goreleaser-action@v6 |
| 40 | + with: |
| 41 | + args: release --clean |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + - name: Upload arm64 build artifacts |
| 46 | + uses: actions/upload-artifact@v4 |
| 47 | + with: |
| 48 | + name: CalendarAPI-linux-arm64 |
| 49 | + path: dist/CalendarAPI_linux_arm64_v8.0/calendarapi |
| 50 | + |
| 51 | + - name: Upload amd64 build artifacts |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: CalendarAPI-linux-amd64 |
| 55 | + path: dist/CalendarAPI_linux_amd64_v1/calendarapi |
| 56 | + |
| 57 | + docker-build: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: |
| 60 | + - goreleaser |
| 61 | + |
| 62 | + strategy: |
| 63 | + fail-fast: false |
| 64 | + matrix: |
| 65 | + include: |
| 66 | + - platform: linux/amd64 |
| 67 | + os: linux |
| 68 | + arch: amd64 |
| 69 | + - platform: linux/arm64 |
| 70 | + os: linux |
| 71 | + arch: arm64 |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: set environment variables |
| 75 | + run: | |
| 76 | + platform=${{ matrix.platform }} |
| 77 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 78 | +
|
| 79 | + image="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" |
| 80 | + image="$(echo $image | tr '[:upper:]' '[:lower:]')" |
| 81 | + echo "FULL_IMAGE_NAME=${image}" >> $GITHUB_ENV |
| 82 | +
|
| 83 | + - name: Setup Docker buildx |
| 84 | + uses: docker/setup-buildx-action@v3 |
| 85 | + |
| 86 | + - name: Login to GitHub Container Registry |
| 87 | + uses: docker/login-action@v3 |
| 88 | + with: |
| 89 | + registry: ghcr.io |
| 90 | + username: ${{ github.actor }} |
| 91 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + |
| 93 | + - name: Docker meta |
| 94 | + id: meta |
| 95 | + uses: docker/metadata-action@v5 |
| 96 | + with: |
| 97 | + images: ghcr.io/${{ github.repository }} |
| 98 | + |
| 99 | + - name: Checkout |
| 100 | + uses: actions/checkout@v4 |
| 101 | + with: |
| 102 | + fetch-depth: 0 |
| 103 | + |
| 104 | + - name: Pull in platform artifact |
| 105 | + uses: actions/download-artifact@v4 |
| 106 | + with: |
| 107 | + name: CalendarAPI-linux-${{ matrix.arch }} |
| 108 | + |
| 109 | + - name: mark artifact as executable |
| 110 | + run: | |
| 111 | + chmod +x calendarapi |
| 112 | +
|
| 113 | + - name: Build and push by digest |
| 114 | + id: build |
| 115 | + uses: docker/build-push-action@v6 |
| 116 | + with: |
| 117 | + context: . |
| 118 | + platforms: ${{ matrix.platform }} |
| 119 | + labels: ${{ steps.meta.outputs.labels }} |
| 120 | + outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true,annotation-index.org.opencontainers.image.description=CalendarAPI is a service that parses iCal files and exposes their content via gRPC or a REST API. |
| 121 | + |
| 122 | + - name: Export digest |
| 123 | + run: | |
| 124 | + mkdir -p /tmp/digests |
| 125 | + digest="${{ steps.build.outputs.digest }}" |
| 126 | + touch "/tmp/digests/${digest#sha256:}" |
| 127 | +
|
| 128 | + - name: Upload digest |
| 129 | + uses: actions/upload-artifact@v4 |
| 130 | + with: |
| 131 | + name: image-digest-${{ env.PLATFORM_PAIR }} |
| 132 | + path: /tmp/digests/* |
| 133 | + if-no-files-found: error |
| 134 | + retention-days: 1 |
| 135 | + |
| 136 | + docker-publish: |
| 137 | + name: Docker Publish |
| 138 | + runs-on: ubuntu-latest |
| 139 | + needs: |
| 140 | + - docker-build |
| 141 | + |
| 142 | + permissions: |
| 143 | + contents: read |
| 144 | + packages: write |
| 145 | + id-token: write |
| 146 | + |
| 147 | + steps: |
| 148 | + - name: set environment variables |
| 149 | + run: | |
| 150 | + image="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" |
| 151 | + image="$(echo $image | tr '[:upper:]' '[:lower:]')" |
| 152 | + echo "FULL_IMAGE_NAME=${image}" >> $GITHUB_ENV |
| 153 | +
|
| 154 | + - name: Download digests |
| 155 | + uses: actions/download-artifact@v4 |
| 156 | + with: |
| 157 | + path: /tmp/digests |
| 158 | + pattern: image-digest-* |
| 159 | + merge-multiple: true |
| 160 | + |
| 161 | + - name: Set up Docker Buildx |
| 162 | + uses: docker/setup-buildx-action@v3 |
| 163 | + |
| 164 | + - name: Docker meta |
| 165 | + id: meta |
| 166 | + uses: docker/metadata-action@v5 |
| 167 | + with: |
| 168 | + images: ${{ env.FULL_IMAGE_NAME }} |
| 169 | + |
| 170 | + - name: Log into registry ${{ env.REGISTRY }} |
| 171 | + uses: docker/login-action@v3 |
| 172 | + with: |
| 173 | + registry: ${{ env.REGISTRY }} |
| 174 | + username: ${{ github.actor }} |
| 175 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 176 | + |
| 177 | + - name: Create manifest list and push |
| 178 | + working-directory: /tmp/digests |
| 179 | + run: | |
| 180 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 181 | + $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *) |
| 182 | +
|
| 183 | + - name: Inspect image |
| 184 | + run: | |
| 185 | + docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }} |
0 commit comments