name: Build on: push: branches: [ main, develop ] pull_request: branches: [ main, develop ] workflow_dispatch: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: # Build Go binaries for multiple platforms build-binaries: name: Build Go Binary runs-on: ubuntu-latest strategy: matrix: include: # Linux AMD64 - goos: linux goarch: amd64 output: sovrabase-linux-amd64 # Linux ARM64 - goos: linux goarch: arm64 output: sovrabase-linux-arm64 # macOS AMD64 (Intel) - goos: darwin goarch: amd64 output: sovrabase-darwin-amd64 # macOS ARM64 (Apple Silicon) - goos: darwin goarch: arm64 output: sovrabase-darwin-arm64 # Windows AMD64 - goos: windows goarch: amd64 output: sovrabase-windows-amd64.exe steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.25.2' cache: true - name: Download dependencies run: go mod download - name: Build binary env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} CGO_ENABLED: 0 run: | go build -ldflags="-w -s" -o ${{ matrix.output }} ./cmd/server/main.go - name: Upload binary artifact uses: actions/upload-artifact@v4 with: name: ${{ matrix.output }} path: ${{ matrix.output }} retention-days: 7 # Build Docker images for multiple architectures build-docker: name: Build Docker Image strategy: matrix: include: # AMD64 on Ubuntu - runner: ubuntu-latest platform: linux/amd64 arch: amd64 # ARM64 on Ubuntu ARM runner - runner: ubuntu-24.04-arm platform: linux/arm64 arch: arm64 runs-on: ${{ matrix.runner }} permissions: contents: read packages: write steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch,suffix=-${{ matrix.arch }} type=ref,event=pr,suffix=-${{ matrix.arch }} type=sha,prefix={{branch}}-,suffix=-${{ matrix.arch }} - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . platforms: ${{ matrix.platform }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | TARGETARCH=${{ matrix.arch }} cache-from: type=gha cache-to: type=gha,mode=max provenance: false # Create manifest list to combine both architectures create-manifest: name: Create Multi-arch Manifest needs: build-docker runs-on: ubuntu-latest if: github.event_name != 'pull_request' permissions: contents: read packages: write steps: - name: Log in to Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Create and push manifest run: | # Extract branch or tag name BRANCH=${GITHUB_REF##*/} SHA_SHORT=$(echo $GITHUB_SHA | cut -c1-7) # Create manifest for branch tag (combines amd64 and arm64) docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH} \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-amd64 \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-arm64 # Create manifest for latest tag if on default branch if [ "${{ github.ref }}" = "refs/heads/main" ] || [ "${{ github.ref }}" = "refs/heads/master" ]; then docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-amd64 \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${SHA_SHORT}-arm64 fi