Skip to content

Build & Release CI Pipeline #54

Build & Release CI Pipeline

Build & Release CI Pipeline #54

Workflow file for this run

name: "Build & Release CI Pipeline"
on:
push:
tags:
- "v*"
env:
GO_VERSION: "1.23.4"
REGISTRY_IMAGE: "ghcr.io/proofrock/ws4sql"
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Test
run: make test
build_linux_amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Modify version number
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
working-directory: src/
- name: Build dir generation
run: mkdir bin/
- name: Compile and Pack Artifact
run: |
make build-static
tar czf bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz -C bin/ ws4sql
rm bin/ws4sql
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binary_linux_amd64
path: bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz
retention-days: 1
# TODO build_linux_arm64
build_macos_arm64:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Modify version number
run: sed -i.bkp 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
working-directory: src/
- name: Build dir generation
run: mkdir bin/
- name: Compile and Pack Artifact
run: |
make build
tar czf bin/ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz -C bin/ ws4sql
rm bin/ws4sql
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binary_macos_arm64
path: bin/ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz
retention-days: 1
build_win_amd64:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Modify version number
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
working-directory: src/
- name: Build dir generation
run: mkdir bin/
- name: Install zip
run: choco install zip -y
- name: Compile and Pack Artifact
run: |
make build-windows
zip -j -9 bin/ws4sql-${{ github.ref_name }}-win-amd64.zip bin/ws4sql.exe
rm bin/ws4sql.exe
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binary_win_amd64
path: bin/ws4sql-${{ github.ref_name }}-win-amd64.zip
retention-days: 1
release:
needs:
- build_linux_amd64
- build_macos_arm64
- build_win_amd64
- test
runs-on: ubuntu-latest
steps:
- name: Download artifacts [1/3]
uses: actions/download-artifact@v4
with:
name: binary_linux_amd64
path: bin/
- name: Download artifacts [2/3]
uses: actions/download-artifact@v4
with:
name: binary_macos_arm64
path: bin/
- name: Download artifacts [3/3]
uses: actions/download-artifact@v4
with:
name: binary_win_amd64
path: bin/
- name: Verify Artifact Creation
run: ls -lh bin/
- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
body: _replace_me_
tag_name: ${{ github.ref_name }}
release_name: Version ${{ github.ref_name }}
draft: true
prerelease: false
- name: Release Artifact [linux/amd64]
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz
asset_name: ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz
asset_content_type: application/gzip
- name: Release Artifact [darwin/arm64]
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: bin/ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz
asset_name: ws4sql-${{ github.ref_name }}-macos-arm64.tar.gz
asset_content_type: application/zip
- name: Release Artifact [windows/amd64]
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: bin/ws4sql-${{ github.ref_name }}-win-amd64.zip
asset_name: ws4sql-${{ github.ref_name }}-win-amd64.zip
asset_content_type: application/zip
build-docker:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Modify version number
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
working-directory: src/
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge-docker:
runs-on: ubuntu-latest
needs:
- build-docker
- release
- test
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}