Skip to content

Commit a630042

Browse files
Add slack notification when release notes website published
1 parent 5a35638 commit a630042

File tree

2 files changed

+333
-0
lines changed

2 files changed

+333
-0
lines changed

.github/workflows/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# GitHub Actions Workflows
2+
3+
## Pages Build Notification
4+
5+
This workflow (`pages-build-notification.yml`) automatically sends a Slack notification whenever GitHub Pages finishes building your site after a new release note is added.
6+
7+
### Features
8+
9+
- 🚀 Triggers automatically when GitHub Pages build completes
10+
- 📱 Sends rich Slack notifications with all relevant links
11+
- 🔗 Includes links to:
12+
- The specific new release note
13+
- The complete release notes index page
14+
- GitHub changelog/releases page
15+
- The repository
16+
- 🛡️ Robust error handling and fallback notification methods
17+
- 🐛 Debug information for troubleshooting
18+
19+
### Setup Instructions
20+
21+
#### 1. Create a Slack Webhook
22+
23+
1. Go to your Slack workspace
24+
2. Navigate to **Apps****Incoming Webhooks**
25+
3. Click **Add to Slack**
26+
4. Choose the channel where you want notifications
27+
5. Copy the webhook URL
28+
29+
#### 2. Add Slack Webhook to GitHub Secrets
30+
31+
1. Go to your GitHub repository
32+
2. Navigate to **Settings****Secrets and variables****Actions**
33+
3. Click **New repository secret**
34+
4. Name: `SLACK_WEBHOOK_URL`
35+
5. Value: Your Slack webhook URL
36+
6. Click **Add secret**
37+
38+
#### 3. Enable GitHub Pages (if not already enabled)
39+
40+
1. Go to **Settings****Pages**
41+
2. Select your source (usually `main` branch)
42+
3. Save the configuration
43+
44+
### How It Works
45+
46+
1. **Trigger**: The workflow triggers on the `page_build` event, which fires when GitHub Pages finishes building
47+
2. **Data Extraction**: It reads your `release-notes/manifest.json` to find the latest release note
48+
3. **URL Generation**: It constructs URLs for:
49+
- Your GitHub Pages site index
50+
- The specific release note
51+
- GitHub releases page
52+
4. **Notification**: Sends a formatted Slack message with all the information
53+
54+
### Notification Format
55+
56+
The Slack notification includes:
57+
58+
```
59+
🚀 GitHub Pages Build Complete
60+
Release Notes Published - Version [VERSION]
61+
62+
📋 All Release Notes: [Link to index.html]
63+
📝 GitHub Changelog: [Link to GitHub releases]
64+
🆕 Latest Release Note: [Link to specific release note]
65+
🏗️ Repository: [Link to repository]
66+
Build Time: [Timestamp]
67+
```
68+
69+
### Troubleshooting
70+
71+
If the workflow fails:
72+
73+
1. Check the **Actions** tab in your GitHub repository
74+
2. Look at the workflow run logs for error messages
75+
3. The workflow includes debug information that will show:
76+
- Repository information
77+
- Directory contents
78+
- Manifest file contents
79+
80+
### Customization
81+
82+
You can customize the workflow by:
83+
84+
- **Changing the Slack message format**: Edit the `custom_payload` section
85+
- **Adding more information**: Extract additional data from your release notes
86+
- **Changing notification conditions**: Modify the trigger conditions
87+
- **Adding other notification channels**: Add steps for email, Discord, etc.
88+
89+
### File Structure Expected
90+
91+
The workflow expects this structure:
92+
```
93+
/
94+
├── index.html (GitHub Pages index)
95+
├── release-notes/
96+
│ ├── manifest.json
97+
│ ├── release-notes-v1.0.0.html
98+
│ └── release-notes-v1.1.0.html
99+
└── .github/
100+
└── workflows/
101+
└── pages-build-notification.yml
102+
```
103+
104+
### Manifest.json Format
105+
106+
Your `manifest.json` should look like:
107+
```json
108+
{
109+
"files": [
110+
"release-notes-v1.0.0.html",
111+
"release-notes-v1.1.0.html"
112+
],
113+
"lastUpdated": "2025-01-01T12:00:00.000Z",
114+
"description": "Manifest file for release notes",
115+
"count": 2
116+
}
117+
```
118+
119+
The workflow will use the last file in the `files` array as the latest release.
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
name: Release Notes Slack Notification
2+
3+
on:
4+
page_build:
5+
# This event triggers when GitHub Pages finishes building
6+
7+
jobs:
8+
notify-slack:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Get latest release info
16+
id: release-info
17+
run: |
18+
# Check if manifest.json exists
19+
if [ ! -f "release-notes/manifest.json" ]; then
20+
echo "❌ manifest.json not found"
21+
exit 1
22+
fi
23+
24+
# Get the latest release note file from manifest.json
25+
LATEST_FILE=$(jq -r '.files[-1]' release-notes/manifest.json)
26+
27+
if [ "$LATEST_FILE" = "null" ] || [ -z "$LATEST_FILE" ]; then
28+
echo "❌ No release files found in manifest"
29+
exit 1
30+
fi
31+
32+
echo "latest_file=$LATEST_FILE" >> $GITHUB_OUTPUT
33+
echo "✅ Latest file: $LATEST_FILE"
34+
35+
# Extract version from filename
36+
# Handle both formats: release-notes-v0.1.107.html and release-notes-v24-release-note-agent.html
37+
VERSION=$(echo "$LATEST_FILE" | sed -n 's/release-notes-\(.*\)\.html/\1/p')
38+
echo "version=$VERSION" >> $GITHUB_OUTPUT
39+
echo "✅ Version: $VERSION"
40+
41+
# Get repository info
42+
REPO_NAME="${{ github.repository }}"
43+
REPO_SHORT_NAME="${{ github.event.repository.name }}"
44+
echo "repo_name=$REPO_NAME" >> $GITHUB_OUTPUT
45+
echo "repo_short_name=$REPO_SHORT_NAME" >> $GITHUB_OUTPUT
46+
47+
# Get GitHub Pages URL
48+
REPO_OWNER="${{ github.repository_owner }}"
49+
50+
# Try to determine the correct Pages URL format
51+
# For user/org pages: username.github.io
52+
# For project pages: username.github.io/repo-name
53+
if [ "$REPO_SHORT_NAME" = "${REPO_OWNER}.github.io" ]; then
54+
PAGES_URL="https://${REPO_OWNER}.github.io"
55+
else
56+
PAGES_URL="https://${REPO_OWNER}.github.io/${REPO_SHORT_NAME}"
57+
fi
58+
59+
echo "pages_url=$PAGES_URL" >> $GITHUB_OUTPUT
60+
echo "✅ Pages URL: $PAGES_URL"
61+
62+
# Specific release note URL
63+
RELEASE_NOTE_URL="${PAGES_URL}/release-notes/${LATEST_FILE}"
64+
echo "release_note_url=$RELEASE_NOTE_URL" >> $GITHUB_OUTPUT
65+
echo "✅ Release note URL: $RELEASE_NOTE_URL"
66+
67+
# GitHub changelog URL
68+
CHANGELOG_URL="https://github.com/${REPO_NAME}/releases"
69+
echo "changelog_url=$CHANGELOG_URL" >> $GITHUB_OUTPUT
70+
echo "✅ Changelog URL: $CHANGELOG_URL"
71+
72+
# Get build timestamp
73+
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
74+
echo "build_time=$BUILD_TIME" >> $GITHUB_OUTPUT
75+
76+
- name: Send Modern Slack Notification
77+
id: slack_notification
78+
run: |
79+
VERSION="${{ steps.release-info.outputs.version }}"
80+
REPO_NAME="${{ steps.release-info.outputs.repo_name }}"
81+
REPO_SHORT_NAME="${{ steps.release-info.outputs.repo_short_name }}"
82+
PAGES_URL="${{ steps.release-info.outputs.pages_url }}"
83+
RELEASE_NOTE_URL="${{ steps.release-info.outputs.release_note_url }}"
84+
CHANGELOG_URL="${{ steps.release-info.outputs.changelog_url }}"
85+
BUILD_TIME="${{ steps.release-info.outputs.build_time }}"
86+
ACTOR="${{ github.actor }}"
87+
88+
# Debug prints
89+
echo "VERSION=$VERSION"
90+
echo "REPO_NAME=$REPO_NAME"
91+
echo "PAGES_URL=$PAGES_URL"
92+
echo "RELEASE_NOTE_URL=$RELEASE_NOTE_URL"
93+
echo "ACTOR=$ACTOR"
94+
95+
# Create modern Slack Block Kit message
96+
slack_message=$(jq -n --arg repo "$REPO_SHORT_NAME" \
97+
--arg version "$VERSION" \
98+
--arg pages_url "$PAGES_URL" \
99+
--arg release_url "$RELEASE_NOTE_URL" \
100+
--arg changelog_url "$CHANGELOG_URL" \
101+
--arg actor "$ACTOR" \
102+
--arg build_time "$BUILD_TIME" \
103+
'{
104+
blocks: [
105+
{
106+
type: "header",
107+
text: {
108+
type: "plain_text",
109+
text: "📋 New Release Notes Published: \($repo) \($version) by @\($actor)",
110+
emoji: true
111+
}
112+
},
113+
{
114+
type: "section",
115+
text: {
116+
type: "mrkdwn",
117+
text: "🚀 GitHub Pages has finished building! The latest release notes are now live."
118+
}
119+
},
120+
{
121+
type: "section",
122+
fields: [
123+
{
124+
type: "mrkdwn",
125+
text: "*📋 All Release Notes:*\n<\($pages_url)|View Complete Index>"
126+
},
127+
{
128+
type: "mrkdwn",
129+
text: "*🆕 Latest Release:*\n<\($release_url)|Version \($version)>"
130+
},
131+
{
132+
type: "mrkdwn",
133+
text: "*📝 GitHub Releases:*\n<\($changelog_url)|View on GitHub>"
134+
},
135+
{
136+
type: "mrkdwn",
137+
text: "*🕐 Build Time:*\n\($build_time)"
138+
}
139+
]
140+
},
141+
{
142+
type: "section",
143+
text: {
144+
type: "mrkdwn",
145+
text: "💡 *Quick Access:* Bookmark <\($pages_url)|the release notes index> for easy access to all versions."
146+
}
147+
},
148+
{
149+
type: "context",
150+
elements: [
151+
{
152+
type: "mrkdwn",
153+
text: "🤖 Qodo CLI Release System | <https://github.com/\($repo)|Repository>"
154+
}
155+
]
156+
}
157+
]
158+
}')
159+
160+
echo "Sending Slack notification..."
161+
response=$(curl -s -X POST -H 'Content-type: application/json' --data "$slack_message" "$SLACK_WEBHOOK_URL")
162+
echo "Slack response: $response"
163+
164+
# Check if the response is "ok" (webhook success)
165+
if [ "$response" = "ok" ]; then
166+
echo "✅ Slack notification sent successfully"
167+
echo "SLACK_NOTIFICATION_SENT=true" >> $GITHUB_OUTPUT
168+
else
169+
echo "⚠️ Warning: Unexpected Slack response: $response"
170+
echo "SLACK_NOTIFICATION_SENT=false" >> $GITHUB_OUTPUT
171+
# Don't fail the job, just warn
172+
fi
173+
env:
174+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
175+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
177+
- name: Fallback Slack notification
178+
if: steps.slack_notification.outputs.SLACK_NOTIFICATION_SENT != 'true'
179+
uses: rtCamp/action-slack-notify@v2
180+
env:
181+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
182+
SLACK_TITLE: "📋 GitHub Pages Build Complete - Version ${{ steps.release-info.outputs.version }}"
183+
SLACK_MESSAGE: |
184+
🚀 New release notes have been published by @${{ github.actor }}!
185+
186+
📋 **All Release Notes**: ${{ steps.release-info.outputs.pages_url }}
187+
🆕 **Latest Release**: ${{ steps.release-info.outputs.release_note_url }}
188+
📝 **GitHub Changelog**: ${{ steps.release-info.outputs.changelog_url }}
189+
🏗️ **Repository**: https://github.com/${{ steps.release-info.outputs.repo_name }}
190+
🕐 **Build Time**: ${{ steps.release-info.outputs.build_time }}
191+
192+
💡 Bookmark the release notes index for easy access to all versions.
193+
SLACK_COLOR: good
194+
SLACK_FOOTER: "Qodo CLI Release System"
195+
196+
- name: Debug information (on failure)
197+
if: failure()
198+
run: |
199+
echo "🔍 Debug Information:"
200+
echo "Repository: ${{ github.repository }}"
201+
echo "Repository Owner: ${{ github.repository_owner }}"
202+
echo "Repository Name: ${{ github.event.repository.name }}"
203+
echo "Actor: ${{ github.actor }}"
204+
echo "Event: ${{ github.event_name }}"
205+
echo "Slack notification sent: ${{ steps.slack_notification.outputs.SLACK_NOTIFICATION_SENT }}"
206+
echo ""
207+
echo "📁 Directory contents:"
208+
ls -la
209+
echo ""
210+
echo "📄 Release notes directory:"
211+
ls -la release-notes/ || echo "release-notes directory not found"
212+
echo ""
213+
echo "📋 Manifest content:"
214+
cat release-notes/manifest.json || echo "manifest.json not found"

0 commit comments

Comments
 (0)