Skip to content

Commit

Permalink
feat: Add build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
simse committed Sep 13, 2024
1 parent f033e86 commit 703e7ce
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build and Release

on:
push:
tags:
- '*'
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install just
run: |
mkdir -p "$HOME/.local/bin"
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to "$HOME/.local/bin"
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.23.x"
- name: Build binaries
run: just build
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binaries
path: build/fgc-*
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
files: build/fgc-*
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
output/*
test/*
test/*
build/*
32 changes: 32 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set shell := ["bash", "-eu", "-o", "pipefail", "-c"]

build:
#!/usr/bin/env bash
# Determine version
if [ "$(git rev-parse --abbrev-ref HEAD)" = "main" ]; then
version="latest"
elif git describe --tags --exact-match >/dev/null 2>&1; then
version="$(git describe --tags --exact-match)"
else
version="$(git rev-parse --short HEAD)"
fi

echo "Building version: $version"

platforms=("linux" "windows" "darwin")
archs=("amd64" "arm64")

for GOOS in "${platforms[@]}"; do
for GOARCH in "${archs[@]}"; do
output="fgc-${GOOS}-${GOARCH}-${version}"
if [ "$GOOS" = "windows" ]; then
output+=".exe"
fi
echo "Building for $GOOS/$GOARCH: $output"

# Build the binary
env CGO_ENABLED=0 GOOS="$GOOS" GOARCH="$GOARCH" \
go build -ldflags="-s -w" -o "build/$output" .
done
done

0 comments on commit 703e7ce

Please sign in to comment.