-
Notifications
You must be signed in to change notification settings - Fork 0
322 lines (284 loc) · 11.2 KB
/
release.yml
File metadata and controls
322 lines (284 loc) · 11.2 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
name: Release
on:
push:
tags:
- 'v*'
workflow_call:
inputs:
version:
description: 'Version to release (e.g., v1.0.0)'
required: false
default: 'v0.1.0-dev'
type: string
create_release:
description: 'Create GitHub release'
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v1.0.0)'
required: false
default: 'v0.1.0-dev'
type: string
create_release:
description: 'Create GitHub release'
required: false
default: false
type: boolean
env:
GO_VERSION: '1.24' # Using Go 1.24 to match go.mod requirement
jobs:
setup:
name: Setup Release Info
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
create_release: ${{ steps.version.outputs.create_release }}
is_tag: ${{ steps.version.outputs.is_tag }}
steps:
- name: Determine version and release type
id: version
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/v* ]]; then
# Tagged release
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "create_release=true" >> $GITHUB_OUTPUT
echo "is_tag=true" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# Manual dispatch
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
echo "create_release=${{ github.event.inputs.create_release }}" >> $GITHUB_OUTPUT
echo "is_tag=false" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "workflow_call" ]]; then
# Called from another workflow (CI success)
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
echo "create_release=${{ inputs.create_release }}" >> $GITHUB_OUTPUT
echo "is_tag=false" >> $GITHUB_OUTPUT
else
# Default
echo "version=v0.1.0-dev" >> $GITHUB_OUTPUT
echo "create_release=false" >> $GITHUB_OUTPUT
echo "is_tag=false" >> $GITHUB_OUTPUT
fi
test:
name: Test Before Release
runs-on: ubuntu-latest
needs: [setup]
# Skip tests for CI-triggered releases (tests already passed in CI)
if: github.event_name != 'workflow_call'
steps:
- uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Run tests
run: make test
- name: Run integration tests
run: |
# Set up kind cluster
go install sigs.k8s.io/kind@latest
kind create cluster --name release-test --wait 60s
# Create a simple test pod that should be healthy (using alpine - smaller and faster)
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: release-test-pod
namespace: default
spec:
containers:
- name: test-container
image: alpine:latest
command: ["sleep", "300"]
resources:
requests:
cpu: 10m
memory: 16Mi
restartPolicy: Never
EOF
# Check pod status for debugging
echo "Checking pod status..."
kubectl get pods
kubectl describe pod release-test-pod
# Wait for pod to be ready with more time and better error handling
echo "Waiting for pod to be ready..."
if ! kubectl wait --for=condition=Ready pod/release-test-pod --timeout=120s; then
echo "Pod failed to become ready, debugging..."
kubectl get pods -o wide
kubectl describe pod release-test-pod
kubectl logs release-test-pod || echo "No logs available"
echo "Continuing with available pod state for testing..."
fi
# Build kdebug binary
echo "Building kdebug..."
go build -o kdebug .
# Test kdebug with the pod (should work even if pod is not fully ready)
echo "Testing kdebug pod diagnostics..."
export KUBECONFIG=$HOME/.kube/config
./kdebug pod release-test-pod || echo "Pod diagnostics completed (exit code $?)"
# Test cluster diagnostics (should succeed)
echo "Testing kdebug cluster diagnostics..."
./kdebug cluster || echo "Cluster diagnostics completed (exit code $?)"
# Cleanup
echo "Cleaning up..."
kubectl delete pod release-test-pod --ignore-not-found=true
kind delete cluster --name release-test
release:
name: Create Release
runs-on: ubuntu-latest
needs: [setup, test]
# Always run if setup passes, test job may be skipped for CI-triggered releases
if: always() && needs.setup.result == 'success' && (needs.test.result == 'success' || needs.test.result == 'skipped')
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Build cross-platform binaries
run: |
# Update version in Makefile
sed -i "s/VERSION=0.1.0-dev/VERSION=${{ needs.setup.outputs.version }}/g" Makefile
make build-all
- name: Create checksums
run: |
cd bin
sha256sum * > checksums.txt
- name: Generate changelog
id: changelog
run: |
if [ -f CHANGELOG.md ]; then
# Extract changelog for this version
awk '/^## \[${{ needs.setup.outputs.version }}\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md > release_notes.md
else
echo "Release ${{ needs.setup.outputs.version }}" > release_notes.md
echo "" >> release_notes.md
echo "### Changes" >> release_notes.md
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD^)..HEAD >> release_notes.md
fi
- name: Create GitHub Release
if: needs.setup.outputs.create_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.setup.outputs.version }}
name: Release ${{ needs.setup.outputs.version }}
body_path: release_notes.md
files: |
bin/kdebug-*
bin/checksums.txt
draft: false
prerelease: ${{ contains(needs.setup.outputs.version, 'rc') || contains(needs.setup.outputs.version, 'beta') || contains(needs.setup.outputs.version, 'alpha') }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/kdebug
tags: |
type=raw,value=${{ needs.setup.outputs.version }}
type=raw,value=latest,enable=${{ needs.setup.outputs.is_tag == 'true' }}
type=semver,pattern={{version}},value=${{ needs.setup.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.setup.outputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ needs.setup.outputs.version }}
- name: Update Homebrew Formula
if: ${{ !contains(needs.setup.outputs.version, 'rc') && !contains(needs.setup.outputs.version, 'beta') && !contains(needs.setup.outputs.version, 'alpha') }}
env:
HOMEBREW_REPO_TOKEN: ${{ secrets.HOMEBREW_REPO_TOKEN }}
run: |
# Get the SHA256 hashes for the Darwin binaries
DARWIN_AMD64_SHA=$(curl -sL https://github.com/timkrebs/kdebug/releases/download/${{ needs.setup.outputs.version }}/checksums.txt | grep kdebug-darwin-amd64 | cut -d' ' -f1)
DARWIN_ARM64_SHA=$(curl -sL https://github.com/timkrebs/kdebug/releases/download/${{ needs.setup.outputs.version }}/checksums.txt | grep kdebug-darwin-arm64 | cut -d' ' -f1)
# Clone the homebrew tap repository with PAT authentication
git clone https://x-access-token:${{ secrets.HOMEBREW_REPO_TOKEN }}@github.com/timkrebs/homebrew-kdebug.git /tmp/homebrew-kdebug
cd /tmp/homebrew-kdebug
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Update the formula with new version and checksums
cat > Formula/kdebug.rb << EOF
class Kdebug < Formula
desc "CLI tool that automatically diagnoses common Kubernetes issues and provides actionable suggestions"
homepage "https://github.com/timkrebs/kdebug"
version "${{ needs.setup.outputs.version }}"
license "MIT"
on_macos do
if Hardware::CPU.intel?
url "https://github.com/timkrebs/kdebug/releases/download/${{ needs.setup.outputs.version }}/kdebug-darwin-amd64"
sha256 "${DARWIN_AMD64_SHA}"
def install
bin.install "kdebug-darwin-amd64" => "kdebug"
end
end
if Hardware::CPU.arm?
url "https://github.com/timkrebs/kdebug/releases/download/${{ needs.setup.outputs.version }}/kdebug-darwin-arm64"
sha256 "${DARWIN_ARM64_SHA}"
def install
bin.install "kdebug-darwin-arm64" => "kdebug"
end
end
end
def caveats
<<~EOS
kdebug is a Kubernetes debugging tool. Make sure you have:
- kubectl installed and configured
- Access to a Kubernetes cluster
Get started with:
kdebug pod --help
kdebug cluster --help
EOS
end
test do
system "#{bin}/kdebug", "--version"
system "#{bin}/kdebug", "--help"
end
end
EOF
# Commit and push the updated formula
git add Formula/kdebug.rb
if git diff --cached --quiet; then
echo "No changes to homebrew formula"
else
git commit -m "Update kdebug to ${{ needs.setup.outputs.version }}"
git push origin main
echo "✅ Updated Homebrew formula to ${{ needs.setup.outputs.version }}"
fi
notify:
name: Notify Release
runs-on: ubuntu-latest
needs: [release]
if: always()
steps:
- name: Notify on success
if: needs.release.result == 'success'
run: |
echo "✅ Release ${{ github.ref_name }} was successful!"
# Add notification logic here (Slack, Discord, etc.)
- name: Notify on failure
if: needs.release.result == 'failure'
run: |
echo "❌ Release ${{ github.ref_name }} failed!"
# Add notification logic here (Slack, Discord, etc.)