|
1 | 1 | name: Release Slack Notify (TEST) |
2 | 2 |
|
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 (✅ / ❌ / ⏭️). |
4 | 8 | # |
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 |
10 | 13 | # |
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. |
15 | 17 | # |
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. |
21 | 20 |
|
22 | 21 | on: |
23 | 22 | push: |
24 | 23 | branches: |
25 | | - - 'test/slack-notify-**' # auto-run on the PoC branch — no default-branch dependency |
| 24 | + - 'test/slack-notify-**' |
26 | 25 | workflow_dispatch: |
27 | 26 | inputs: |
28 | 27 | channel_id: |
29 | | - description: 'Slack channel ID to post to' |
| 28 | + description: 'Slack channel ID to post the demo messages to' |
30 | 29 | required: false |
31 | 30 | 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 |
47 | 31 |
|
48 | 32 | permissions: |
49 | | - contents: write |
| 33 | + contents: read |
50 | 34 |
|
51 | 35 | concurrency: |
52 | 36 | group: release-slack-notify-test |
53 | 37 | cancel-in-progress: false |
54 | 38 |
|
55 | 39 | 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 |
59 | 41 |
|
60 | 42 | jobs: |
61 | | - notify: |
| 43 | + demo: |
62 | 44 | runs-on: ubuntu-latest |
63 | 45 | 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. |
64 | 48 | - uses: actions/checkout@v4 |
65 | 49 | with: |
66 | 50 | ref: main |
67 | 51 | fetch-depth: 0 |
68 | 52 |
|
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 |
111 | 54 | env: |
112 | 55 | 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 |
0 commit comments