Skip to content

Commit 22243b6

Browse files
test: sprint-cut notify preview — 4 outcome scenarios (branch/dev/preview/PR, npmjs link)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a64da40 commit 22243b6

2 files changed

Lines changed: 140 additions & 137 deletions

File tree

Lines changed: 27 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,60 @@
11
name: Release Slack Notify (TEST)
22

3-
# End-to-end test harness for the release-branch Slack notification.
3+
# Preview harness for the sprint-cut Slack notification. Posts DEMO messages
4+
# (mock data — no real cut, no publish) to a Slack channel so the team can see
5+
# how the biweekly `sprint-release-cut.yml` notification renders in every
6+
# outcome: full success, preview-publish failure, dev-publish failure, and
7+
# branch-cut failure. Each step carries a status emoji (✅ / ❌ / ⏭️).
48
#
5-
# Mirrors the notify path that will hang off `sprint-release-cut.yml` (the real
6-
# biweekly-Sunday cut), but WITHOUT the npm publish / version-bump machinery:
7-
# it cuts a throwaway `release/test-<run_id>` branch from `main`, posts a
8-
# "release branch created" message to Slack, then (by default) deletes the
9-
# throwaway branch so the test leaves no residue.
9+
# The notification models the real cut (see sprint-release-cut.yml):
10+
# 1. cut release/v<M.N> from main at version M.N.0
11+
# 2. publish DEV (GitHub Packages) + PREVIEW (npmjs) — stable is manual
12+
# 3. open a bump PR advancing main to the next line
1013
#
11-
# Slack mechanism copies the CLI repo (UiPath/cli, coverage-weekly.yml):
12-
# `SLACK_BOT_TOKEN` + `chat.postMessage` by channel ID. Unlike an Incoming
13-
# Webhook, a bot token can target any channel by ID, so the same action posts
14-
# to the test channel now and the real release channel later — just swap the ID.
14+
# Slack mechanism copies UiPath/cli (coverage-weekly.yml): SLACK_BOT_TOKEN +
15+
# chat.postMessage by channel ID. The four demo messages are threaded under a
16+
# banner to keep the channel tidy.
1517
#
16-
# How to run the E2E test:
17-
# 1. Add repo secret SLACK_BOT_TOKEN (a Slack bot `xoxb-...` token) and invite
18-
# that bot to the target channel.
19-
# 2. Push this file on a `test/slack-notify-**` branch (auto-runs), or use the
20-
# Actions tab / `gh workflow run` once it is on the default branch.
18+
# Run it: push this file on a `test/slack-notify-**` branch (auto-runs), or
19+
# dispatch from the Actions tab once it is on the default branch.
2120

2221
on:
2322
push:
2423
branches:
25-
- 'test/slack-notify-**' # auto-run on the PoC branch — no default-branch dependency
24+
- 'test/slack-notify-**'
2625
workflow_dispatch:
2726
inputs:
2827
channel_id:
29-
description: 'Slack channel ID to post to'
28+
description: 'Slack channel ID to post the demo messages to'
3029
required: false
3130
default: 'C0BHX329GNR' # #tmp-skills-slack-bot-tests
32-
cut_branch:
33-
description: 'Actually cut a throwaway release/test-<run_id> branch'
34-
type: boolean
35-
required: false
36-
default: true
37-
keep_branch:
38-
description: 'Keep the throwaway branch instead of deleting it'
39-
type: boolean
40-
required: false
41-
default: false
42-
dry_run:
43-
description: 'Print the message without posting to Slack or cutting a branch'
44-
type: boolean
45-
required: false
46-
default: false
4731

4832
permissions:
49-
contents: write
33+
contents: read
5034

5135
concurrency:
5236
group: release-slack-notify-test
5337
cancel-in-progress: false
5438

5539
env:
56-
# #tmp-skills-slack-bot-tests. workflow_dispatch overrides via input; push
57-
# runs use this default.
58-
DEFAULT_CHANNEL_ID: 'C0BHX329GNR'
40+
DEFAULT_CHANNEL_ID: 'C0BHX329GNR' # #tmp-skills-slack-bot-tests
5941

6042
jobs:
61-
notify:
43+
demo:
6244
runs-on: ubuntu-latest
6345
steps:
46+
# Check out main so the demo reads the REAL current version (the line the
47+
# next cut would target) rather than a hardcoded guess.
6448
- uses: actions/checkout@v4
6549
with:
6650
ref: main
6751
fetch-depth: 0
6852

69-
- name: Resolve settings
70-
id: cfg
71-
run: |
72-
CHANNEL="${{ github.event.inputs.channel_id }}"
73-
[ -z "$CHANNEL" ] && CHANNEL="$DEFAULT_CHANNEL_ID"
74-
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"
75-
76-
# Default booleans differ by trigger: a push has no inputs, so treat
77-
# it as "cut a branch, delete it after, not a dry run".
78-
CUT="${{ github.event.inputs.cut_branch }}"
79-
[ -z "$CUT" ] && CUT="true"
80-
echo "cut=$CUT" >> "$GITHUB_OUTPUT"
81-
82-
KEEP="${{ github.event.inputs.keep_branch }}"
83-
[ -z "$KEEP" ] && KEEP="false"
84-
echo "keep=$KEEP" >> "$GITHUB_OUTPUT"
85-
86-
DRY="${{ github.event.inputs.dry_run }}"
87-
[ -z "$DRY" ] && DRY="false"
88-
echo "dry=$DRY" >> "$GITHUB_OUTPUT"
89-
90-
echo "branch=release/test-${{ github.run_id }}" >> "$GITHUB_OUTPUT"
91-
92-
- name: Cut throwaway release branch
93-
id: cut
94-
if: steps.cfg.outputs.cut == 'true' && steps.cfg.outputs.dry != 'true'
95-
run: |
96-
BRANCH="${{ steps.cfg.outputs.branch }}"
97-
git config user.name "github-actions[bot]"
98-
git config user.email "github-actions[bot]@users.noreply.github.com"
99-
100-
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
101-
echo "$BRANCH already exists — reusing."
102-
else
103-
git push origin "HEAD:refs/heads/$BRANCH"
104-
echo "Created $BRANCH."
105-
fi
106-
echo "sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
107-
108-
- name: Post to Slack
109-
id: slack
110-
if: steps.cfg.outputs.dry != 'true'
53+
- name: Post demo scenario messages
11154
env:
11255
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
113-
run: |
114-
set -euo pipefail
115-
if [ -z "${SLACK_BOT_TOKEN:-}" ]; then
116-
echo "::error::SLACK_BOT_TOKEN is not set. Add it as a repo secret and invite the bot to the channel."
117-
exit 1
118-
fi
119-
120-
CHANNEL="${{ steps.cfg.outputs.channel }}"
121-
BRANCH="${{ steps.cfg.outputs.branch }}"
122-
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
123-
124-
# Match the Studio "Sprint Release Bot" style (#dev-studio-robot):
125-
# ":checkbox_ticked: Created branch `<branch>` for <url|Repo>. Any
126-
# further changes targeting the release should be cherry-picked there."
127-
if [ "${{ steps.cfg.outputs.cut }}" = "true" ]; then
128-
REPO_LINK="<$REPO_URL/tree/$BRANCH|skills>"
129-
else
130-
REPO_LINK="<$REPO_URL|skills>"
131-
fi
132-
133-
TEXT="[TEST] :checkbox_ticked: Created branch \`$BRANCH\` for $REPO_LINK. Any further changes targeting the release should be cherry-picked there."
134-
135-
# Build the JSON body with jq so message text is escaped correctly.
136-
BODY="$(jq -nc --arg channel "$CHANNEL" --arg text "$TEXT" \
137-
'{channel: $channel, text: $text, unfurl_links: false}')"
138-
139-
RESP="$(curl -sS -X POST https://slack.com/api/chat.postMessage \
140-
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
141-
-H "Content-Type: application/json; charset=utf-8" \
142-
--data "$BODY")"
143-
144-
echo "Slack API response: $RESP"
145-
# Slack returns HTTP 200 even on logical failure — check the ok field.
146-
if [ "$(echo "$RESP" | jq -r '.ok')" != "true" ]; then
147-
echo "::error::Slack post failed: $(echo "$RESP" | jq -r '.error // "unknown error"')"
148-
exit 1
149-
fi
150-
echo "Posted to $CHANNEL (ts=$(echo "$RESP" | jq -r '.ts'))."
151-
152-
- name: Delete throwaway release branch
153-
if: always() && steps.cfg.outputs.cut == 'true' && steps.cfg.outputs.dry != 'true' && steps.cfg.outputs.keep != 'true'
154-
run: |
155-
BRANCH="${{ steps.cfg.outputs.branch }}"
156-
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
157-
git push origin --delete "$BRANCH" && echo "Deleted $BRANCH."
158-
fi
159-
160-
- name: Summary
161-
if: always()
162-
run: |
163-
{
164-
echo "## Release Slack Notify (TEST)"
165-
echo ""
166-
echo "- channel: \`${{ steps.cfg.outputs.channel }}\`"
167-
echo "- cut branch: \`${{ steps.cfg.outputs.cut }}\` (\`${{ steps.cfg.outputs.branch }}\`)"
168-
echo "- kept branch: \`${{ steps.cfg.outputs.keep }}\`"
169-
echo "- dry run: \`${{ steps.cfg.outputs.dry }}\`"
170-
} >> "$GITHUB_STEP_SUMMARY"
56+
CHANNEL_ID: ${{ github.event.inputs.channel_id }}
57+
DEFAULT_CHANNEL_ID: ${{ env.DEFAULT_CHANNEL_ID }}
58+
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
59+
RUN_ID: ${{ github.run_id }}
60+
run: node .github/workflows/scripts/slack-release-demo.mjs
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Posts DEMO sprint-cut Slack notifications (mock data) so the team can preview
2+
// how the real biweekly cut notification renders in each outcome. No real cut,
3+
// no publish. Mechanism mirrors UiPath/cli: SLACK_BOT_TOKEN + chat.postMessage.
4+
5+
import { readFileSync } from "node:fs";
6+
7+
const SLACK_URL = "https://slack.com/api/chat.postMessage";
8+
9+
const token = requireEnv("SLACK_BOT_TOKEN");
10+
const channel = process.env.CHANNEL_ID || process.env.DEFAULT_CHANNEL_ID;
11+
if (!channel) throw new Error("No channel id (CHANNEL_ID / DEFAULT_CHANNEL_ID).");
12+
13+
const repo = process.env.REPO_URL || "https://github.com/UiPath/skills";
14+
const runUrl = process.env.RUN_ID ? `${repo}/actions/runs/${process.env.RUN_ID}` : repo;
15+
16+
// Read the REAL current version from main so the demo shows the line the next
17+
// cut would actually target (main carries M.N.0; the cut branches at M.N.0 and
18+
// main then advances to M.(N+1).0).
19+
const version = JSON.parse(readFileSync("package.json", "utf8")).version; // e.g. 1.199.0
20+
const [major, minor] = version.split(".");
21+
const line = `${major}.${minor}`; // 1.199
22+
const nextLine = `${major}.${Number(minor) + 1}`; // 1.200
23+
const nextVersion = `${nextLine}.0`; // 1.200.0
24+
25+
// Illustrative build/PR identifiers (real runs stamp the run number / PR id).
26+
const run = "18052309";
27+
const previewVer = `${version}-preview.${run}`; // 1.199.0-preview.18052309
28+
const devVer = `${version}-dev.${run}`; // 1.199.0-dev.18052309
29+
const npmUrl = `https://www.npmjs.com/package/@uipath/skills/v/${previewVer}`;
30+
const pkgsUrl = `${repo}/pkgs/npm/skills`;
31+
const prUrl = `${repo}/pull/1234`;
32+
33+
const OK = "✅";
34+
const FAIL = "❌";
35+
const SKIP = "⏭️";
36+
37+
const scenarios = [
38+
{
39+
title: `${OK} *Sprint release cut — \`${line}\`* · _[DEMO 1/4: all steps succeeded]_`,
40+
lines: [
41+
`${OK} Release branch \`release/v${line}\` cut from \`main\` (version \`${version}\`)`,
42+
`${OK} Dev build published to GitHub Packages — \`@uipath/skills@${devVer}\` (<${pkgsUrl}|packages>)`,
43+
`${OK} Preview package published to npmjs — \`@uipath/skills@${previewVer}\` (<${npmUrl}|view on npmjs>)`,
44+
`${OK} Version-bump PR opened: \`main\` → \`${nextVersion}\` (<${prUrl}|#1234>)`,
45+
`_Stable (\`latest\`) is promoted manually — see docs/RELEASE.md._`,
46+
],
47+
},
48+
{
49+
title: `${FAIL} *Sprint release cut — \`${line}\`* · _[DEMO 2/4: preview publish failed]_`,
50+
lines: [
51+
`${OK} Release branch \`release/v${line}\` cut from \`main\` (version \`${version}\`)`,
52+
`${OK} Dev build published to GitHub Packages — \`@uipath/skills@${devVer}\` (<${pkgsUrl}|packages>)`,
53+
`${FAIL} Preview publish to npmjs FAILED — \`@uipath/skills@${previewVer}\` (<${runUrl}|see logs>)`,
54+
`${SKIP} Version-bump PR skipped — \`main\` stays on \`${version}\` until the preview publish succeeds`,
55+
],
56+
},
57+
{
58+
title: `${FAIL} *Sprint release cut — \`${line}\`* · _[DEMO 3/4: dev build publish failed]_`,
59+
lines: [
60+
`${OK} Release branch \`release/v${line}\` cut from \`main\` (version \`${version}\`)`,
61+
`${FAIL} Dev build publish to GitHub Packages FAILED — \`@uipath/skills@${devVer}\` (<${runUrl}|see logs>)`,
62+
`${SKIP} Preview publish skipped — dev build must succeed first`,
63+
`${SKIP} Version-bump PR skipped — \`main\` stays on \`${version}\``,
64+
],
65+
},
66+
{
67+
title: `${FAIL} *Sprint release cut — \`${line}\`* · _[DEMO 4/4: branch cut failed]_`,
68+
lines: [
69+
`${FAIL} Release branch \`release/v${line}\` cut from \`main\` FAILED (<${runUrl}|see logs>)`,
70+
`${SKIP} Dev + preview publish skipped`,
71+
`${SKIP} Version-bump PR skipped`,
72+
],
73+
},
74+
];
75+
76+
const banner =
77+
":test_tube: *Sprint-cut Slack notification — DEMO previews (mock data, no real cut)*\n" +
78+
"The four threaded replies below show how the biweekly `sprint-release-cut.yml` " +
79+
"notification will look in each outcome. Emojis: ✅ succeeded · ❌ failed · ⏭️ skipped.";
80+
81+
async function post(text, threadTs) {
82+
const body = { channel, text, unfurl_links: false };
83+
if (threadTs) body.thread_ts = threadTs;
84+
const res = await fetch(SLACK_URL, {
85+
method: "POST",
86+
headers: {
87+
Authorization: `Bearer ${token}`,
88+
"Content-Type": "application/json; charset=utf-8",
89+
},
90+
body: JSON.stringify(body),
91+
});
92+
const data = await res.json();
93+
// Slack returns HTTP 200 even on logical failure — check the ok field.
94+
if (!res.ok || data.ok !== true) {
95+
throw new Error(`Slack post failed: ${data.error || `${res.status} ${res.statusText}`}`);
96+
}
97+
return data.ts;
98+
}
99+
100+
const parentTs = await post(banner);
101+
console.log(`Posted banner (ts=${parentTs}).`);
102+
for (const s of scenarios) {
103+
const text = `${s.title}\n${s.lines.join("\n")}`;
104+
await post(text, parentTs);
105+
console.log(`Posted: ${s.title.replace(/[*_`]/g, "")}`);
106+
}
107+
console.log(`Done — 1 banner + ${scenarios.length} scenarios to ${channel}.`);
108+
109+
function requireEnv(name) {
110+
const v = process.env[name];
111+
if (!v) throw new Error(`Missing ${name} environment variable.`);
112+
return v;
113+
}

0 commit comments

Comments
 (0)