Skip to content

feat: workflows and goreleaser #1

feat: workflows and goreleaser

feat: workflows and goreleaser #1

Workflow file for this run

name: Deploy Canary
on:
push:
branches: [ main ]
workflow_dispatch:
permissions:
contents: write
packages: write
pages: write
id-token: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]
exclude:
- os: windows
arch: arm64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build canary for ${{ matrix.os }}-${{ matrix.arch }}
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
run: |
output="canary-${{ matrix.os }}-${{ matrix.arch }}"
if [ "${{ matrix.os }}" = "windows" ]; then
output="${output}.exe"
fi
go build -ldflags="-s -w" -o "dist/${output}" ./main.go
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: canary-${{ matrix.os }}-${{ matrix.arch }}
path: dist/canary-*
docker:
runs-on: ubuntu-latest
needs: build-and-deploy
steps:
- name: Checkout
uses: actions/checkout@v4
- 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.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
create-release:
runs-on: ubuntu-latest
needs: build-and-deploy
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist/
- name: Create nightly release
uses: softprops/action-gh-release@v2
with:
tag_name: nightly-${{ github.sha }}
name: Nightly Build ${{ github.sha }}
body: |
Automated nightly build of canary scanner
**Commit:** ${{ github.sha }}
**Branch:** ${{ github.ref_name }}
**Date:** ${{ github.event.head_commit.timestamp }}
## Installation
Download the appropriate binary for your platform and make it executable:
```bash
# Linux/macOS
chmod +x canary-*
./canary --help
# Windows
canary-windows-amd64.exe --help
```
files: dist/**/canary-*
draft: false
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}