-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): fix release announcement script
- Loading branch information
1 parent
5994a90
commit f484ef7
Showing
3 changed files
with
99 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as fs from 'node:fs' | ||
import * as os from 'node:os' | ||
import * as crypto from 'node:crypto' | ||
|
||
/** Based on https://github.com/actions/toolkit/blob/4e3b068ce116d28cb840033c02f912100b4592b0/packages/core/src/file-command.ts */ | ||
export function setOutput(key, value) { | ||
const filePath = process.env['GITHUB_OUTPUT'] || '' | ||
if (filePath) { | ||
return issueFileCommand('OUTPUT', prepareKeyValueMessage(key, value)) | ||
} | ||
process.stdout.write(os.EOL) | ||
} | ||
|
||
function issueFileCommand(command, message) { | ||
const filePath = process.env[`GITHUB_${command}`] | ||
if (!filePath) { | ||
throw new Error( | ||
`Unable to find environment variable for file command ${command}` | ||
) | ||
} | ||
if (!fs.existsSync(filePath)) { | ||
throw new Error(`Missing file at path: ${filePath}`) | ||
} | ||
|
||
fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, { | ||
encoding: 'utf8' | ||
}) | ||
} | ||
|
||
function prepareKeyValueMessage(key, value) { | ||
const delimiter = `gh-delimiter-${crypto.randomUUID()}` | ||
const convertedValue = toCommandValue(value) | ||
|
||
// These should realistically never happen, but just in case someone finds a | ||
// way to exploit uuid generation let's not allow keys or values that contain | ||
// the delimiter. | ||
if (key.includes(delimiter)) { | ||
throw new Error( | ||
`Unexpected input: name should not contain the delimiter "${delimiter}"` | ||
) | ||
} | ||
|
||
if (convertedValue.includes(delimiter)) { | ||
throw new Error( | ||
`Unexpected input: value should not contain the delimiter "${delimiter}"` | ||
) | ||
} | ||
|
||
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}` | ||
} | ||
|
||
function toCommandValue(input) { | ||
if (input === null || input === undefined) { | ||
return '' | ||
} else if (typeof input === 'string' || input instanceof String) { | ||
return input | ||
} | ||
return JSON.stringify(input) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,16 @@ jobs: | |
# Needs access to publish to npm | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Generate Notification | ||
id: notification | ||
- name: Generate Announcement | ||
id: message | ||
if: steps.changesets.outputs.published == 'true' | ||
env: | ||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | ||
run: node scripts/notify/index.js '${{ steps.changesets.outputs.publishedPackages }}' | ||
run: node .github/scripts/announce.mjs '${{ steps.changesets.outputs.publishedPackages }}' | ||
|
||
- name: Send message on Discord | ||
env: | ||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | ||
uses: Ilshidur/[email protected] | ||
with: | ||
args: "${{ steps.message.outputs.DISCORD_MESSAGE }}" |