Skip to content

Commit

Permalink
ci: Add GitHub Actions workflow for CI/CD with automated testing, bui…
Browse files Browse the repository at this point in the history
…lding, and release generation
  • Loading branch information
aronchick committed Nov 29, 2024
1 parent d209697 commit ed46875
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI/CD Pipeline

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

permissions:
contents: write
packages: write

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Install Just
uses: extractions/setup-just@v2
- name: Run Tests
run: just test

build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Install Just
uses: extractions/setup-just@v2
- name: Build
run: just build

release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [test, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Install Just
uses: extractions/setup-just@v2

- name: Generate Release Notes
id: release-notes
run: |
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^)
# Generate changelog
CHANGELOG=$(git log $PREVIOUS_TAG..HEAD --pretty=format:"- %s" --no-merges)
# Escape multiline output for GitHub Actions
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
echo "changelog=$CHANGELOG" >> $GITHUB_OUTPUT
- name: Build Release Artifacts
run: just build-release

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
dist/andaime_*
body: |
## Changelog
${{ steps.release-notes.outputs.changelog }}
draft: false
prerelease: false
18 changes: 17 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@ genmock:

# Generate cloud data
gencloud:
@go run ./internal/generate_cloud_data.go
@go run ./internal/generate_cloud_data.go

# Run tests
test:
go test ./...

# Build binary
build:
go build -o andaime ./cmd/andaime

# Build release artifacts for multiple platforms
build-release:
mkdir -p dist
GOOS=linux GOARCH=amd64 go build -o dist/andaime_linux_amd64 ./cmd/andaime
GOOS=darwin GOARCH=amd64 go build -o dist/andaime_darwin_amd64 ./cmd/andaime
GOOS=darwin GOARCH=arm64 go build -o dist/andaime_darwin_arm64 ./cmd/andaime
GOOS=windows GOARCH=amd64 go build -o dist/andaime_windows_amd64.exe ./cmd/andaime

0 comments on commit ed46875

Please sign in to comment.