|
| 1 | +name: "Build & Release CI Pipeline" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +env: |
| 9 | + GO_VERSION: "1.23.4" |
| 10 | + REGISTRY_IMAGE: "ghcr.io/proofrock/ws4sql" |
| 11 | + |
| 12 | +jobs: |
| 13 | + test: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - uses: actions/setup-go@v5 |
| 21 | + with: |
| 22 | + go-version: ${{ env.GO_VERSION }} |
| 23 | + |
| 24 | + - name: Test |
| 25 | + run: make test |
| 26 | + |
| 27 | + build_linux_amd64: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - uses: actions/setup-go@v5 |
| 35 | + with: |
| 36 | + go-version: ${{ env.GO_VERSION }} |
| 37 | + |
| 38 | + - name: Modify version number |
| 39 | + run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go |
| 40 | + working-directory: src/ |
| 41 | + |
| 42 | + - name: Build dir generation |
| 43 | + run: mkdir bin/ |
| 44 | + |
| 45 | + - name: Compile and Pack Artifact |
| 46 | + run: | |
| 47 | + make build-static |
| 48 | + tar czf bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz -C bin/ ws4sql |
| 49 | + rm bin/ws4sql |
| 50 | +
|
| 51 | + - name: Upload artifacts |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: binary_linux_amd64 |
| 55 | + path: bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz |
| 56 | + retention-days: 1 |
| 57 | + |
| 58 | + # TODO build_linux_arm64 |
| 59 | + |
| 60 | + build_macos_arm64: |
| 61 | + runs-on: macos-latest |
| 62 | + |
| 63 | + steps: |
| 64 | + - name: Checkout |
| 65 | + uses: actions/checkout@v4 |
| 66 | + |
| 67 | + - uses: actions/setup-go@v5 |
| 68 | + with: |
| 69 | + go-version: ${{ env.GO_VERSION }} |
| 70 | + |
| 71 | + - name: Modify version number |
| 72 | + run: sed -i.bkp 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go |
| 73 | + working-directory: src/ |
| 74 | + |
| 75 | + - name: Build dir generation |
| 76 | + run: mkdir bin/ |
| 77 | + |
| 78 | + - name: Compile and Pack Artifact |
| 79 | + run: | |
| 80 | + make build |
| 81 | + tar czf bin/ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz -C bin/ ws4sql |
| 82 | + rm bin/ws4sql |
| 83 | +
|
| 84 | + - name: Upload artifacts |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + with: |
| 87 | + name: binary_macos_arm64 |
| 88 | + path: bin/ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz |
| 89 | + retention-days: 1 |
| 90 | + |
| 91 | + build_win_amd64: |
| 92 | + runs-on: windows-latest |
| 93 | + |
| 94 | + steps: |
| 95 | + - name: Checkout |
| 96 | + uses: actions/checkout@v4 |
| 97 | + |
| 98 | + - uses: actions/setup-go@v5 |
| 99 | + with: |
| 100 | + go-version: ${{ env.GO_VERSION }} |
| 101 | + |
| 102 | + - name: Modify version number |
| 103 | + run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go |
| 104 | + working-directory: src/ |
| 105 | + |
| 106 | + - name: Build dir generation |
| 107 | + run: mkdir bin/ |
| 108 | + |
| 109 | + - name: Install zip |
| 110 | + run: choco install zip -y |
| 111 | + |
| 112 | + - name: Compile and Pack Artifact |
| 113 | + run: | |
| 114 | + make build-windows |
| 115 | + zip -j -9 bin/ws4sql-${{ github.ref_name }}-win-amd64.zip bin/ws4sql.exe |
| 116 | + rm bin/ws4sql.exe |
| 117 | +
|
| 118 | + - name: Upload artifacts |
| 119 | + uses: actions/upload-artifact@v4 |
| 120 | + with: |
| 121 | + name: binary_win_amd64 |
| 122 | + path: bin/ws4sql-${{ github.ref_name }}-win-amd64.zip |
| 123 | + retention-days: 1 |
| 124 | + |
| 125 | + release: |
| 126 | + needs: |
| 127 | + - build_linux_amd64 |
| 128 | + - build_macos_arm64 |
| 129 | + - build_win_amd64 |
| 130 | + - test |
| 131 | + runs-on: ubuntu-latest |
| 132 | + |
| 133 | + steps: |
| 134 | + - name: Download artifacts [1/3] |
| 135 | + uses: actions/download-artifact@v4 |
| 136 | + with: |
| 137 | + name: binary_linux_amd64 |
| 138 | + path: bin/ |
| 139 | + |
| 140 | + - name: Download artifacts [2/3] |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + name: binary_macos_arm64 |
| 144 | + path: bin/ |
| 145 | + |
| 146 | + - name: Download artifacts [3/3] |
| 147 | + uses: actions/download-artifact@v4 |
| 148 | + with: |
| 149 | + name: binary_win_amd64 |
| 150 | + path: bin/ |
| 151 | + |
| 152 | + - name: Verify Artifact Creation |
| 153 | + run: ls -lh bin/ |
| 154 | + |
| 155 | + - name: Create Draft Release |
| 156 | + id: create_release |
| 157 | + uses: actions/create-release@v1 |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.TOKEN }} |
| 160 | + with: |
| 161 | + body: _replace_me_ |
| 162 | + tag_name: ${{ github.ref_name }} |
| 163 | + release_name: Version ${{ github.ref_name }} |
| 164 | + draft: true |
| 165 | + prerelease: false |
| 166 | + |
| 167 | + - name: Release Artifact [linux/amd64] |
| 168 | + uses: actions/upload-release-asset@v1 |
| 169 | + env: |
| 170 | + GITHUB_TOKEN: ${{ secrets.TOKEN }} |
| 171 | + with: |
| 172 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 173 | + asset_path: bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz |
| 174 | + asset_name: ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz |
| 175 | + asset_content_type: application/gzip |
| 176 | + |
| 177 | + - name: Release Artifact [darwin/arm64] |
| 178 | + uses: actions/upload-release-asset@v1 |
| 179 | + env: |
| 180 | + GITHUB_TOKEN: ${{ secrets.TOKEN }} |
| 181 | + with: |
| 182 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 183 | + asset_path: bin/ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz |
| 184 | + asset_name: ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz |
| 185 | + asset_content_type: application/zip |
| 186 | + |
| 187 | + - name: Release Artifact [windows/amd64] |
| 188 | + uses: actions/upload-release-asset@v1 |
| 189 | + env: |
| 190 | + GITHUB_TOKEN: ${{ secrets.TOKEN }} |
| 191 | + with: |
| 192 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 193 | + asset_path: bin/ws4sql-${{ github.ref_name }}-win-amd64.zip |
| 194 | + asset_name: ws4sql-${{ github.ref_name }}-win-amd64.zip |
| 195 | + asset_content_type: application/zip |
| 196 | + |
| 197 | + build-docker: |
| 198 | + runs-on: ubuntu-latest |
| 199 | + strategy: |
| 200 | + fail-fast: false |
| 201 | + matrix: |
| 202 | + platform: |
| 203 | + - linux/amd64 |
| 204 | + - linux/arm64 |
| 205 | + steps: |
| 206 | + - name: Prepare |
| 207 | + run: | |
| 208 | + platform=${{ matrix.platform }} |
| 209 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 210 | +
|
| 211 | + - name: Checkout |
| 212 | + uses: actions/checkout@v4 |
| 213 | + |
| 214 | + - name: Modify version number |
| 215 | + run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go |
| 216 | + working-directory: src/ |
| 217 | + |
| 218 | + - name: Docker meta |
| 219 | + id: meta |
| 220 | + uses: docker/metadata-action@v5 |
| 221 | + with: |
| 222 | + images: ${{ env.REGISTRY_IMAGE }} |
| 223 | + |
| 224 | + # - name: Set up QEMU |
| 225 | + # uses: docker/setup-qemu-action@v3 |
| 226 | + |
| 227 | + - name: Set up Docker Buildx |
| 228 | + uses: docker/setup-buildx-action@v3 |
| 229 | + |
| 230 | + - name: Login to Github Container Registry |
| 231 | + uses: docker/login-action@v3 |
| 232 | + with: |
| 233 | + registry: ghcr.io |
| 234 | + username: ${{ github.actor }} |
| 235 | + password: ${{ secrets.TOKEN }} |
| 236 | + |
| 237 | + - name: Build and push by digest |
| 238 | + id: build |
| 239 | + uses: docker/build-push-action@v5 |
| 240 | + with: |
| 241 | + context: . |
| 242 | + platforms: ${{ matrix.platform }} |
| 243 | + labels: ${{ steps.meta.outputs.labels }} |
| 244 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 245 | + |
| 246 | + - name: Export digest |
| 247 | + run: | |
| 248 | + mkdir -p /tmp/digests |
| 249 | + digest="${{ steps.build.outputs.digest }}" |
| 250 | + touch "/tmp/digests/${digest#sha256:}" |
| 251 | +
|
| 252 | + - name: Upload digest |
| 253 | + uses: actions/upload-artifact@v4 |
| 254 | + with: |
| 255 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 256 | + path: /tmp/digests/* |
| 257 | + if-no-files-found: error |
| 258 | + retention-days: 1 |
| 259 | + |
| 260 | + merge-docker: |
| 261 | + runs-on: ubuntu-latest |
| 262 | + needs: |
| 263 | + - build-docker |
| 264 | + - release |
| 265 | + - test |
| 266 | + steps: |
| 267 | + - name: Download digests |
| 268 | + uses: actions/download-artifact@v4 |
| 269 | + with: |
| 270 | + path: /tmp/digests |
| 271 | + pattern: digests-* |
| 272 | + merge-multiple: true |
| 273 | + |
| 274 | + - name: Set up Docker Buildx |
| 275 | + uses: docker/setup-buildx-action@v3 |
| 276 | + |
| 277 | + - name: Docker meta |
| 278 | + id: meta |
| 279 | + uses: docker/metadata-action@v5 |
| 280 | + with: |
| 281 | + images: ${{ env.REGISTRY_IMAGE }} |
| 282 | + |
| 283 | + - name: Login to Github Container Registry |
| 284 | + uses: docker/login-action@v3 |
| 285 | + with: |
| 286 | + registry: ghcr.io |
| 287 | + username: ${{ github.actor }} |
| 288 | + password: ${{ secrets.TOKEN }} |
| 289 | + |
| 290 | + - name: Create manifest list and push |
| 291 | + working-directory: /tmp/digests |
| 292 | + run: | |
| 293 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 294 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 295 | +
|
| 296 | + - name: Inspect image |
| 297 | + run: | |
| 298 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments