Skip to content

Commit

Permalink
[DX-2341] Notify SDK Slack with Publish Status (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSchwert committed Oct 6, 2023
1 parent 36855bf commit 6f5a1d9
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/actions/notify-slack-publish-status/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Slack Notify
11 changes: 11 additions & 0 deletions .github/actions/notify-slack-publish-status/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: 'Notify Slack Publish Status'
description: 'Notify Slack with the completion status of the publish action'
inputs:
message:
description: 'Message to send to Slack'
required: true
default: ''
runs:
using: 'node20'
main: 'index.js'
52 changes: 52 additions & 0 deletions .github/actions/notify-slack-publish-status/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const core = require('@actions/core');
const webhook = process.env.SDK_PUBLISH_SLACK_WEBHOOK;

const run = async () => {
if (webhook) {
try {
await postSlackNotification();
} catch (e) {
console.log(e);
throw new Error(`failed because : ${e}`)
}
} else {
throw new Error('No SDK_PUBLISH_SLACK_WEBHOOK environment variable found');
}
}

const postSlackNotification = async () => {
const message = core.getInput('message');

if (!message) {
throw new Error('No message input found');
}

const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: message,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: message,
}
}
]
}),
};

const response = await fetch(webhook, options);

if (response.status == 200) {
console.log('Posted message to Slack successfully');
} else {
throw new Error(`Failed to post message to Slack. Status code: ${response.status}`);
}
}

run();
5 changes: 3 additions & 2 deletions .github/scripts/push-docs-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ then
sleep 60

echo "Creating a pull request"
gh pr create --title "Release SDK reference docs v$VERSION" \
PR=$(gh pr create --title "Release SDK reference docs v$VERSION" \
--body "Released from ts-immutable-sdk" \
--reviewer "$GITHUB_ACTOR"
--reviewer "$GITHUB_ACTOR")
echo "PR=$PR" >> $GITHUB_ENV
else
echo "No changes detected"
fi
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.PLATFORM_SA_GITHUB_TOKEN }}
SDK_PUBLISH_SLACK_WEBHOOK: ${{ secrets.SDK_PUBLISH_SLACK_WEBHOOK }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -65,5 +66,18 @@ jobs:
run: ./.github/scripts/update-docs-link.sh

- name: Create SDK Docs PR
id: docs_pr
run: ./.github/scripts/push-docs-pr.sh
shell: bash

- name: Notify SDK Slack Docs PR Success
if: ${{ success() && steps.docs_pr.conclusion == 'success' }}
uses: ./.github/actions/notify-slack-publish-status
with:
message: "✅ SDK reference documents PR created successfully - please review and merge ${{ env.PR }} into main."

- name: Notify SDK Slack Docs PR Failure
if: ${{ failure() }}
uses: ./.github/actions/notify-slack-publish-status
with:
message: "❌ Failed to create SDK reference documents PR. Please check the logs for more details."
15 changes: 15 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.PLATFORM_SA_GITHUB_TOKEN }}
NODE_OPTIONS: --max-old-space-size=14366
SDK_PUBLISH_SLACK_WEBHOOK: ${{ secrets.SDK_PUBLISH_SLACK_WEBHOOK }}
steps:
- name: Check Public Release Branch
if: contains(github.event.inputs.release_type, 'release') && (github.ref != 'refs/heads/main')
Expand Down Expand Up @@ -106,6 +107,7 @@ jobs:
- name: Pre Release Step
if: contains(github.event.inputs.release_type, 'alpha')
id: pre_release
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.PLATFORM_SA_NPM_TOKEN }}
Expand All @@ -119,6 +121,7 @@ jobs:
run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.PLATFORM_SA_NPM_TOKEN }}

- name: Release
id: npm_release
if: contains(github.event.inputs.release_type, 'release')
run: yarn release --ci --no-increment -c .release-it.json $( ${{ github.event.inputs.dry_run }} && echo "--dry-run" || echo "") --github.tokenRef=${{ secrets.RELEASE_TOKEN }}

Expand All @@ -132,3 +135,15 @@ jobs:
run: |
echo "RELEASE_NAME=$(gh release view --json name | jq -r .name)" >> $GITHUB_OUTPUT
echo "RELEASE_URL=$(gh release view --json url | jq -r .url)" >> $GITHUB_OUTPUT
- name: Notify SDK Slack Publish Success
if: ${{ success() && (steps.npm_release.conclusion == 'success' || steps.pre_release.conclusion == 'success') && github.event.inputs.dry_run == 'false' }}
uses: ./.github/actions/notify-slack-publish-status
with:
message: "✅ Successfully published SDK version ${{steps.version.outputs.NEXT_VERSION}} to NPM.\n\nhttps://www.npmjs.com/package/@imtbl/sdk/v/${{steps.version.outputs.NEXT_VERSION}}"

- name: Notify SDK Slack Publish Failure
if: ${{ failure() && (steps.npm_release.conclusion == 'failure' || steps.pre_release.conclusion == 'failure') && github.event.inputs.dry_run == 'false' }}
uses: ./.github/actions/notify-slack-publish-status
with:
message: "❌ Failed to publish SDK version ${{steps.version.outputs.NEXT_VERSION}} to NPM. Please check the logs for more details."
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "Immutable",
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
"devDependencies": {
"@actions/core": "^1.10.1",
"@release-it-plugins/workspaces": "^3.2.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ __metadata:
languageName: node
linkType: hard

"@actions/core@npm:^1.10.1":
version: 1.10.1
resolution: "@actions/core@npm:1.10.1"
dependencies:
"@actions/http-client": ^2.0.1
uuid: ^8.3.2
checksum: 96524c2725e70e3c3176b4e4d93a1358a86f3c5ca777db9a2f65eadfa672f00877db359bf60fffc416c33838ffb4743db93bcc5bf53e76199dd28bf7f7ff8e80
languageName: node
linkType: hard

"@actions/http-client@npm:^2.0.1":
version: 2.1.1
resolution: "@actions/http-client@npm:2.1.1"
dependencies:
tunnel: ^0.0.6
checksum: 5a3fd0407020a11cd3864b6c9ed8ef36912e08418df34fac675d15fc71543abb419db236ddb8fbd649f8ad8b5057bd78f1ac301f87283dfc706aa85578a90658
languageName: node
linkType: hard

"@adobe/css-tools@npm:^4.0.1":
version: 4.2.0
resolution: "@adobe/css-tools@npm:4.2.0"
Expand Down Expand Up @@ -28865,6 +28884,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "ts-immutable-sdk@workspace:."
dependencies:
"@actions/core": ^1.10.1
"@release-it-plugins/workspaces": ^3.2.0
"@typescript-eslint/eslint-plugin": ^5.57.1
"@typescript-eslint/parser": ^5.57.1
Expand Down

0 comments on commit 6f5a1d9

Please sign in to comment.