|
| 1 | +name: Release Notes Slack Notification |
| 2 | + |
| 3 | +on: |
| 4 | + page_build: |
| 5 | + # This event triggers when GitHub Pages finishes building |
| 6 | + workflow_dispatch: |
| 7 | + # This allows manual triggering of the workflow |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'Version to notify about (optional - will use latest if not specified)' |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + message: |
| 14 | + description: 'Custom message to include in the notification (optional)' |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + |
| 18 | +jobs: |
| 19 | + notify-slack: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Get latest release info |
| 27 | + id: release-info |
| 28 | + run: | |
| 29 | + # Check if manifest.json exists |
| 30 | + if [ ! -f "release-notes/manifest.json" ]; then |
| 31 | + echo "❌ manifest.json not found" |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + |
| 35 | + # Get the latest release note file from manifest.json |
| 36 | + LATEST_FILE=$(jq -r '.files[-1]' release-notes/manifest.json) |
| 37 | + |
| 38 | + if [ "$LATEST_FILE" = "null" ] || [ -z "$LATEST_FILE" ]; then |
| 39 | + echo "❌ No release files found in manifest" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + |
| 43 | + echo "latest_file=$LATEST_FILE" >> $GITHUB_OUTPUT |
| 44 | + echo "✅ Latest file: $LATEST_FILE" |
| 45 | + |
| 46 | + # Extract version from filename |
| 47 | + # Handle both formats: release-notes-v0.1.107.html and release-notes-v24-release-note-agent.html |
| 48 | + VERSION=$(echo "$LATEST_FILE" | sed -n 's/release-notes-\(.*\)\.html/\1/p') |
| 49 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 50 | + echo "✅ Version: $VERSION" |
| 51 | + |
| 52 | + # Get repository info |
| 53 | + REPO_NAME="${{ github.repository }}" |
| 54 | + REPO_SHORT_NAME="${{ github.event.repository.name }}" |
| 55 | + echo "repo_name=$REPO_NAME" >> $GITHUB_OUTPUT |
| 56 | + echo "repo_short_name=$REPO_SHORT_NAME" >> $GITHUB_OUTPUT |
| 57 | + |
| 58 | + # Get GitHub Pages URL |
| 59 | + REPO_OWNER="${{ github.repository_owner }}" |
| 60 | + |
| 61 | + # Try to determine the correct Pages URL format |
| 62 | + # For user/org pages: username.github.io |
| 63 | + # For project pages: username.github.io/repo-name |
| 64 | + if [ "$REPO_SHORT_NAME" = "${REPO_OWNER}.github.io" ]; then |
| 65 | + PAGES_URL="https://${REPO_OWNER}.github.io" |
| 66 | + else |
| 67 | + PAGES_URL="https://${REPO_OWNER}.github.io/${REPO_SHORT_NAME}" |
| 68 | + fi |
| 69 | + |
| 70 | + echo "pages_url=$PAGES_URL" >> $GITHUB_OUTPUT |
| 71 | + echo "✅ Pages URL: $PAGES_URL" |
| 72 | + |
| 73 | + # Specific release note URL |
| 74 | + RELEASE_NOTE_URL="${PAGES_URL}/release-notes/${LATEST_FILE}" |
| 75 | + echo "release_note_url=$RELEASE_NOTE_URL" >> $GITHUB_OUTPUT |
| 76 | + echo "✅ Release note URL: $RELEASE_NOTE_URL" |
| 77 | + |
| 78 | + # GitHub changelog URL |
| 79 | + CHANGELOG_URL="https://github.com/${REPO_NAME}/releases" |
| 80 | + echo "changelog_url=$CHANGELOG_URL" >> $GITHUB_OUTPUT |
| 81 | + echo "✅ Changelog URL: $CHANGELOG_URL" |
| 82 | + |
| 83 | + # Get build timestamp |
| 84 | + BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 85 | + echo "build_time=$BUILD_TIME" >> $GITHUB_OUTPUT |
| 86 | +
|
| 87 | + - name: Send Modern Slack Notification |
| 88 | + id: slack_notification |
| 89 | + run: | |
| 90 | + VERSION="${{ steps.release-info.outputs.version }}" |
| 91 | + REPO_NAME="${{ steps.release-info.outputs.repo_name }}" |
| 92 | + REPO_SHORT_NAME="${{ steps.release-info.outputs.repo_short_name }}" |
| 93 | + PAGES_URL="${{ steps.release-info.outputs.pages_url }}" |
| 94 | + RELEASE_NOTE_URL="${{ steps.release-info.outputs.release_note_url }}" |
| 95 | + CHANGELOG_URL="${{ steps.release-info.outputs.changelog_url }}" |
| 96 | + BUILD_TIME="${{ steps.release-info.outputs.build_time }}" |
| 97 | + ACTOR="${{ github.actor }}" |
| 98 | +
|
| 99 | + # Debug prints |
| 100 | + echo "VERSION=$VERSION" |
| 101 | + echo "REPO_NAME=$REPO_NAME" |
| 102 | + echo "PAGES_URL=$PAGES_URL" |
| 103 | + echo "RELEASE_NOTE_URL=$RELEASE_NOTE_URL" |
| 104 | + echo "ACTOR=$ACTOR" |
| 105 | +
|
| 106 | + # Create modern Slack Block Kit message |
| 107 | + slack_message=$(jq -n --arg repo "$REPO_SHORT_NAME" \ |
| 108 | + --arg version "$VERSION" \ |
| 109 | + --arg pages_url "$PAGES_URL" \ |
| 110 | + --arg release_url "$RELEASE_NOTE_URL" \ |
| 111 | + --arg changelog_url "$CHANGELOG_URL" \ |
| 112 | + --arg actor "$ACTOR" \ |
| 113 | + --arg build_time "$BUILD_TIME" \ |
| 114 | + '{ |
| 115 | + blocks: [ |
| 116 | + { |
| 117 | + type: "header", |
| 118 | + text: { |
| 119 | + type: "plain_text", |
| 120 | + text: "📋 New Release Notes Published: \($repo) \($version) by @\($actor)", |
| 121 | + emoji: true |
| 122 | + } |
| 123 | + }, |
| 124 | + { |
| 125 | + type: "section", |
| 126 | + text: { |
| 127 | + type: "mrkdwn", |
| 128 | + text: "🚀 GitHub Pages has finished building! The latest release notes are now live." |
| 129 | + } |
| 130 | + }, |
| 131 | + { |
| 132 | + type: "section", |
| 133 | + fields: [ |
| 134 | + { |
| 135 | + type: "mrkdwn", |
| 136 | + text: "*📋 All Release Notes:*\n<\($pages_url)|View Complete Index>" |
| 137 | + }, |
| 138 | + { |
| 139 | + type: "mrkdwn", |
| 140 | + text: "*🆕 Latest Release:*\n<\($release_url)|Version \($version)>" |
| 141 | + }, |
| 142 | + { |
| 143 | + type: "mrkdwn", |
| 144 | + text: "*📝 GitHub Releases:*\n<\($changelog_url)|View on GitHub>" |
| 145 | + }, |
| 146 | + { |
| 147 | + type: "mrkdwn", |
| 148 | + text: "*🕐 Build Time:*\n\($build_time)" |
| 149 | + } |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + type: "section", |
| 154 | + text: { |
| 155 | + type: "mrkdwn", |
| 156 | + text: "💡 *Quick Access:* Bookmark <\($pages_url)|the release notes index> for easy access to all versions." |
| 157 | + } |
| 158 | + }, |
| 159 | + { |
| 160 | + type: "context", |
| 161 | + elements: [ |
| 162 | + { |
| 163 | + type: "mrkdwn", |
| 164 | + text: "🤖 Qodo CLI Release System | <https://github.com/\($repo)|Repository>" |
| 165 | + } |
| 166 | + ] |
| 167 | + } |
| 168 | + ] |
| 169 | + }') |
| 170 | +
|
| 171 | + echo "Sending Slack notification..." |
| 172 | + response=$(curl -s -X POST -H 'Content-type: application/json' --data "$slack_message" "$SLACK_WEBHOOK_URL") |
| 173 | + echo "Slack response: $response" |
| 174 | +
|
| 175 | + # Check if the response is "ok" (webhook success) |
| 176 | + if [ "$response" = "ok" ]; then |
| 177 | + echo "✅ Slack notification sent successfully" |
| 178 | + echo "SLACK_NOTIFICATION_SENT=true" >> $GITHUB_OUTPUT |
| 179 | + else |
| 180 | + echo "⚠️ Warning: Unexpected Slack response: $response" |
| 181 | + echo "SLACK_NOTIFICATION_SENT=false" >> $GITHUB_OUTPUT |
| 182 | + # Don't fail the job, just warn |
| 183 | + fi |
| 184 | + env: |
| 185 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 186 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 187 | + |
| 188 | + - name: Fallback Slack notification |
| 189 | + if: steps.slack_notification.outputs.SLACK_NOTIFICATION_SENT != 'true' |
| 190 | + uses: rtCamp/action-slack-notify@v2 |
| 191 | + env: |
| 192 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 193 | + SLACK_TITLE: "📋 Release Notes Website - Version ${{ steps.release-info.outputs.version }}" |
| 194 | + SLACK_MESSAGE: | |
| 195 | + 🚀 New release notes have been published by @${{ github.actor }}! |
| 196 | + |
| 197 | + 📋 **All Release Notes**: ${{ steps.release-info.outputs.pages_url }} |
| 198 | + 🆕 **Latest Release**: ${{ steps.release-info.outputs.release_note_url }} |
| 199 | + 📝 **GitHub Changelog**: ${{ steps.release-info.outputs.changelog_url }} |
| 200 | + 🏗️ **Repository**: https://github.com/${{ steps.release-info.outputs.repo_name }} |
| 201 | + 🕐 **Build Time**: ${{ steps.release-info.outputs.build_time }} |
| 202 | + |
| 203 | + 💡 Bookmark the release notes index for easy access to all versions. |
| 204 | + SLACK_COLOR: good |
| 205 | + SLACK_FOOTER: "Qodo CLI Release System" |
| 206 | + |
| 207 | + - name: Debug information (on failure) |
| 208 | + if: failure() |
| 209 | + run: | |
| 210 | + echo "🔍 Debug Information:" |
| 211 | + echo "Repository: ${{ github.repository }}" |
| 212 | + echo "Repository Owner: ${{ github.repository_owner }}" |
| 213 | + echo "Repository Name: ${{ github.event.repository.name }}" |
| 214 | + echo "Actor: ${{ github.actor }}" |
| 215 | + echo "Event: ${{ github.event_name }}" |
| 216 | + echo "Slack notification sent: ${{ steps.slack_notification.outputs.SLACK_NOTIFICATION_SENT }}" |
| 217 | + echo "" |
| 218 | + echo "📁 Directory contents:" |
| 219 | + ls -la |
| 220 | + echo "" |
| 221 | + echo "📄 Release notes directory:" |
| 222 | + ls -la release-notes/ || echo "release-notes directory not found" |
| 223 | + echo "" |
| 224 | + echo "📋 Manifest content:" |
| 225 | + cat release-notes/manifest.json || echo "manifest.json not found" |
0 commit comments