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
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Description

<!-- Provide a clear description of what this PR does and why it's needed -->

## Type of Change

<!-- Mark the relevant option with an 'x' -->

- [ ] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] 📝 Documentation update
- [ ] ♻️ Refactoring (no functional changes)
- [ ] 🔧 Other (please describe):

## Additional Notes

<!-- Add any additional context, screenshots, or notes for reviewers -->

93 changes: 93 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# GitHub Actions Workflows

This directory contains reusable workflows for Go projects.

## Features

- ✅ **Test Results as Artifacts**: Downloadable from workflow run summary
- ✅ **PR Comments**: Test summary posted directly in PR comments
- ✅ **Check Annotations**: Failed tests appear as annotations in the PR checks
- ✅ **Path Filtering**: Only runs when Go files change
- ✅ **Skip CI Support**: Respects `[skip-ci]` flag
- ✅ **Private Module Support**: Configured for private Go modules

## Test Results in Pull Requests

### Artifacts vs Comments

**GitHub Actions Limitations:**
- Unlike GitLab, GitHub Actions **cannot** display artifacts directly inline in PRs
- Artifacts are stored separately and must be downloaded from the workflow run summary
- The standard approach for showing test results in GitHub PRs is through **PR comments** and **check annotations**

**Our Solution:**
We use a **dual approach**:
1. **Artifacts**: Test results are uploaded as artifacts for downloadability and archival
2. **PR Comments**: Test results are posted as comments on PRs using `dorny/test-reporter` action

### How to Use in Other Repositories

1. **Copy the workflow** to your repository:
```bash
cp .github/workflows/test.yml /path/to/repo/.github/workflows/test.yml
```

2. **Customize as needed**:
- Adjust `GOPRIVATE` environment variable if needed
- Modify test command if you need coverage or specific test flags
- Add/remove path filters in the `on:` section
- Adjust timeout values

3. **Ensure permissions** are set correctly:
```yaml
permissions:
contents: read
checks: write
pull-requests: write
```

4. **For private modules**, ensure `GH_ACCESS_TOKEN` secret is configured in your repository settings.

### Features

- ✅ **Test Results as Artifacts**: Downloadable from workflow run summary
- ✅ **PR Comments**: Test summary posted directly in PR comments
- ✅ **Check Annotations**: Failed tests appear as annotations in the PR checks
- ✅ **Generic & Reusable**: Works across all Go repositories
- ✅ **Path Filtering**: Only runs when relevant files change
- ✅ **Skip CI Support**: Respects `[skip-ci]` flag

### Example Output

When tests run, you'll see:
- **In PR Comments**: A formatted test summary with pass/fail counts
- **In PR Checks**: Individual test failures as annotations
- **In Artifacts**: Downloadable `test-results.xml` file

### Customization Examples

**Add coverage:**
```yaml
- name: Run tests with coverage
run: |
gotestsum --junitfile test-results.xml --format standard-verbose -coverprofile=coverage.out ./...
```

**Test specific packages:**
```yaml
- name: Run tests
run: |
gotestsum --junitfile test-results.xml --format standard-verbose ./pkg/... ./cmd/...
```

**Add custom paths:**
```yaml
on:
push:
paths:
- '**/*.go'
- 'go.mod'
- 'go.sum'
- '.github/**' # Add this to trigger on workflow changes
```

44 changes: 44 additions & 0 deletions .github/workflows/SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Quick Setup Guide

## Copy Test Workflow to Other Repositories

Run this command from the `magic` repository root:

```bash
# For base repository
cp .github/workflows/test.yml ../source/base/.github/workflows/test.yml

# For ledge repository
cp .github/workflows/test.yml ../source/ledge/.github/workflows/test.yml

# For flow repository
cp .github/workflows/test.yml ../source/flow/.github/workflows/test.yml

# For wire repository
cp .github/workflows/test.yml ../source/wire/.github/workflows/test.yml

# For imagine repository
cp .github/workflows/test.yml ../source/imagine/.github/workflows/test.yml

# For matchblox repository
cp .github/workflows/test.yml ../source/matchblox/.github/workflows/test.yml

# For profile repository
cp .github/workflows/test.yml ../source/profile/.github/workflows/test.yml
```

## After Copying

1. **Review the workflow file** - Ensure paths and configurations match your repository
2. **Check permissions** - Verify the workflow has `pull-requests: write` permission
3. **Test it** - Create a test PR to verify test results appear correctly
4. **Remove old test steps** - If updating existing workflows, remove duplicate test steps

## What You Get

- ✅ Test results posted as PR comments
- ✅ Test results uploaded as downloadable artifacts
- ✅ Failed tests shown as check annotations
- ✅ Only runs when Go files change
- ✅ Respects `[skip-ci]` flag

48 changes: 36 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ defaults:
run:
shell: bash

permissions:
contents: read
checks: write
pull-requests: write

jobs:
conventional-commits:
name: Conventional Commits Check
Expand All @@ -37,38 +42,57 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest
needs: conventional-commits
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-go@v5
with:
go-version: '1.22.4'
go-version: '1.24.3'
cache: true
- name: golangci-lint
- name: Lint
uses: golangci/golangci-lint-action@v3
continue-on-error: true
with:
version: latest
only-new-issues: true
args: --timeout=5m
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true

test:
name: Test
runs-on: ubuntu-latest
needs: lint
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-go@v5
with:
go-version: '1.22.4'
go-version: '1.24.3'
cache: true
- name: Run tests
run: go test -v -cover ./...
- name: Install gotestsum
run: |
go install gotest.tools/gotestsum@latest
- name: Run tests with JUnit XML output
id: test
continue-on-error: true
run: |
gotestsum --junitfile test-results.xml --format standard-verbose ./... || true
- name: Upload test results as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ github.run_number }}
path: test-results.xml
retention-days: 30
- name: Generate test annotations and PR comment
if: always()
uses: dorny/test-reporter@v1
with:
name: Go Test Results
path: test-results.xml
reporter: java-junit
fail-on-error: false
list-suites: all
max-annotations: 50
only-summary: false

99 changes: 99 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Test

on:
push:
branches: [main]
paths:
- '**/*.go'
- 'go.mod'
- 'go.sum'
pull_request:
branches: [main]
paths:
- '**/*.go'
- 'go.mod'
- 'go.sum'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash

# Configure GOPRIVATE if your project uses private Go modules
env:
GOPRIVATE: github.com/blox-eng/*

permissions:
contents: read
checks: write
pull-requests: write

jobs:
changes:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
go: ${{ steps.changes-go.outputs.exists }}
steps:
- uses: yumemi-inc/path-filter@v2
id: changes-go
with:
patterns: '**/*.go'

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10
needs: changes
# Skip CI if [skip-ci] is in commit message or PR title
if: ${{ !contains(github.event.head_commit.message, '[skip-ci]') && !contains(github.event.pull_request.title, '[skip-ci]') && needs.changes.outputs.go == 'true' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Configure git for private modules
if: env.GOPRIVATE != ''
run: |
git config --global url."https://x-access-token:${{ secrets.GH_ACCESS_TOKEN }}@github.com/".insteadOf "https://github.com/"

- uses: actions/setup-go@v5
with:
go-version: '1.24.3'
cache: true

- name: Install gotestsum
run: |
go install gotest.tools/gotestsum@latest

- name: Run tests with JUnit XML output
id: test
continue-on-error: true
# Customize test command here if needed (e.g., add coverage, specific packages, etc.)
run: |
gotestsum --junitfile test-results.xml --format standard-verbose ./... || true

- name: Upload test results as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ github.run_number }}
path: test-results.xml
retention-days: 30

- name: Generate test annotations and PR comment
if: always()
uses: dorny/test-reporter@v1
with:
name: Go Test Results
path: test-results.xml
reporter: java-junit
fail-on-error: false
list-suites: all
max-annotations: 50
only-summary: false

Loading
Loading