Skip to content
Merged
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
Binary file added .github/dave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: PR Tests

on:
pull_request:
branches:
- main

permissions:
contents: read
pull-requests: write

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'

- name: Download dependencies
run: go mod download

- name: Run tests
id: test
run: |
go test -v ./tests/... 2>&1 | tee test-output.txt
echo "test_exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT

- name: Comment PR with test results
uses: actions/github-script@v7
if: always()
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const testOutput = fs.readFileSync('test-output.txt', 'utf8');
const testPassed = ${{ steps.test.outputs.test_exit_code }} === 0;

const emoji = testPassed ? '✅' : '❌';
const status = testPassed ? 'PASSED' : 'FAILED';

const body = `## ${emoji} Test Results: ${status}

<details>
<summary>Test Output</summary>

\`\`\`
${testOutput}
\`\`\`

</details>`;

await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});

- name: Fail if tests failed
if: steps.test.outputs.test_exit_code != '0'
run: exit 1
203 changes: 203 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
name: Build and Release

on:
push:
branches:
- main

permissions:
contents: write

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'

- name: Download dependencies
run: go mod download

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

version:
name: Calculate Version
runs-on: ubuntu-latest
needs: test
outputs:
new_version: ${{ steps.version.outputs.new_version }}
changelog: ${{ steps.version.outputs.changelog }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Get latest tag
id: get_tag
run: |
# Get the latest tag, or use v0.0.0 if no tags exist
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG"

- name: Calculate new version
id: version
run: |
LATEST_TAG="${{ steps.get_tag.outputs.latest_tag }}"

# Remove 'v' prefix
VERSION=${LATEST_TAG#v}

# Split version into parts
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}

# Get commit messages since last tag
if [ "$LATEST_TAG" = "v0.0.0" ]; then
COMMITS=$(git log --pretty=format:"%s")
else
COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%s")
fi

echo "Commits since last tag:"
echo "$COMMITS"

# Check for breaking changes (MAJOR)
if echo "$COMMITS" | grep -qiE "BREAKING CHANGE|major:"; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
BUMP_TYPE="major"
# Check for features (MINOR)
elif echo "$COMMITS" | grep -qiE "^feat|^feature|minor:"; then
MINOR=$((MINOR + 1))
PATCH=0
BUMP_TYPE="minor"
# Default to PATCH
else
PATCH=$((PATCH + 1))
BUMP_TYPE="patch"
fi

NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION (${BUMP_TYPE} bump)"

# Generate changelog
CHANGELOG="## Changes in $NEW_VERSION\n\n"
if [ "$LATEST_TAG" = "v0.0.0" ]; then
CHANGELOG+="Initial release\n\n"
CHANGELOG+=$(git log --pretty=format:"- %s (%h)" | head -20)
else
CHANGELOG+=$(git log ${LATEST_TAG}..HEAD --pretty=format:"- %s (%h)")
fi

echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo -e "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

build:
name: Build Binaries
runs-on: ubuntu-latest
needs: version
strategy:
matrix:
include:
# Windows
- goos: windows
goarch: amd64
output: dave-windows-amd64.exe
- goos: windows
goarch: arm64
output: dave-windows-arm64.exe

# macOS
- goos: darwin
goarch: amd64
output: dave-macos-amd64
- goos: darwin
goarch: arm64
output: dave-macos-arm64

# Linux
- goos: linux
goarch: amd64
output: dave-linux-amd64
- goos: linux
goarch: arm64
output: dave-linux-arm64
- goos: linux
goarch: 386
output: dave-linux-386

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'

- name: Download dependencies
run: go mod download

- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION="${{ needs.version.outputs.new_version }}"
go build -ldflags "-s -w -X main.Version=${VERSION}" -o ${{ matrix.output }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.output }}
path: ${{ matrix.output }}

release:
name: Create Release
runs-on: ubuntu-latest
needs: [version, build]
steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./binaries

- name: Display structure of downloaded files
run: ls -R ./binaries

- name: Prepare release assets
run: |
mkdir -p release
find ./binaries -type f -exec cp {} ./release/ \;
ls -lh ./release

- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.new_version }}
name: Release ${{ needs.version.outputs.new_version }}
body: ${{ needs.version.outputs.changelog }}
files: ./release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading