Skip to content

Commit

Permalink
feat: Add GitHub Actions workflows for Go setup, testing, linting, an…
Browse files Browse the repository at this point in the history
…d release
  • Loading branch information
mattevans committed Dec 18, 2024
1 parent e81f15d commit cd0142e
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 28 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/go-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: go-setup

on:
workflow_call:
inputs:
go-version:
description: 'Go version to use'
required: false
default: '1.23'
type: string

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
cache: true
80 changes: 80 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: go-test

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

permissions:
contents: read
checks: write

jobs:
test:
name: test-${{ matrix.os }}-${{ matrix.test-group }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
test-group: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: ./.github/workflows/go-setup.yml
with:
go-version: ${{ vars.GO_VERSION }}

- name: Run Tests
run: |
# List all packages
PKGS=$(go list ./...)
# Get total package count and calculate split
COUNT=$(echo "$PKGS" | wc -l)
SPLIT=$((COUNT / 4))
START=$(((matrix.test-group - 1) * SPLIT))
# Select packages for this group
if [ "${{ matrix.test-group }}" == "4" ]; then
TEST_PKGS=$(echo "$PKGS" | tail -n +$START)
else
TEST_PKGS=$(echo "$PKGS" | tail -n +$START | head -n $SPLIT)
fi
# Run tests for this group with JSON output
go test -v -race -json $TEST_PKGS > test.${{ matrix.test-group }}.json
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.test-group }}
path: test.${{ matrix.test-group }}.json

annotate:
needs: test
runs-on: ubuntu-latest
if: always()
steps:
- name: Download test results
uses: actions/download-artifact@v4
with:
pattern: test-results-*
merge-multiple: true

- name: Merge test results
run: |
# Ensure we start with an empty file
echo "" > test.json
# Merge all test result files
for f in test.*.json; do
cat "$f" >> test.json
done
- name: Annotate tests
uses: guyarb/[email protected]
with:
test-results: test.json
28 changes: 28 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: golangci-lint

on:
push:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: ./.github/workflows/go-setup.yml

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: release

on:
push:
Expand All @@ -18,9 +18,7 @@ jobs:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
uses: ./.github/workflows/go-setup.yml

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
Expand Down
4 changes: 0 additions & 4 deletions cmd/cli/commands/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ func startContributoor(c *cli.Context, opts *options.CommandOpts) error {

configService, err := service.NewConfigService(log, c.GlobalString("config-path"))
if err != nil {
if _, ok := err.(*service.ConfigNotFoundError); ok {
return fmt.Errorf("%s%v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

return fmt.Errorf("%sError loading config: %v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

Expand Down
4 changes: 0 additions & 4 deletions cmd/cli/commands/stop/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ func stopContributoor(c *cli.Context, opts *options.CommandOpts) error {

configService, err := service.NewConfigService(log, c.GlobalString("config-path"))
if err != nil {
if _, ok := err.(*service.ConfigNotFoundError); ok {
return fmt.Errorf("%s%v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

return fmt.Errorf("%sError loading config: %v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

Expand Down
4 changes: 0 additions & 4 deletions cmd/cli/commands/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ func updateContributoor(c *cli.Context, opts *options.CommandOpts) error {

configService, err := service.NewConfigService(log, c.GlobalString("config-path"))
if err != nil {
if _, ok := err.(*service.ConfigNotFoundError); ok {
return fmt.Errorf("%s%v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

return fmt.Errorf("%sError loading config: %v%s", tui.TerminalColorRed, err, tui.TerminalColorReset)
}

Expand Down
13 changes: 1 addition & 12 deletions internal/service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ type ConfigService struct {
config *ContributoorConfig
}

// ConfigNotFoundError is an error that occurs when the file config is not found.
type ConfigNotFoundError struct {
Path string
}

// Error returns the error message.
func (e *ConfigNotFoundError) Error() string {
return fmt.Sprintf("Config file not found at [%s]. Please run 'contributoor install' first", e.Path)
}

// NewConfigService creates a new ConfigService.
func NewConfigService(logger *logrus.Logger, configPath string) (*ConfigService, error) {
// Expand home directory
Expand All @@ -84,7 +74,7 @@ func NewConfigService(logger *logrus.Logger, configPath string) (*ConfigService,

// Check if config exists
if _, serr := os.Stat(fullConfigPath); os.IsNotExist(serr) {
return nil, &ConfigNotFoundError{Path: fullConfigPath}
return nil, fmt.Errorf("config file not found at [%s]. Please run 'contributoor install' first", fullConfigPath)
}

// Load existing config
Expand Down Expand Up @@ -239,7 +229,6 @@ func mergeConfig(target, source *ContributoorConfig) error {
}

// migrateConfig handles version-specific migrations.

func migrateConfig(target, source *ContributoorConfig) error {
/*
switch source.Version {
Expand Down

0 comments on commit cd0142e

Please sign in to comment.