-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (82 loc) · 3.01 KB
/
Copy pathrelease.yml
File metadata and controls
96 lines (82 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Release Go CLI with GoReleaser
# Workflow-wide environment variables
env:
CLI_NAME: "dg" # Your CLI's name, used in .goreleaser.yaml
on:
push:
branches:
- main
tags:
- "v*" # Trigger on version tags like v1.0.0
permissions:
contents: write # Required to upload assets to the release
issues: write # Required for semantic-release to comment on issues
pull-requests: write # Required for semantic-release to comment on PRs
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24" # Match your project's Go version
cache: true
- name: Install dependencies
run: go mod download
- name: Run tests
run: make test
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: latest
semantic-release:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: 24
extra_plugins: |
conventional-changelog-conventionalcommits@8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
goreleaser:
needs: [test, semantic-release]
if: always() && needs.test.result == 'success' && (needs.semantic-release.outputs.new_release_published == 'true' || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest
steps:
# Checkout the repository with full history
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for changelog generation
ref: ${{ needs.semantic-release.outputs.new_release_version && format('v{0}', needs.semantic-release.outputs.new_release_version) || github.ref }}
# Set up Go environment
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24" # Match your project's Go version
cache: true # Cache Go modules for faster builds
# Run GoReleaser to build and release
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser # Use 'goreleaser-pro' for pro features
version: "~> v2" # Pin to v2.x, or use 'latest'
args: release --clean # Build and publish, clean build dir after
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Auth for GitHub Releases
# Optional: Print release URL (for debugging or logs)
- name: Print Release URL
run: echo "Release published at ${{ github.event.release.html_url }}"