-
Notifications
You must be signed in to change notification settings - Fork 1
218 lines (189 loc) · 7.84 KB
/
Copy pathrelease.yml
File metadata and controls
218 lines (189 loc) · 7.84 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: Release
on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-*'
workflow_dispatch:
permissions:
contents: write
packages: write
env:
GO_VERSION: '1.24'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run Tests
run: |
go test -v -race -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
- name: Upload Coverage
uses: codecov/codecov-action@v5
with:
files: ./coverage.out
flags: unittests
name: codecov-umbrella
build-and-release:
name: Build & Release
runs-on: ubuntu-latest
if: always() && startsWith(github.ref, 'refs/tags/')
needs: test
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Extract Version Info
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
GIT_COMMIT=$(git rev-parse HEAD)
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S_UTC')
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "git_commit=${GIT_COMMIT}" >> $GITHUB_OUTPUT
echo "build_time=${BUILD_TIME}" >> $GITHUB_OUTPUT
echo "is_prerelease=$([[ $VERSION == *-* ]] && echo true || echo false)" >> $GITHUB_OUTPUT
- name: Build Binaries
env:
CGO_ENABLED: 0
run: |
mkdir -p dist
LDFLAGS="-s -w \
-X github.com/valpere/shopogoda/internal/version.Version=${{ steps.version.outputs.version }} \
-X github.com/valpere/shopogoda/internal/version.GitCommit=${{ steps.version.outputs.git_commit }} \
-X github.com/valpere/shopogoda/internal/version.BuildTime=${{ steps.version.outputs.build_time }}"
GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/shopogoda-linux-amd64 ./cmd/bot
GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o dist/shopogoda-linux-arm64 ./cmd/bot
GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/shopogoda-darwin-amd64 ./cmd/bot
GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o dist/shopogoda-darwin-arm64 ./cmd/bot
GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/shopogoda-windows-amd64.exe ./cmd/bot
- name: Create Checksums
run: |
cd dist
sha256sum shopogoda-* > checksums.txt
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker Metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha,prefix={{branch}}-
- name: Build and Push Docker Image
uses: docker/build-push-action@v7
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ steps.version.outputs.version }}
GIT_COMMIT=${{ steps.version.outputs.git_commit }}
BUILD_TIME=${{ steps.version.outputs.build_time }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate Changelog
id: changelog
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "🎉 Initial release of ShoPogoda Weather Bot" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details." >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "## Changes since ${PREVIOUS_TAG}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const version = '${{ steps.version.outputs.version }}';
const isPrerelease = ${{ steps.version.outputs.is_prerelease }};
const changelog = `${{ steps.changelog.outputs.changelog }}`;
const repository = '${{ github.repository }}';
// Create release body
const dockerCmd = 'docker pull ghcr.io/' + repository + ':' + version.replace('v', '');
const installSection = '\n\n## 📦 Installation\n\n' +
'### Docker\n```bash\n' + dockerCmd + '\n```\n\n' +
'### Binary Download\n' +
'Download the binary for your platform from the assets below and run:\n' +
'```bash\nchmod +x shopogoda-*\n./shopogoda-*\n```\n\n' +
'### Quick Start\n' +
'See [DEMO_SETUP.md](https://github.com/' + repository + '/blob/main/docs/DEMO_SETUP.md) for complete setup instructions.\n\n' +
'## 📊 Checksums\n' +
'See `checksums.txt` asset for SHA256 checksums of all binaries.\n\n' +
'## 🐛 Bug Reports\n' +
'Report issues at https://github.com/' + repository + '/issues\n';
const releaseBody = changelog + installSection;
// Create the release
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: version,
name: `ShoPogoda ${version}`,
body: releaseBody,
draft: false,
prerelease: isPrerelease,
generate_release_notes: false
});
console.log(`✅ Created release: ${release.data.html_url}`);
// Upload binaries
const files = [
'dist/shopogoda-linux-amd64',
'dist/shopogoda-linux-arm64',
'dist/shopogoda-darwin-amd64',
'dist/shopogoda-darwin-arm64',
'dist/shopogoda-windows-amd64.exe',
'dist/checksums.txt'
];
for (const filepath of files) {
const filename = filepath.split('/').pop();
console.log(`Uploading ${filename}...`);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: filename,
data: fs.readFileSync(filepath)
});
}
console.log('✅ All assets uploaded');