|
| 1 | +// Posts the sprint-cut announcement to Slack (chat.postMessage; mirrors |
| 2 | +// UiPath/cli). Driven by the real step outcomes passed in as env vars, so the |
| 3 | +// message reflects what actually happened. Emojis match Studio's Sprint Release |
| 4 | +// Bot (#dev-studio-robot): :checkbox_ticked: succeeded · :warning: failed/skipped. |
| 5 | + |
| 6 | +const SLACK_URL = "https://slack.com/api/chat.postMessage"; |
| 7 | + |
| 8 | +const token = requireEnv("SLACK_BOT_TOKEN"); |
| 9 | +const channel = requireEnv("CHANNEL_ID"); |
| 10 | +const repo = process.env.REPO_URL || "https://github.com/UiPath/skills"; |
| 11 | +const runUrl = process.env.RUN_ID ? `${repo}/actions/runs/${process.env.RUN_ID}` : repo; |
| 12 | + |
| 13 | +const line = requireEnv("CUT_LINE"); // e.g. 1.199 |
| 14 | +const version = `${line}.0`; // 1.199.0 |
| 15 | +const nextVersion = `${requireEnv("NEXT_LINE")}.0`; // 1.200.0 |
| 16 | + |
| 17 | +const cutOk = process.env.CUT_OUTCOME === "success"; |
| 18 | +const publishOk = process.env.PUBLISH_OUTCOME === "success"; |
| 19 | +const bumpOk = process.env.BUMP_OUTCOME === "success"; |
| 20 | +const bumpUrl = process.env.BUMP_URL || ""; |
| 21 | + |
| 22 | +const branchUrl = `${repo}/tree/release/v${line}`; |
| 23 | +// Exact preview version is stamped by publish.yml (<version>-preview.<run>). |
| 24 | +// If we have it, link the precise npmjs version; else fall back to versions tab. |
| 25 | +const previewVersion = process.env.PREVIEW_VERSION || ""; |
| 26 | +const npmUrl = previewVersion |
| 27 | + ? `https://www.npmjs.com/package/@uipath/skills/v/${previewVersion}` |
| 28 | + : "https://www.npmjs.com/package/@uipath/skills?activeTab=versions"; |
| 29 | +const previewLabel = previewVersion |
| 30 | + ? `\`@uipath/skills@${previewVersion}\`` |
| 31 | + : `\`@uipath/skills@${version}-preview\``; |
| 32 | + |
| 33 | +const OK = ":checkbox_ticked:"; |
| 34 | +const WARN = ":warning:"; |
| 35 | + |
| 36 | +// Branch line |
| 37 | +const branchLine = cutOk |
| 38 | + ? `${OK} Release branch \`release/v${line}\` cut from \`main\` (version \`${version}\`, <${branchUrl}|view branch>)` |
| 39 | + : `${WARN} Release branch \`release/v${line}\` cut from \`main\` FAILED (<${runUrl}|see logs>)`; |
| 40 | + |
| 41 | +// Preview package line |
| 42 | +let previewLine; |
| 43 | +if (publishOk) { |
| 44 | + previewLine = `${OK} Preview package published to npmjs — ${previewLabel} (<${npmUrl}|view on npmjs>)`; |
| 45 | +} else if (!cutOk) { |
| 46 | + previewLine = `${WARN} Preview package publish skipped`; |
| 47 | +} else { |
| 48 | + previewLine = `${WARN} Preview package publish to npmjs FAILED — ${previewLabel} (<${runUrl}|see logs>)`; |
| 49 | +} |
| 50 | + |
| 51 | +// Version-bump PR line |
| 52 | +let bumpLine; |
| 53 | +if (bumpOk && bumpUrl) { |
| 54 | + bumpLine = publishOk |
| 55 | + ? `${OK} Version-bump PR opened: \`main\` → \`${nextVersion}\` (<${bumpUrl}|PR>)` |
| 56 | + : `${OK} Version-bump PR opened anyway: \`main\` → \`${nextVersion}\` (<${bumpUrl}|PR>) — ${WARN} verify the failed publish before merging`; |
| 57 | +} else if (bumpOk && !bumpUrl) { |
| 58 | + bumpLine = `${OK} \`main\` already on \`${nextVersion}\` — no bump PR needed`; |
| 59 | +} else { |
| 60 | + bumpLine = `${WARN} Version-bump PR not opened — \`main\` stays on \`${version}\``; |
| 61 | +} |
| 62 | + |
| 63 | +const overall = cutOk && publishOk ? OK : WARN; |
| 64 | +const text = [ |
| 65 | + `${overall} *Sprint release cut — \`${line}\`*`, |
| 66 | + branchLine, |
| 67 | + previewLine, |
| 68 | + bumpLine, |
| 69 | +].join("\n"); |
| 70 | + |
| 71 | +const res = await fetch(SLACK_URL, { |
| 72 | + method: "POST", |
| 73 | + headers: { |
| 74 | + Authorization: `Bearer ${token}`, |
| 75 | + "Content-Type": "application/json; charset=utf-8", |
| 76 | + }, |
| 77 | + body: JSON.stringify({ channel, text, unfurl_links: false }), |
| 78 | +}); |
| 79 | +const data = await res.json(); |
| 80 | +// Slack returns HTTP 200 even on logical failure — check the ok field. |
| 81 | +if (!res.ok || data.ok !== true) { |
| 82 | + throw new Error(`Slack post failed: ${data.error || `${res.status} ${res.statusText}`}`); |
| 83 | +} |
| 84 | +console.log(`Posted sprint-cut announcement to ${channel} (ts=${data.ts}).`); |
| 85 | + |
| 86 | +function requireEnv(name) { |
| 87 | + const v = process.env[name]; |
| 88 | + if (!v) throw new Error(`Missing ${name} environment variable.`); |
| 89 | + return v; |
| 90 | +} |
0 commit comments