Repository navigation
132 lines (128 loc) · 6.74 KB
/
Copy pathrelease.yml
File metadata and controls
132 lines (128 loc) · 6.74 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
# Each cleared RIFT firmware: a GitHub release and its announcement in Discord's RIFT ANNOUNCEMENTS.
#
# Claude publishes a cleared build (CLAUDE.md, "Every cleared build is published"), then
# commits its announcement as releases/vX.Y.md on main (a new file there is the trigger: the
# session's git route cannot push tags). This job, for each releases/v*.md the push added:
# 1. makes the GitHub release vX.Y (and its tag, on that commit), its notes that file (no firmware is attached: the .syx
# stays on the builds branch, and players build it with the patcher from their own
# Elektron files);
# 2. posts the same notes to RIFT ANNOUNCEMENTS through the webhook in the repository secret
# DISCORD_WEBHOOK_URL, as "De-Pattern".
# Both happen here because a release made with the workflow's own token does not start
# other workflows. A release made by hand (the GitHub page) is announced by the second job.
# Re-announce one: Actions > this workflow > Run workflow, with its tag.
name: Release and announce
on:
push:
branches: [main]
paths: ['releases/v*.md']
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Version to announce again (its releases/VERSION.md, e.g. v0.31)"
required: true
permissions:
contents: write
jobs:
from-file:
if: github.event_name != 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: The announcements this push added
id: list
env:
INPUT_TAG: ${{ github.event.inputs.tag }}
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# (the independent review's RIFT-011: the input is data, never shell; only vX.Y or vX.YY)
[[ "$INPUT_TAG" =~ ^v[0-9]+\.[0-9]+(-t[0-9]+)?$ ]] || { echo "::error::not a version tag"; exit 1; }
echo "files=releases/$INPUT_TAG.md" >> "$GITHUB_OUTPUT"
else
BEFORE="${{ github.event.before }}"
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then BEFORE="${{ github.sha }}~1"; fi
F=$(git diff --name-only --diff-filter=A "$BEFORE" "${{ github.sha }}" -- 'releases/v*.md' | tr '\n' ' ')
echo "files=$F" >> "$GITHUB_OUTPUT"
fi
- name: Release and announce each
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
FILES: ${{ steps.list.outputs.files }}
EVENT: ${{ github.event_name }}
run: |
for F in $FILES; do
test -f "$F" || { echo "::error::$F is missing"; exit 1; }
TAG=$(basename "$F" .md)
[[ "$TAG" =~ ^v[0-9]+\.[0-9]+(-t[0-9]+)?$ ]] || { echo "::error::$F: not a version"; exit 1; }
if [ "$EVENT" = "push" ] && ! gh release view "$TAG" >/dev/null 2>&1; then
# (the independent review's RIFT-002) no release without its cleared build: the builds branch
# holds TAG-NAME/*.syx and its .gate.json, the record's sha256 the file's, every gate PASS or n/a
git fetch -q origin +refs/heads/builds:refs/remotes/origin/builds
D=$(git ls-tree --name-only origin/builds | grep -E "^${TAG}-[A-Z0-9]+$" | head -1)
[ -n "$D" ] || { echo "::error::$TAG: no builds/$TAG-NAME/"; exit 1; }
SYX=$(git ls-tree --name-only origin/builds "$D/" | grep -E '\.syx$' | head -1)
[ -n "$SYX" ] || { echo "::error::$TAG: no .syx in builds/$D"; exit 1; }
git show "origin/builds:$SYX" > build.syx
git show "origin/builds:$SYX.gate.json" > gate.json || { echo "::error::$TAG: no gate record"; exit 1; }
python3 - <<'PY' || { echo "::error::$TAG: the gate record does not clear this build"; exit 1; }
import hashlib, json, sys
g = json.load(open("gate.json"))
sha = hashlib.sha256(open("build.syx", "rb").read()).hexdigest()
ok = g.get("sha256") == sha and g.get("gates") and all(str(v).startswith(("PASS", "n/a")) for v in g["gates"].values())
print("gate record:", "clears" if ok else "does NOT clear", sha)
sys.exit(0 if ok else 1)
PY
rm -f build.syx gate.json
# and its entry in FIRMWARE.md (the table's row), as CLAUDE.md's step 1 makes it
grep -qE "^\| (\*\*)?${TAG//./\\.}(\*\*)? \|" FIRMWARE.md || { echo "::error::$TAG: no row in FIRMWARE.md"; exit 1; }
fi
# the first line, "# TITLE", is the release's name; the rest its notes
head -1 "$F" | sed 's/^# *//' > title.txt
tail -n +2 "$F" | sed '1{/^$/d}' > body.md
if [ "$EVENT" = "push" ]; then
if gh release view "$TAG" >/dev/null 2>&1; then
echo "$TAG: released already"
else
gh release create "$TAG" --target "${{ github.sha }}" --title "$(cat title.txt)" --notes-file body.md
fi
fi
if [ -z "$WEBHOOK" ]; then echo "::warning::DISCORD_WEBHOOK_URL is not set: $TAG not announced"; continue; fi
jq -n --rawfile t title.txt --rawfile b body.md '{
username: "De-Pattern",
allowed_mentions: {parse: []},
embeds: [{
title: ($t | rtrimstr("\n")),
description: ($b[0:4000] + (if ($b|length) > 4000 then "\n\n…the rest on GitHub" else "" end)),
color: 15105570,
footer: {text: "RIFT · unofficial, not made or supported by Elektron"}
}]
}' | curl -fsS -H "Content-Type: application/json" -d @- "$WEBHOOK"
done
# a release published by hand on GitHub (not by the job above)
from-release:
if: github.event_name == 'release' && github.event.release.author.login != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- name: Post to RIFT ANNOUNCEMENTS
env:
WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
NAME: ${{ github.event.release.name }}
TAG: ${{ github.event.release.tag_name }}
BODY: ${{ github.event.release.body }}
run: |
if [ -z "$WEBHOOK" ]; then echo "::warning::DISCORD_WEBHOOK_URL is not set: not announced"; exit 0; fi
jq -n --arg n "${NAME:-$TAG}" --arg b "$BODY" '{
username: "De-Pattern",
allowed_mentions: {parse: []},
embeds: [{
title: $n,
description: ($b[0:4000] + (if ($b|length) > 4000 then "\n\n…the rest on GitHub" else "" end)),
color: 15105570,
footer: {text: "RIFT · unofficial, not made or supported by Elektron"}
}]
}' | curl -fsS -H "Content-Type: application/json" -d @- "$WEBHOOK"