workflows: replace Ilshidur/action-discord with inline github-script

Replace the third-party Discord notification action with inline
`actions/github-script@v8` steps that post to the Discord webhook
directly using fetch. This removes a third-party action dependency
and adds explicit error handling for missing secrets and failed
webhook requests.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-28 13:07:38 +01:00
parent 781815fd25
commit 18c928175d
2 changed files with 50 additions and 6 deletions
+33 -4
View File
@@ -125,11 +125,26 @@ jobs:
- name: Discord notification
if: ${{ failure() }}
uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554 # 0.4.0
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
with:
args: 'Master build failed https://github.com/{{GITHUB_REPOSITORY}}/actions/runs/{{GITHUB_RUN_ID}}'
script: |
const webhook = process.env.DISCORD_WEBHOOK;
if (!webhook) {
throw new Error('DISCORD_WEBHOOK secret is not set');
}
const repo = context.repo.owner + '/' + context.repo.repo;
const runId = context.runId;
const message = `Master build failed https://github.com/${repo}/actions/runs/${runId}`;
const response = await fetch(webhook, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: message }),
});
if (!response.ok) {
throw new Error(`Discord webhook request failed: ${response.status} ${response.statusText}`);
}
# A separate release build that is only run for commits that are the result of merging the "Version Packages" PR
# We can't re-use the output from the above step, but we'll have a guaranteed node_modules cache and
@@ -153,8 +168,22 @@ jobs:
# Notify maintainers that a new release is ready to be published
- name: Discord notification
uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554 # 0.4.0
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_MAINTAINERS_WEBHOOK }}
with:
args: 'A new release is ready to be [published](https://github.com/backstage/publishing/actions/workflows/publish-main.yml) from {{GITHUB_SHA}}'
script: |
const webhook = process.env.DISCORD_WEBHOOK;
if (!webhook) {
throw new Error('DISCORD_MAINTAINERS_WEBHOOK secret is not set');
}
const sha = context.sha;
const message = `A new release is ready to be [published](https://github.com/backstage/publishing/actions/workflows/publish-main.yml) from ${sha}`;
const response = await fetch(webhook, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: message }),
});
if (!response.ok) {
throw new Error(`Discord webhook request failed: ${response.status} ${response.statusText}`);
}
+17 -2
View File
@@ -49,8 +49,23 @@ jobs:
- name: Discord notification
if: ${{ failure() }}
uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554 # 0.4.0
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
with:
args: 'Version Packages Sync Failed https://github.com/{{GITHUB_REPOSITORY}}/actions/runs/{{GITHUB_RUN_ID}}'
script: |
const webhook = process.env.DISCORD_WEBHOOK;
if (!webhook) {
throw new Error('DISCORD_WEBHOOK secret is not set');
}
const repo = context.repo.owner + '/' + context.repo.repo;
const runId = context.runId;
const message = `Version Packages Sync Failed https://github.com/${repo}/actions/runs/${runId}`;
const response = await fetch(webhook, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: message }),
});
if (!response.ok) {
throw new Error(`Discord webhook request failed: ${response.status} ${response.statusText}`);
}