diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fd66577 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1202919..2791fae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ output/* -test/* \ No newline at end of file +test/* +build/* \ No newline at end of file diff --git a/justfile b/justfile new file mode 100644 index 0000000..f9131c1 --- /dev/null +++ b/justfile @@ -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