fix: Delete the env errors #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go CI/CD | |
on: | |
push: | |
branches: [ main ] | |
tags: | |
- 'v0.[1-9][0-9]*.[0-9]+' # Matches v0.1.0, v0.2.0, v0.10.0, etc. | |
- 'v0.[1-9][0-9]*.[0-9]+[0-9]' # Also matches v0.1.10, v0.2.23, etc. | |
pull_request: | |
branches: [ main ] | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
test: | |
name: Test & Lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
cache: true | |
- name: Install dependencies | |
run: | | |
go mod download | |
go install golang.org/x/tools/cmd/goimports@latest | |
- name: Run tests | |
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... | |
- name: Run golangci-lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
version: latest | |
args: --timeout=5m --out-format=colored-line-number --issues-exit-code=1 | |
only-new-issues: true | |
skip-pkg-cache: true | |
skip-build-cache: false | |
- name: Upload coverage | |
if: success() | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ./coverage.txt | |
fail_ci_if_error: false | |
verbose: true | |
build: | |
name: Build Binary | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
cache: true | |
- name: Build | |
run: | | |
VERSION=$(git describe --tags --always --dirty) | |
mkdir -p hapax | |
go build -v -ldflags="-X main.Version=${VERSION}" -o hapax/hapax . | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: hapax-binary | |
path: ./hapax | |
retention-days: 5 | |
release: | |
name: Create Release | |
needs: [test, build] | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate changelog | |
id: changelog | |
run: | | |
echo "CHANGELOG<<EOF" >> $GITHUB_ENV | |
echo "## What's Changed" >> $GITHUB_ENV | |
echo "" >> $GITHUB_ENV | |
# Features | |
echo "### Features" >> $GITHUB_ENV | |
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^feat' | sed 's/feat: /* /' >> $GITHUB_ENV || true | |
# Fixes | |
echo "" >> $GITHUB_ENV | |
echo "### Fixes" >> $GITHUB_ENV | |
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^fix' | sed 's/fix: /* /' >> $GITHUB_ENV || true | |
# Documentation | |
echo "" >> $GITHUB_ENV | |
echo "### Documentation" >> $GITHUB_ENV | |
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^docs' | sed 's/docs: /* /' >> $GITHUB_ENV || true | |
# Performance | |
echo "" >> $GITHUB_ENV | |
echo "### Performance Improvements" >> $GITHUB_ENV | |
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^perf' | sed 's/perf: /* /' >> $GITHUB_ENV || true | |
echo "EOF" >> $GITHUB_ENV | |
- name: Download binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: hapax-binary | |
path: ./ | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
body: ${{ env.CHANGELOG }} | |
files: ./hapax/hapax | |
draft: false | |
prerelease: false | |
generate_release_notes: true |