-
Notifications
You must be signed in to change notification settings - Fork 3
139 lines (119 loc) · 4.11 KB
/
Copy pathrelease.yaml
File metadata and controls
139 lines (119 loc) · 4.11 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Publish Release
on:
push:
tags:
- 'v*.*.*'
- '!v*.*.*-*' # Exclude pre-releases
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., v1.0.0)'
required: true
type: string
jobs:
determine-version:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ env.VERSION }}
changelog_body: ${{ env.CHANGELOG_BODY }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Extract version from tag
id: get_version
run: |
# Get version from tag (either from push event or manual input)
if [ "${{ github.event_name }}" = "push" ]; then
VERSION="${{ github.ref_name }}"
else
VERSION="${{ inputs.tag }}"
fi
# Validate version format using make target
make validate-release-tag VERSION="$VERSION"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "Release version: $VERSION"
- name: Validate CHANGELOG has version section
run: make validate-changelog-has-version VERSION="${{ env.VERSION }}"
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- name: Extract changelog for release
id: changelog
run: |
VERSION="${{ env.VERSION }}"
# Extract the specific version section from CHANGELOG.md using make target
CHANGELOG_CONTENT=$(make extract-changelog-version VERSION="$VERSION")
# Save to environment variable, handling multiline content
{
echo 'CHANGELOG_BODY<<EOF'
echo "$CHANGELOG_CONTENT"
echo 'EOF'
} >> "$GITHUB_ENV"
- name: Run tests
run: make test
- name: Create or update release
run: |
VERSION="${{ env.VERSION }}"
# Check if release already exists
if gh release view "$VERSION" >/dev/null 2>&1; then
echo "Release $VERSION already exists, checking if changelog needs to be updated..."
# Get current release notes
CURRENT_NOTES=$(gh release view "$VERSION" --json body -q .body)
# Check if changelog content is already in the notes
if echo "$CURRENT_NOTES" | grep -qF "${{ env.CHANGELOG_BODY }}"; then
echo "Changelog already present in release notes, skipping update..."
else
echo "Appending changelog to existing release notes..."
NEW_NOTES="${CURRENT_NOTES}\n\n---\n\n${{ env.CHANGELOG_BODY }}"
gh release edit "$VERSION" --notes "$NEW_NOTES"
fi
else
echo "Creating release $VERSION..."
gh release create "$VERSION" \
--title "$VERSION" \
--notes "${{ env.CHANGELOG_BODY }}" \
--latest
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-upload:
needs: determine-version
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write # Permission for keyless signing
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- name: Install cosign
uses: sigstore/cosign-installer@v4.0.0
- name: Build release artifacts
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ needs.determine-version.outputs.version }}
run: make build-release package-release
- name: Sign release artifacts
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: make sign-release
- name: Upload assets to release
run: make upload-release-assets VERSION="${{ needs.determine-version.outputs.version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}