Skip to content

ci: consolidate CI and release into single workflow #34

ci: consolidate CI and release into single workflow

ci: consolidate CI and release into single workflow #34

Workflow file for this run

name: CI
on:
push:
branches: ["*"]
tags: ["v*"]
pull_request:
branches: ["*"]
permissions:
contents: read
jobs:
build:
runs-on: ${{ matrix.os }}
name: Build and test
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
go: ["1.23.x", "1.24.x"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Download Dependencies
run: go mod download
- name: Test
run: make test-cover
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.24.x
cache: false # managed by golangci-lint
- uses: golangci/golangci-lint-action@v6
name: Install golangci-lint
with:
version: latest
args: --help # make lint will run the linter
- run: make lint
name: Lint
release:
name: Release
runs-on: ubuntu-latest
needs: [build, lint] # Only run after build and lint pass
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
!contains(github.event.head_commit.message, 'skip ci') &&
!contains(github.event.head_commit.message, 'skip release')
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.24.x
# Configure git to use GitHub Actions bot
- name: Configure Git
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Check for conventional commits
id: check_commits
run: |
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
echo "No previous tag found, checking all commits"
COMMITS=$(git log --pretty=format:"%s")
else
echo "Checking commits since $LAST_TAG"
COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"%s")
fi
# Check if any commits are releasable (feat, fix, or breaking change)
RELEASABLE=false
while IFS= read -r commit; do
if [[ "$commit" =~ ^(feat|fix)(\(.+\))?!?:|BREAKING\ CHANGE: ]] || [[ "$commit" =~ ^[a-z]+(\(.+\))?!: ]]; then
RELEASABLE=true
break
fi
done <<< "$COMMITS"
echo "releasable=$RELEASABLE" >> $GITHUB_OUTPUT
if [ "$RELEASABLE" = "false" ]; then
echo "No releasable changes found. Skipping release."
fi
- name: Conventional Changelog Action
id: changelog
if: steps.check_commits.outputs.releasable == 'true'
uses: TriPSs/conventional-changelog-action@v5.3.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
git-message: |
chore(release): v{version} [skip ci]
- Update changelog
- Bump version
preset: "angular"
tag-prefix: "v"
output-file: "docs/reference/changelog.md"
version-file: "version.json"
skip-on-empty: "true"
skip-version-file: "false"
skip-git-pull: "false"
create-summary: "true"
- name: Create Release
if: |
steps.check_commits.outputs.releasable == 'true' &&
steps.changelog.outputs.skipped == 'false'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.changelog.outputs.tag }}
name: ${{ steps.changelog.outputs.tag }}
body: ${{ steps.changelog.outputs.clean_changelog }}
token: ${{ secrets.GITHUB_TOKEN }}