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
153 changes: 153 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: Build and Release

on:
push:
branches: [ main, develop ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]

env:
GO_VERSION: '1.25'

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Download dependencies
run: go mod download

- name: Run tests
run: go test -v ./...

- name: Run go vet
run: go vet ./...

- name: Run go fmt check
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "Code is not formatted properly:"
gofmt -s -l .
exit 1
fi

build:
name: Build
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
goos: [ linux, darwin, windows ]
goarch: [ amd64, arm64 ]
exclude:
- goos: windows
goarch: arm64

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Get build info
id: build_info
run: |
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "build_time=$(date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
echo "git_commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "version=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
fi

- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ steps.build_info.outputs.version }}
BUILD_TIME: ${{ steps.build_info.outputs.build_time }}
GIT_COMMIT: ${{ steps.build_info.outputs.git_commit }}
run: |
mkdir -p dist
binary_name="stargo-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
binary_name="${binary_name}.exe"
fi

go build -ldflags "-w -s -X 'main.Version=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GitCommit=${GIT_COMMIT}'" \
-o "dist/${binary_name}" .

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: stargo-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/stargo-${{ matrix.goos }}-${{ matrix.goarch }}*

release:
name: Release
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')

steps:
- uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: dist

- name: Prepare release assets
run: |
mkdir -p release
cd dist
for dir in */; do
cd "$dir"
if [[ -f *.exe ]]; then
zip "../../release/${dir%/}.zip" *
else
tar -czf "../../release/${dir%/}.tar.gz" *
fi
cd ..
done
cd ..
ls -la release/

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: release/*
draft: false
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75 changes: 75 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Build artifacts
/dist/
/release/
stargo
stargo-*
*.tar.gz
*.zip

# Logs
*.log

# Temporary files
tmp/
temp/

# Environment files
.env
.env.local
.env.*.local

# Coverage reports
coverage.txt
coverage.html

# Profiling data
*.prof

# Debug files
debug
*.debug

# Local configuration files
config.local.*

# Backup files
*.bak
*.backup

# Package files
*.pkg.tar.xz
Loading