0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

chore(ci): fix release announcement script (#9796)

This commit is contained in:
Nate Moore 2024-01-23 15:28:28 -06:00 committed by GitHub
parent 5994a901e8
commit e6c0fa5c33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 99 additions and 39 deletions

View file

@ -1,6 +1,7 @@
import { globby as glob } from 'globby'; import { globby as glob } from 'globby';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { readFile } from 'node:fs/promises'; import { readFile } from 'node:fs/promises';
import { setOutput } from './utils.mjs';
const { GITHUB_REF = 'main' } = process.env; const { GITHUB_REF = 'main' } = process.env;
const baseUrl = new URL(`https://github.com/withastro/astro/blob/${GITHUB_REF}/`); const baseUrl = new URL(`https://github.com/withastro/astro/blob/${GITHUB_REF}/`);
@ -17,34 +18,34 @@ const descriptors = [
'updates', 'updates',
]; ];
const verbs = [ const verbs = [
'just went out!', "just went out!",
'just launched!', "just launched!",
'now available!', "now available!",
'in the wild!', "in the wild!",
'now live!', "now live!",
'hit the registry!', "hit the registry!",
'to share!', "to share!",
'for you!', "for you!",
'for yall! 🤠', "for yall! 🤠",
'comin your way!', "comin your way!",
'comin atcha!', "comin atcha!",
'comin in hot!', "comin in hot!",
'freshly minted on the blockchain! (jk)', "freshly minted on the blockchain! (jk)",
'[is] out (now with 100% more reticulated splines!)', "[is] out (now with 100% more reticulated splines!)",
'(as seen on TV!)', "(as seen on TV!)",
'just dropped!', "just dropped!",
' artisanally hand-crafted just for you.', " artisanally hand-crafted just for you.",
' oh happy day!', " oh happy day!",
' enjoy!', " enjoy!",
'now out. Be the first on your block to download!', "now out. Be the first on your block to download!",
'made with love 💕', "made with love 💕",
'[is] out! Our best [version] yet!', "[is] out! Our best [version] yet!",
'[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!', "[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!",
'... HUZZAH!', "... HUZZAH!",
'[has] landed!', "[has] landed!",
'landed! The internet just got a little more fun.', "landed! The internet just got a little more fun.",
' from our family to yours.', " from our family to yours.",
' go forth and build!', " go forth and build!"
]; ];
const extraVerbs = [ const extraVerbs = [
'new', 'new',
@ -162,14 +163,7 @@ async function run() {
process.exit(1); process.exit(1);
} }
const content = await generateMessage(); const content = await generateMessage();
setOutput('DISCORD_MESSAGE', content);
await fetch(`${process.env.DISCORD_WEBHOOK}?wait=true`, {
method: 'POST',
body: JSON.stringify({ content }),
headers: {
'content-type': 'application/json',
},
});
} }
run(); run();

59
.github/scripts/utils.mjs vendored Normal file
View file

@ -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)
}

View file

@ -59,9 +59,16 @@ jobs:
# Needs access to publish to npm # Needs access to publish to npm
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Generate Notification - name: Generate Announcement
id: notification id: message
if: steps.changesets.outputs.published == 'true' if: steps.changesets.outputs.published == 'true'
env: env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} 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/action-discord@0.3.2
with:
args: "${{ steps.message.outputs.DISCORD_MESSAGE }}"