Skip to content

Commit cea7dec

Browse files
vdemeesterclaude
andcommitted
chore: add task signing to release script
- Check for signing key and tkn CLI before proceeding - Sign task and stepaction YAMLs with tkn task sign - Normalize AH_CHANGES indentation (handle LLM output variance) - Include stepaction in version bump files Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
1 parent 72fde74 commit cea7dec

1 file changed

Lines changed: 42 additions & 13 deletions

File tree

hack/release.sh

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# ./hack/release.sh v1.5.0 # bump, commit, tag, push
2121
# ./hack/release.sh v1.5.0 --dry-run # show what would change
2222
# ./hack/release.sh v1.5.0 --llm # generate changelog with gh copilot
23+
#
24+
# Environment variables:
25+
# SIGNING_KEY - Path to ECDSA private key for signing tasks (default: keys/signing-key.pem)
2326

2427
set -euo pipefail
2528

@@ -30,6 +33,7 @@ ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
3033
VERSION=""
3134
DRY_RUN=false
3235
USE_LLM=false
36+
SIGNING_KEY="${SIGNING_KEY:-${ROOT_DIR}/keys/signing-key.pem}"
3337

3438
for arg in "$@"; do
3539
case "${arg}" in
@@ -46,6 +50,20 @@ if [[ -z "${VERSION}" ]]; then
4650
exit 1
4751
fi
4852

53+
# Check signing key
54+
if [[ ! -f "${SIGNING_KEY}" ]]; then
55+
echo "Error: signing key not found at ${SIGNING_KEY}"
56+
echo " Set SIGNING_KEY env var or place key at keys/signing-key.pem"
57+
echo " Generate with: openssl ecparam -genkey -name prime256v1 -noout -out keys/signing-key.pem"
58+
exit 1
59+
fi
60+
61+
# Check tkn CLI
62+
if ! command -v tkn &>/dev/null; then
63+
echo "Error: tkn CLI not found. Install from https://tekton.dev/docs/cli/"
64+
exit 1
65+
fi
66+
4967
# Validate version format
5068
if ! echo "${VERSION}" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
5169
echo "Error: version must match vX.Y.Z (got: ${VERSION})"
@@ -57,6 +75,12 @@ BARE_VERSION="${VERSION#v}"
5775

5876
cd "${ROOT_DIR}"
5977

78+
# --- Task files to sign ---
79+
TASK_FILES=(
80+
"task/git-clone/git-clone.yaml"
81+
"stepaction/git-clone/git-clone.yaml"
82+
)
83+
6084
# --- Detect current version ---
6185
CURRENT_VERSION=$(grep 'app.kubernetes.io/version' task/git-clone/git-clone.yaml | head -1 | sed 's/.*"\(.*\)"/\1/')
6286
CURRENT_TAG="v${CURRENT_VERSION}"
@@ -122,7 +146,6 @@ Output the two sections separated by the exact string ---SEPARATOR--- on its own
122146
LLM_OUTPUT=$(gh copilot -p "${PROMPT}" 2>/dev/null || echo "")
123147

124148
if [[ -n "${LLM_OUTPUT}" ]]; then
125-
# Extract the two sections, stripping any preamble before the YAML
126149
AH_CHANGES=$(echo "${LLM_OUTPUT}" | sed -n '/^ *- kind:/,/---SEPARATOR---/p' | grep -v '^---SEPARATOR---')
127150
TAG_MESSAGE=$(echo "${LLM_OUTPUT}" | sed -n '/^---SEPARATOR---$/,$ p' | tail -n +2 | sed '/^$/d; /^[[:space:]]*$/d' | sed '1{/^$/d}')
128151
else
@@ -159,14 +182,11 @@ echo "--- Tag message:"
159182
echo "${TAG_MESSAGE}"
160183
echo ""
161184

162-
# --- Files to update ---
163-
FILES=(
164-
"task/git-clone/git-clone.yaml"
165-
"README.md"
166-
)
185+
# --- All files to update ---
186+
ALL_FILES=("${TASK_FILES[@]}" "README.md")
167187

168188
echo "--- Version bumps:"
169-
for f in "${FILES[@]}"; do
189+
for f in "${ALL_FILES[@]}"; do
170190
echo " ${f}"
171191
done
172192
echo ""
@@ -183,11 +203,13 @@ apply_version_bumps() {
183203

184204
# --- Helper: update artifacthub changelog in content (stdin → stdout) ---
185205
apply_ah_changes() {
206+
local normalized
207+
normalized=$(echo -e "${AH_CHANGES}" | grep -v '^[[:space:]]*\`\`\`' | sed -e 's/^[[:space:]]*- kind:/ - kind:/' -e 's/^[[:space:]]*description:/ description:/')
186208
python3 -c "
187209
import re, sys
188210
content = sys.stdin.read()
189211
new_changes = ''' artifacthub.io/changes: |
190-
$(echo -e "${AH_CHANGES}")'''
212+
${normalized}'''
191213
content = re.sub(
192214
r' artifacthub\.io/changes: \|\n( .*\n)*',
193215
new_changes.rstrip() + '\n',
@@ -200,10 +222,10 @@ sys.stdout.write(content)
200222
if [[ "${DRY_RUN}" == true ]]; then
201223
echo "--- Dry run: showing changes ---"
202224

203-
for f in "${FILES[@]}"; do
225+
for f in "${ALL_FILES[@]}"; do
204226
echo ""
205227
echo "=== ${f} ==="
206-
if [[ "${f}" == *"git-clone.yaml" ]]; then
228+
if [[ "${f}" == *".yaml" ]]; then
207229
apply_version_bumps "${f}" | apply_ah_changes | diff -u "${f}" - || true
208230
else
209231
apply_version_bumps "${f}" | diff -u "${f}" - || true
@@ -217,8 +239,8 @@ fi
217239
# --- Apply version bumps ---
218240
echo "--- Applying version bumps..."
219241

220-
for f in "${FILES[@]}"; do
221-
if [[ "${f}" == *"git-clone.yaml" ]]; then
242+
for f in "${ALL_FILES[@]}"; do
243+
if [[ "${f}" == *".yaml" ]]; then
222244
apply_version_bumps "${f}" | apply_ah_changes > "${f}.tmp" && mv "${f}.tmp" "${f}"
223245
else
224246
apply_version_bumps "${f}" > "${f}.tmp" && mv "${f}.tmp" "${f}"
@@ -228,8 +250,15 @@ done
228250
echo "--- Regenerating StepAction..."
229251
./hack/generate-stepaction.sh
230252

253+
# --- Sign task YAMLs ---
254+
echo "--- Signing task YAMLs with ${SIGNING_KEY}..."
255+
for f in "${TASK_FILES[@]}"; do
256+
echo " Signing ${f}"
257+
tkn task sign "${f}" -K="${SIGNING_KEY}" -f="${f}"
258+
done
259+
231260
echo "--- Committing..."
232-
git add task/git-clone/git-clone.yaml README.md stepaction/git-clone/git-clone.yaml
261+
git add "${ALL_FILES[@]}"
233262
git commit --signoff --message "chore: bump version to ${VERSION}"
234263

235264
echo "--- Pushing to main..."

0 commit comments

Comments
 (0)