Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ jobs:
run: go test -count=1 ./config/ ./config/node/ ./lib/tn/ ./lib/constructs/validator_set/ ./stacks/

# Tests the check that release.yaml and publish-node-image.yaml run on each
# release page.
# release page, and the Telegram announcement that release.yaml posts. The
# announcement test sends only to a local fake Telegram.
release-upgrade-line:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- uses: actions/checkout@v4
- name: Test the upgrade line check
run: scripts/release/test-check-upgrade-line.sh
- name: Test the Telegram announcement
run: scripts/release/test-announce-telegram.sh

acceptance-test:
runs-on: ubuntu-latest
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ jobs:
RELEASE_BODY: ${{ github.event.release.body }}
run: printf '%s' "$RELEASE_BODY" | scripts/release/check-upgrade-line.sh

# The last step announces the release in Telegram only when the release
# had no assets before this run: on its publish, or on the edit that
# fixes a release whose first run failed, but not on later edits. This
# reads the release from the API, not from the event, so a run that
# waited behind an earlier one sees the binaries that run uploaded. A
# failed read leaves assets unset, so nothing is announced.
- name: Count the release's assets
id: before
if: github.event_name == 'release'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ github.event.release.id }}
run: |
if count=$(gh api "repos/$GITHUB_REPOSITORY/releases/$RELEASE_ID/assets" --jq length); then
echo "The release has $count asset(s)."
echo "assets=$count" >> "$GITHUB_OUTPUT"
else
echo "::warning::Could not read the release's assets, so this run does not announce the release in Telegram."
fi

- name: Set Version
id: vars
run: |
Expand Down Expand Up @@ -94,6 +114,7 @@ jobs:
rm -rf ./.build/kwild

- name: Release
id: upload
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
Expand All @@ -103,3 +124,22 @@ jobs:
./.build/tn_${{ env.VERSION }}_linux_amd64.tar.gz
./.build/tn_${{ env.VERSION }}_linux_arm64.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}

# One message to the Telegram chat and topic that the node alerts use
# (docs/release-process.md). Without the secrets, as in a fork, the
# script skips with a notice. A failure here does not fail the release.
- name: Announce the release in Telegram
if: github.event_name == 'release' && steps.before.outputs.assets == '0' && steps.upload.outcome == 'success'
continue-on-error: true
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_TOPIC_ID: ${{ secrets.TELEGRAM_TOPIC_ID }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_URL: ${{ github.event.release.html_url }}
RELEASE_BODY: ${{ github.event.release.body }}
run: |
if ! scripts/release/announce-telegram.sh "$RELEASE_TAG" "$RELEASE_URL" <<<"$RELEASE_BODY"; then
echo "::warning::The release was not announced in Telegram. To post it by hand, see docs/release-process.md#the-telegram-announcement."
exit 1
fi
24 changes: 21 additions & 3 deletions docs/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,30 @@ A required release must run every block before its block the same way as the rel

Release notices go out on the [release page](https://github.com/trufnetwork/node/releases). Operators get them by choosing **Watch → Custom → Releases** on this repository, or from the feed at <https://github.com/trufnetwork/node/releases.atom>.

`release.yaml` also posts one message about each release to Telegram; see [The Telegram Announcement](#the-telegram-announcement).

## The Telegram Announcement

After `release.yaml` uploads the binaries, it posts one message to the Telegram chat and topic that the node alerts use. The repository secrets `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` and `TELEGRAM_TOPIC_ID` set the bot, the chat and the topic. The message is built from the upgrade line and the tag. For a required release, it names the networks, the block and its time on each, and the version that `kwild version` prints after the upgrade, and it links to the release page and to [Required In-Place Upgrade](node-upgrade-guide.md#required-in-place-upgrade). For an optional release, it says that the upgrade is optional and links to the release page.

The message goes out once per release. `release.yaml` reads the release's assets before it builds, and posts only when the release had none and its upload succeeded. That is the run of the publish or, when that run failed, the run of the edit that fixes the release. Later edits find the binaries in place and post nothing, and a manual run of the workflow posts nothing.

A failed post does not fail the release; the run shows a warning. To see the message, or to post it by hand, run the script with the tag, the release page URL and the notes:

```bash
scripts/release/announce-telegram.sh --dry-run v2.6.9 https://github.com/trufnetwork/node/releases/tag/v2.6.9 < notes.md
```

Without `--dry-run`, it posts the message to the chat in `TELEGRAM_CHAT_ID`, in the topic in `TELEGRAM_TOPIC_ID` when that is set, with the bot in `TELEGRAM_BOT_TOKEN`. Without the token or the chat id, as in a fork, it posts nothing and exits without an error. It refuses notes that `check-upgrade-line.sh` refuses.

`scripts/release/test-announce-telegram.sh` tests the messages and the post against a local fake Telegram. CI runs it.

## Publishing a Release

1. Draft the release from its tag, generate the notes, and put the upgrade line first.
2. Check the notes with `scripts/release/check-upgrade-line.sh`.
3. Publish. `release.yaml` builds the four `kwild` tarballs and uploads them to the release. `publish-node-image.yaml` pushes the image as `v<version>`, `<version>`, `sha-<short commit>` and `latest`.
4. If the line was missing or wrong, both workflows fail before they build. Edit the release to fix the line. `release.yaml` runs again on the edit and uploads the binaries. `publish-node-image.yaml` runs only when a release is published, so run **Publish Node Image** by hand on the release tag with **Also tag this build as latest**. A manual run has no release notes to read, so it skips the check.
3. Publish. `release.yaml` builds the four `kwild` tarballs, uploads them to the release and posts the Telegram announcement. `publish-node-image.yaml` pushes the image as `v<version>`, `<version>`, `sha-<short commit>` and `latest`.
4. If the line was missing or wrong, both workflows fail before they build. Edit the release to fix the line. `release.yaml` runs again on the edit, uploads the binaries and posts the announcement. `publish-node-image.yaml` runs only when a release is published, so run **Publish Node Image** by hand on the release tag with **Also tag this build as latest**. A manual run has no release notes to read, so it skips the check.
5. After a required release, run **Build AMI** so that nodes launched from the AMI start on it.

Every edit of the release notes runs `release.yaml` again, which builds and uploads the binaries again.
Every edit of the release notes runs `release.yaml` again, which builds and uploads the binaries again. It does not post the announcement again.
147 changes: 147 additions & 0 deletions scripts/release/announce-telegram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/usr/bin/env bash
# Posts one message about a release to Telegram, to the chat and topic that the
# node alerts use. The message says whether operators must install the release,
# read from the upgrade line that opens the release body (docs/release-process.md).
# release.yaml runs it once per release, after it uploads the binaries.
#
# Usage: scripts/release/announce-telegram.sh [--dry-run] TAG RELEASE_URL < release-notes.md
#
# --dry-run print the message and send nothing
#
# Settings, from the environment:
# TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID where the message goes; without both,
# it prints a notice and sends nothing
# TELEGRAM_TOPIC_ID topic (thread) in a forum chat, optional
# TELEGRAM_API for tests: another Telegram server
#
# Exits 1 when the body does not open with the upgrade line or Telegram does not
# take the message, and 2 on wrong arguments.
set -euo pipefail

guide_url=https://github.com/trufnetwork/node/blob/main/docs/node-upgrade-guide.md#required-in-place-upgrade

usage() {
echo "usage: $0 [--dry-run] TAG RELEASE_URL < release-notes.md" >&2
exit 2
}

dry_run=no
if [ "${1:-}" = --dry-run ]; then
dry_run=yes
shift
fi
[ $# -eq 2 ] && [ -n "$1" ] && [ -n "$2" ] || usage
tag=$1 release_url=$2

notice() {
if [ "${GITHUB_ACTIONS:-}" = true ]; then
echo "::notice::$1" >&2
else
echo "notice: $1" >&2
fi
}

# Escapes the characters that Telegram's HTML parse mode reads as markup.
# The replacements are quoted so that bash 5.2 does not read & in them as the
# matched text.
html() {
local s=$1
s=${s//'&'/'&amp;'}
s=${s//'<'/'&lt;'}
s=${s//'>'/'&gt;'}
printf '%s' "$s"
}

# Writes a block number with thousands separators: 3300000 -> 3,300,000.
commas() {
local n=$1 out=''
while [ ${#n} -gt 3 ]; do
out=,${n: -3}$out
n=${n:0:${#n}-3}
done
printf '%s' "$n$out"
}

line=''
IFS= read -r line || true
line=${line%$'\r'}
# The same check that release.yaml runs before it builds; it reads only the
# first line. Its "Upgrade line:" output goes to stderr so that --dry-run
# prints the message alone.
printf '%s\n' "$line" | "$(dirname "$0")/check-upgrade-line.sh" >&2

declare -A block=() when=()
for net in mainnet testnet; do
re="required on $net from block ([0-9]+) \\(about ([^)]*)\\)"
if [[ $line =~ $re ]]; then
block[$net]=$(commas "${BASH_REMATCH[1]}")
when[$net]=$(html "${BASH_REMATCH[2]}")
fi
done

name=$(html "$tag")
version=$(html "${tag#v}")
links="Release: $(html "$release_url")"
stops="A node still on an older release stops at that block. After upgrading, <code>kwild version</code> prints ${version}."

if [ -n "${block[mainnet]:-}" ] && [ -n "${block[testnet]:-}" ]; then
text="REQUIRED: TN node ${name}

Install it before:
- mainnet block ${block[mainnet]} (about ${when[mainnet]})
- testnet block ${block[testnet]} (about ${when[testnet]})

${stops}

${links}
How to upgrade: ${guide_url}"
elif [ -n "${block[mainnet]:-}" ] || [ -n "${block[testnet]:-}" ]; then
if [ -n "${block[mainnet]:-}" ]; then
net=mainnet other=testnet
else
net=testnet other=mainnet
fi
text="REQUIRED on ${net}: TN node ${name}

Install it before ${net} block ${block[$net]} (about ${when[$net]}). On ${other} it is optional.

${stops}

${links}
How to upgrade: ${guide_url}"
else
text="TN node ${name} is out. Optional: nodes on older releases keep following the chain, so upgrade when it suits you.

${links}"
fi

if [ "$dry_run" = yes ]; then
printf '%s\n' "$text"
exit 0
fi

if [ -z "${TELEGRAM_BOT_TOKEN:-}" ] || [ -z "${TELEGRAM_CHAT_ID:-}" ]; then
notice "TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID is not set, so ${tag} is not announced in Telegram."
exit 0
fi

topic=()
if [ -n "${TELEGRAM_TOPIC_ID:-}" ]; then
topic=(--data-urlencode "message_thread_id=${TELEGRAM_TOPIC_ID}")
fi
answer=$(mktemp)
trap 'rm -f "$answer"' EXIT
# The URL holds the token, so it goes to curl through stdin, not the command line.
code=$(printf 'url = "%s/bot%s/sendMessage"\n' "${TELEGRAM_API:-https://api.telegram.org}" "$TELEGRAM_BOT_TOKEN" |
curl -sS -m 20 -o "$answer" -w '%{http_code}' -K - \
--data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" ${topic[@]+"${topic[@]}"} \
--data-urlencode parse_mode=HTML \
--data-urlencode disable_web_page_preview=true \
--data-urlencode "text=${text}") || code=000
if [ "$code" != 200 ]; then
# Telegram explains a refusal in "description", such as a wrong topic id.
why=$(sed -n 's/.*"description":"\([^"]*\)".*/\1/p' "$answer" | head -c 300)
echo "announce-telegram: Telegram answered HTTP ${code}${why:+: $why}" >&2
exit 1
fi
echo "Announced ${tag} in Telegram."
Loading
Loading