-
Notifications
You must be signed in to change notification settings - Fork 0
187 lines (164 loc) · 6.98 KB
/
release-please.yml
File metadata and controls
187 lines (164 loc) · 6.98 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
name: Release Please
on:
push:
branches:
- main
workflow_dispatch:
inputs:
tag_name:
description: Existing release tag to publish (for example `v0.1.0`)
required: false
type: string
permissions:
contents: write
packages: write
pull-requests: write
concurrency:
group: release-please-${{ github.ref }}
cancel-in-progress: true
env:
GHCR_IMAGE: ghcr.io/${{ github.repository }}
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- name: Release Please
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.tag_name == '' }}
id: release
uses: googleapis/release-please-action@v5
with:
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
config-file: .github/release-please-config.json
manifest-file: .github/.release-please-manifest.json
- name: Checkout workflow source
uses: actions/checkout@v6
- name: Detect release context
id: publish
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
manual_tag="${{ github.event.inputs.tag_name }}"
if [ -n "${manual_tag}" ]; then
release_json="$(gh release view "${manual_tag}" --json targetCommitish,url 2>/dev/null || true)"
if [ -z "${release_json}" ]; then
echo "Release ${manual_tag} not found" >&2
exit 1
fi
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "tag_name=${manual_tag}" >> "$GITHUB_OUTPUT"
echo "release_url=$(printf '%s' "${release_json}" | jq -r '.url')" >> "$GITHUB_OUTPUT"
echo "checkout_ref=${manual_tag}" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "${{ steps.release.outputs.release_created }}" = "true" ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "tag_name=${{ steps.release.outputs.tag_name }}" >> "$GITHUB_OUTPUT"
echo "release_url=${{ steps.release.outputs.html_url }}" >> "$GITHUB_OUTPUT"
echo "checkout_ref=${{ steps.release.outputs.tag_name }}" >> "$GITHUB_OUTPUT"
exit 0
fi
version="$(jq -r '."."' .github/.release-please-manifest.json)"
if [ -z "${version}" ] || [ "${version}" = "null" ]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
exit 0
fi
tag_name="v${version}"
release_json="$(gh release view "${tag_name}" --json targetCommitish,url 2>/dev/null || true)"
if [ -z "${release_json}" ]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
exit 0
fi
target_commitish="$(printf '%s' "${release_json}" | jq -r '.targetCommitish')"
if [ "${target_commitish}" != "${GITHUB_SHA}" ]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "tag_name=${tag_name}" >> "$GITHUB_OUTPUT"
echo "release_url=$(printf '%s' "${release_json}" | jq -r '.url')" >> "$GITHUB_OUTPUT"
echo "checkout_ref=${tag_name}" >> "$GITHUB_OUTPUT"
- name: Checkout release source
if: ${{ steps.publish.outputs.publish == 'true' }}
uses: actions/checkout@v6
with:
ref: ${{ steps.publish.outputs.checkout_ref }}
- name: Set up Docker Buildx
if: ${{ steps.publish.outputs.publish == 'true' }}
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
if: ${{ steps.publish.outputs.publish == 'true' }}
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
if: ${{ steps.publish.outputs.publish == 'true' }}
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.GHCR_IMAGE }}
tags: |
type=semver,pattern={{version}},value=${{ steps.publish.outputs.tag_name }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.publish.outputs.tag_name }}
type=semver,pattern={{major}},value=${{ steps.publish.outputs.tag_name }}
type=raw,value=${{ steps.publish.outputs.tag_name }}
type=raw,value=latest
- name: Build and push Docker image
if: ${{ steps.publish.outputs.publish == 'true' }}
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Detect template manifest
if: ${{ steps.publish.outputs.publish == 'true' }}
id: template
run: |
set -euo pipefail
if [ -f Engram.yaml ]; then
template_file="Engram.yaml"
template_kind="EngramTemplate"
elif [ -f Impulse.yaml ]; then
template_file="Impulse.yaml"
template_kind="ImpulseTemplate"
else
echo "Expected Engram.yaml or Impulse.yaml at repo root" >&2
exit 1
fi
echo "file=${template_file}" >> "$GITHUB_OUTPUT"
echo "kind=${template_kind}" >> "$GITHUB_OUTPUT"
echo "latest_url=https://github.com/${{ github.repository }}/releases/latest/download/${template_file}" >> "$GITHUB_OUTPUT"
echo "versioned_url=https://github.com/${{ github.repository }}/releases/download/${{ steps.publish.outputs.tag_name }}/${template_file}" >> "$GITHUB_OUTPUT"
- name: Upload template manifest to GitHub release
if: ${{ steps.publish.outputs.publish == 'true' }}
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "${{ steps.publish.outputs.tag_name }}" "${{ steps.template.outputs.file }}" --clobber
- name: Summarize release
if: ${{ steps.publish.outputs.publish == 'true' }}
run: |
{
echo "## Release ${{ steps.publish.outputs.tag_name }} 🚀"
echo
echo "- **GitHub Release**: ${{ steps.publish.outputs.release_url }}"
echo "- **Container Image**: \`${{ env.GHCR_IMAGE }}:${{ steps.publish.outputs.tag_name }}\`"
echo "- **Template Kind**: \`${{ steps.template.outputs.kind }}\`"
echo "- **Latest Template URL**: ${{ steps.template.outputs.latest_url }}"
echo "- **Pinned Template URL**: ${{ steps.template.outputs.versioned_url }}"
echo
echo "### Install the template"
echo '```bash'
echo "kubectl apply -f ${{ steps.template.outputs.latest_url }}"
echo '```'
echo
echo "### Pull the image"
echo '```bash'
echo "docker pull ${{ env.GHCR_IMAGE }}:${{ steps.publish.outputs.tag_name }}"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"