Skip to content

Commit 977df86

Browse files
committed
chore: harden release automation
1 parent 91a00a0 commit 977df86

3 files changed

Lines changed: 91 additions & 37 deletions

File tree

.github/release-please-config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"release-type": "go",
66
"package-name": "kubernetes-impulse",
77
"include-component-in-tag": false,
8+
"extra-files": [
9+
{
10+
"type": "generic",
11+
"path": "Impulse.yaml"
12+
}
13+
],
814
"changelog-sections": [
915
{
1016
"type": "feat",

.github/workflows/release-please.yml

Lines changed: 83 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ on:
44
push:
55
branches:
66
- main
7+
workflow_dispatch:
8+
inputs:
9+
tag_name:
10+
description: Existing release tag to publish (for example `v0.1.0`)
11+
required: false
12+
type: string
713

814
permissions:
915
contents: write
@@ -20,63 +26,105 @@ env:
2026
jobs:
2127
release-please:
2228
runs-on: ubuntu-latest
23-
outputs:
24-
release_created: ${{ steps.release.outputs.release_created }}
25-
tag_name: ${{ steps.release.outputs.tag_name }}
2629
steps:
2730
- name: Release Please
31+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.tag_name == '' }}
2832
id: release
2933
uses: googleapis/release-please-action@v4
3034
with:
3135
config-file: .github/release-please-config.json
3236
manifest-file: .github/.release-please-manifest.json
3337

34-
- name: Checkout code
35-
if: ${{ steps.release.outputs.release_created }}
38+
- name: Checkout workflow source
3639
uses: actions/checkout@v6
3740

38-
- name: Set up Go
39-
if: ${{ steps.release.outputs.release_created }}
40-
uses: actions/setup-go@v6
41-
with:
42-
go-version-file: go.mod
43-
check-latest: true
44-
cache: true
45-
cache-dependency-path: go.sum
46-
47-
- name: Run lint and tests
48-
if: ${{ steps.release.outputs.release_created }}
41+
- name: Detect release context
42+
id: publish
43+
env:
44+
GH_TOKEN: ${{ github.token }}
4945
run: |
50-
make lint
51-
make test
46+
set -euo pipefail
47+
48+
manual_tag="${{ github.event.inputs.tag_name }}"
49+
if [ -n "${manual_tag}" ]; then
50+
release_json="$(gh release view "${manual_tag}" --json targetCommitish,url 2>/dev/null || true)"
51+
if [ -z "${release_json}" ]; then
52+
echo "Release ${manual_tag} not found" >&2
53+
exit 1
54+
fi
55+
56+
echo "publish=true" >> "$GITHUB_OUTPUT"
57+
echo "tag_name=${manual_tag}" >> "$GITHUB_OUTPUT"
58+
echo "release_url=$(printf '%s' "${release_json}" | jq -r '.url')" >> "$GITHUB_OUTPUT"
59+
echo "checkout_ref=${manual_tag}" >> "$GITHUB_OUTPUT"
60+
exit 0
61+
fi
62+
63+
if [ "${{ steps.release.outputs.release_created }}" = "true" ]; then
64+
echo "publish=true" >> "$GITHUB_OUTPUT"
65+
echo "tag_name=${{ steps.release.outputs.tag_name }}" >> "$GITHUB_OUTPUT"
66+
echo "release_url=${{ steps.release.outputs.html_url }}" >> "$GITHUB_OUTPUT"
67+
echo "checkout_ref=${{ steps.release.outputs.tag_name }}" >> "$GITHUB_OUTPUT"
68+
exit 0
69+
fi
70+
71+
version="$(jq -r '."."' .github/.release-please-manifest.json)"
72+
if [ -z "${version}" ] || [ "${version}" = "null" ]; then
73+
echo "publish=false" >> "$GITHUB_OUTPUT"
74+
exit 0
75+
fi
76+
77+
tag_name="v${version}"
78+
release_json="$(gh release view "${tag_name}" --json targetCommitish,url 2>/dev/null || true)"
79+
if [ -z "${release_json}" ]; then
80+
echo "publish=false" >> "$GITHUB_OUTPUT"
81+
exit 0
82+
fi
83+
84+
target_commitish="$(printf '%s' "${release_json}" | jq -r '.targetCommitish')"
85+
if [ "${target_commitish}" != "${GITHUB_SHA}" ]; then
86+
echo "publish=false" >> "$GITHUB_OUTPUT"
87+
exit 0
88+
fi
89+
90+
echo "publish=true" >> "$GITHUB_OUTPUT"
91+
echo "tag_name=${tag_name}" >> "$GITHUB_OUTPUT"
92+
echo "release_url=$(printf '%s' "${release_json}" | jq -r '.url')" >> "$GITHUB_OUTPUT"
93+
echo "checkout_ref=${tag_name}" >> "$GITHUB_OUTPUT"
94+
95+
- name: Checkout release source
96+
if: ${{ steps.publish.outputs.publish == 'true' }}
97+
uses: actions/checkout@v6
98+
with:
99+
ref: ${{ steps.publish.outputs.checkout_ref }}
52100

53101
- name: Set up Docker Buildx
54-
if: ${{ steps.release.outputs.release_created }}
102+
if: ${{ steps.publish.outputs.publish == 'true' }}
55103
uses: docker/setup-buildx-action@v4
56104

57105
- name: Log in to GitHub Container Registry
58-
if: ${{ steps.release.outputs.release_created }}
106+
if: ${{ steps.publish.outputs.publish == 'true' }}
59107
uses: docker/login-action@v4
60108
with:
61109
registry: ghcr.io
62110
username: ${{ github.actor }}
63111
password: ${{ secrets.GITHUB_TOKEN }}
64112

65113
- name: Extract Docker metadata
66-
if: ${{ steps.release.outputs.release_created }}
114+
if: ${{ steps.publish.outputs.publish == 'true' }}
67115
id: meta
68116
uses: docker/metadata-action@v6
69117
with:
70118
images: ${{ env.GHCR_IMAGE }}
71119
tags: |
72-
type=semver,pattern={{version}},value=${{ steps.release.outputs.tag_name }}
73-
type=semver,pattern={{major}}.{{minor}},value=${{ steps.release.outputs.tag_name }}
74-
type=semver,pattern={{major}},value=${{ steps.release.outputs.tag_name }}
75-
type=raw,value=${{ steps.release.outputs.tag_name }}
120+
type=semver,pattern={{version}},value=${{ steps.publish.outputs.tag_name }}
121+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.publish.outputs.tag_name }}
122+
type=semver,pattern={{major}},value=${{ steps.publish.outputs.tag_name }}
123+
type=raw,value=${{ steps.publish.outputs.tag_name }}
76124
type=raw,value=latest
77125
78126
- name: Build and push Docker image
79-
if: ${{ steps.release.outputs.release_created }}
127+
if: ${{ steps.publish.outputs.publish == 'true' }}
80128
uses: docker/build-push-action@v7
81129
with:
82130
context: .
@@ -88,7 +136,7 @@ jobs:
88136
cache-to: type=gha,mode=max
89137

90138
- name: Detect template manifest
91-
if: ${{ steps.release.outputs.release_created }}
139+
if: ${{ steps.publish.outputs.publish == 'true' }}
92140
id: template
93141
run: |
94142
set -euo pipefail
@@ -106,22 +154,22 @@ jobs:
106154
echo "file=${template_file}" >> "$GITHUB_OUTPUT"
107155
echo "kind=${template_kind}" >> "$GITHUB_OUTPUT"
108156
echo "latest_url=https://github.com/${{ github.repository }}/releases/latest/download/${template_file}" >> "$GITHUB_OUTPUT"
109-
echo "versioned_url=https://github.com/${{ github.repository }}/releases/download/${{ steps.release.outputs.tag_name }}/${template_file}" >> "$GITHUB_OUTPUT"
157+
echo "versioned_url=https://github.com/${{ github.repository }}/releases/download/${{ steps.publish.outputs.tag_name }}/${template_file}" >> "$GITHUB_OUTPUT"
110158
111159
- name: Upload template manifest to GitHub release
112-
if: ${{ steps.release.outputs.release_created }}
160+
if: ${{ steps.publish.outputs.publish == 'true' }}
113161
env:
114162
GH_TOKEN: ${{ github.token }}
115-
run: gh release upload "${{ steps.release.outputs.tag_name }}" "${{ steps.template.outputs.file }}" --clobber
163+
run: gh release upload "${{ steps.publish.outputs.tag_name }}" "${{ steps.template.outputs.file }}" --clobber
116164

117165
- name: Summarize release
118-
if: ${{ steps.release.outputs.release_created }}
166+
if: ${{ steps.publish.outputs.publish == 'true' }}
119167
run: |
120168
{
121-
echo "## Release ${{ steps.release.outputs.tag_name }} 🚀"
169+
echo "## Release ${{ steps.publish.outputs.tag_name }} 🚀"
122170
echo
123-
echo "- **GitHub Release**: https://github.com/${{ github.repository }}/releases/tag/${{ steps.release.outputs.tag_name }}"
124-
echo "- **Container Image**: \`${{ env.GHCR_IMAGE }}:${{ steps.release.outputs.tag_name }}\`"
171+
echo "- **GitHub Release**: ${{ steps.publish.outputs.release_url }}"
172+
echo "- **Container Image**: \`${{ env.GHCR_IMAGE }}:${{ steps.publish.outputs.tag_name }}\`"
125173
echo "- **Template Kind**: \`${{ steps.template.outputs.kind }}\`"
126174
echo "- **Latest Template URL**: ${{ steps.template.outputs.latest_url }}"
127175
echo "- **Pinned Template URL**: ${{ steps.template.outputs.versioned_url }}"
@@ -133,6 +181,6 @@ jobs:
133181
echo
134182
echo "### Pull the image"
135183
echo '```bash'
136-
echo "docker pull ${{ env.GHCR_IMAGE }}:${{ steps.release.outputs.tag_name }}"
184+
echo "docker pull ${{ env.GHCR_IMAGE }}:${{ steps.publish.outputs.tag_name }}"
137185
echo '```'
138186
} >> "$GITHUB_STEP_SUMMARY"

Impulse.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ metadata:
55
annotations:
66
registry.bubustack.io/maturity: experimental
77
spec:
8-
version: 0.1.0
8+
version: 0.1.0 # x-release-please-version
99
description: |
1010
Triggers Stories from Kubernetes cluster activity.
1111
Supports watching resource changes, cluster events, and more.
1212
1313
Modes:
1414
- watch: React to resource state changes (Add/Update/Delete)
1515
- events: React to Kubernetes Event objects (warnings, errors)
16-
image: ghcr.io/bubustack/kubernetes-impulse:0.1.0
16+
image: ghcr.io/bubustack/kubernetes-impulse:0.1.0 # x-release-please-version
1717
supportedModes:
1818
- deployment
1919

0 commit comments

Comments
 (0)