Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:

build-and-test:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
matrix:
include:
Expand All @@ -70,15 +73,55 @@ jobs:
goos: linux
goarch: arm64
artifact_name: tronbyt-server-linux-arm64
- os: macos-26
- os: macos-latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured if we're doing windows-latest, might as well update mac, I can remove if you'd like

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's better to be explicit with version numbers so that the runners don't change unexpectedly.

goos: darwin
goarch: arm64
artifact_name: tronbyt-server-darwin-arm64
- os: windows-latest
goos: windows
goarch: amd64
artifact_name: tronbyt-server-windows-amd64.exe

steps:
- uses: actions/checkout@v6

# Windows specific setup
# Install GCC and Libwebp
- name: Setup MSYS2
id: msys2
if: matrix.goos == 'windows'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
path-type: inherit
update: true
install: >-
mingw-w64-x86_64-gcc
mingw-w64-x86_64-libwebp
mingw-w64-x86_64-pkgconf

- name: Set CGO Flags (windows)
if: matrix.goos == 'windows'
shell: bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove the shell: bash here as it's the default.

run: |
# Retrieve the install location from the previous step
MSYS_ROOT="${{ steps.msys2.outputs.msys2-location }}"

echo "Using MSYS2 at: $MSYS_ROOT"

# Convert backslashes to forward slashes for GCC compatibility
MSYS_ROOT=$(echo "$MSYS_ROOT" | sed 's/\\/\//g')

# Write to GITHUB_ENV so following steps (like 'go build') can see them
echo "CGO_CFLAGS=-I${MSYS_ROOT}/mingw64/include" >> "$GITHUB_ENV"
echo "CGO_LDFLAGS=-L${MSYS_ROOT}/mingw64/lib" >> "$GITHUB_ENV"

# Optional: Add the mingw64 bin folder to PATH so dlls are found during tests
echo "${MSYS_ROOT}/mingw64/bin" >> "$GITHUB_PATH"

# Linux/Mac specific setup
- name: Install system dependencies
if: matrix.goos != 'windows'
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update
Expand All @@ -96,19 +139,29 @@ jobs:
run: go mod download

- name: Test
# CGO required for pixlet
run: CGO_ENABLED=1 go test -v ./...
env:
CGO_ENABLED: 1 # CGO required for pixlet
run: go test -v ./...

- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 1
run: |
VERSION=${GITHUB_REF_NAME}
COMMIT=${GITHUB_SHA}
DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

# Base flags
LDFLAGS="-w -s -X 'tronbyt-server/internal/version.Version=${VERSION}' -X 'tronbyt-server/internal/version.Commit=${COMMIT}' -X 'tronbyt-server/internal/version.BuildDate=${DATE}'"
CGO_ENABLED=1 go build -v -ldflags "${LDFLAGS}" -o ${{ matrix.artifact_name }} ./cmd/server

# Add static flags ONLY for Windows to avoid DLL dependency
if [ "${{ matrix.goos }}" == "windows" ]; then
LDFLAGS="${LDFLAGS} -extldflags '-static'"
fi

go build -v -ldflags "${LDFLAGS}" -tags gzip_fonts -o ${{ matrix.artifact_name }} ./cmd/server

- name: Upload Release Artifacts
uses: actions/upload-artifact@v6
Expand Down
51 changes: 51 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Write-Host "Checking dependencies..." -ForegroundColor Cyan
if (-not (Get-Command "gcc" -ErrorAction SilentlyContinue)) {
Write-Error "GCC not found. Please ensure MSYS2 MinGW64 bin folder is in your PATH."
exit 1
}

# 1. Setup Environment Variables
$env:GOOS = "windows"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "1" # Required for libwebp and sqlite

# 2. Get Version Info
$VERSION = "dev"
$COMMIT = "unknown"
$DATE = Get-Date -Format "yyyy-MM-dd"

if (Test-Path .git) {
if (-not (Get-Command "git" -ErrorAction SilentlyContinue)) {
Write-Error "git not found, but .git directory exists. Cannot determine version information."
exit 1
}
$COMMIT = git rev-parse --short HEAD
$VERSION = git describe --tags --always --dirty
}

Write-Host "Building Tronbyt Server ($VERSION)..." -ForegroundColor Green

# 3. Download Dependencies
go mod download

# 4. Build 'boot' (Entrypoint wrapper)
# Note: Usually on Windows you don't need this wrapper, but building it just in case.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the boot wrapper here.

# Boot is CGO-free (CGO_ENABLED=0), so we toggle it off briefly.
$env:CGO_ENABLED = "0"
go build -ldflags="-w -s" -o boot.exe ./cmd/boot
$env:CGO_ENABLED = "1"

# 5. Build 'tronbyt-server'
$LDFLAGS = "-w -s -extldflags '-static' -X 'tronbyt-server/internal/version.Version=$VERSION' -X 'tronbyt-server/internal/version.Commit=$COMMIT' -X 'tronbyt-server/internal/version.BuildDate=$DATE'"

go build -ldflags="$LDFLAGS" -tags gzip_fonts -o tronbyt-server.exe ./cmd/server

if ($LASTEXITCODE -ne 0) {
Write-Error "Server build failed!"
exit 1
}

# 6. Build 'migrate' (Database tool)
go build -ldflags="-w -s" -o migrate.exe ./cmd/migrate

Write-Host "Build Complete!" -ForegroundColor Green
2 changes: 2 additions & 0 deletions cmd/boot/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change.
go build -v -ldflags "${LDFLAGS}" -tags gzip_fonts -o ${{ matrix.artifact_name }} ./cmd/server only builds the server command. No need to exclude the boot command because it won't be built.


package main

import (
Expand Down
Loading