0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/scripts/notify/index.js

160 lines
4.2 KiB
JavaScript
Raw Normal View History

import { globby as glob } from 'globby';
import { fileURLToPath } from 'node:url';
2022-03-19 12:34:21 -05:00
import { readFile } from 'node:fs/promises';
const { GITHUB_REF = 'main' } = process.env;
const baseUrl = new URL(`https://github.com/withastro/astro/blob/${GITHUB_REF}/`);
Improve GitHub Actions (#2041) * chore(actions): test new CI action * chore(actions): switch action order * chore(actions): update registry * chore(actions): remove debug * chore(actions): target all packages * chore(actions): test artifacts * chore(actions): try moving artifacts * chore(actions): test moving * chore(actions): test tar approach * chore(actions): test tar approach * chore(actions): use artifacts/packages before tar * chore(actions): test mv -vn * chore(actions): mkdir first * chore(actions): how does tar work? * chore(actions): so good at bash * chore(actions): test matrix * chore(actions): fix test matrix * chore(actions): fix windows? * chore(actions): fix windows? * chore(actions): fix windows! * chore(actions): fix windows! * chore(actions): add lint * chore(actions): add back old actions * chore(actions): test notification action * chore(actions): test notification action again * chore(actions): fix extract action * chore(actions): fix action? * chore(actions): fix action? * chore(actions): fix newlines * chore(actions): test --production flag * chore(actions): test --production flag for test * chore(actions): add execa to production deps * chore(actions): add cheerio to production deps * chore(actions): add production deps for tested examples * chore(actions): fix changelog action * chore(actions): attempt to use --prefer-offline * chore(actions): revert dependencies/devDependencies change * chore(actions): update all actions * chore(actions): add smoke test * chore(actions): update changelog deps * chore(actions): move notify script * chore(actions): consolidate main scripts * chore(actions): update changelog name * chore(actions): update congratsbot * chore(actions): update ci * chore(actions): change lint/format strategy * chore(actions): expose GITHUB_TOKEN to linter * chore(actions): update lint * chore(actions): enable autofix * chore(actions): fetch-depth 0 * chore(actions): fix eslint extensions * chore(actions): debug lint * chore(actions): fix eslint args * chore(actions): fix eslint? * [ci] ESLint fix * [ci] Prettier fix * chore(actions): fix lint! * chore(actions): cleanup comments * chore(actions): fix lint * chore(actions): lint astro only * chore(actions): ignore pattern * chore(actions): no_verify * chore(actions): disable no verify * chore(actions): debug status * chore(actions): add concurrency * chore(actions): add comment about concurrency * chore(actions): make release dependent on lint * chore(actions): move lint first * chore(actions): run CI on PR or `main` only * chore(actions): remove GPR publish step * chore: add back old actions * chore: revert package.json * chore: improve changelog with GitHub info * chore(actions): try pull_request_target * debug lint * debug lint * debug lint * try pull_request_target * update pull_request_target perms * update pull_request_target * fix perms * fix run? * fix run? * fix run? (part 3) * fix run? (part 4) * fix run? (part 5) * fix run! * fix run!! * fix run!!! * fix run!!!! * fix run!!!!! * fix run!!!!!! * add comment about forks Co-authored-by: GitHub Actions <actions-user@github.com>
2021-11-29 16:11:15 -05:00
const emojis = ['🎉', '🥳', '🚀', '🧑‍🚀', '🎊', '🏆', '✅', '🤩', '🤖', '🙌'];
2022-04-02 15:15:41 -05:00
const descriptors = [
'new releases',
'hot and fresh updates',
'shiny updates',
'exciting changes',
'package updates',
'awesome updates',
'bug fixes and features',
'updates',
];
const verbs = [
2021-12-22 16:11:05 -05:00
'just went out!',
'just launched!',
'now available!',
'in the wild!',
'now live!',
'hit the registry!',
'to share!',
'for you!',
'for yall! 🤠',
'comin your way!',
'comin atcha!',
'comin in hot!',
'freshly minted on the blockchain! (jk)',
'[is] out (now with 100% more reticulated splines!)',
'(as seen on TV!)',
'just dropped!',
' artisanally hand-crafted just for you.',
' oh happy day!',
' enjoy!',
'now out. Be the first on your block to download!',
'made with love 💕',
'[is] out! Our best [version] yet!',
'[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!',
'... HUZZAH!',
'[has] landed!',
'landed! The internet just got a little more fun.',
' from our family to yours.',
' go forth and build!',
];
const extraVerbs = [
'new',
'here',
'released',
'freshly made',
'going out',
'hitting the registry',
'available',
'live now',
'hot and fresh',
'for you',
2023-01-12 16:28:30 -05:00
"comin' atcha",
];
function item(items) {
2021-12-22 16:11:05 -05:00
return items[Math.floor(Math.random() * items.length)];
}
2021-12-07 17:08:49 -05:00
const plurals = new Map([
2021-12-22 16:11:05 -05:00
['is', 'are'],
['has', 'have'],
2021-12-07 17:09:46 -05:00
]);
2021-12-07 17:08:49 -05:00
function pluralize(text) {
2022-04-02 15:15:41 -05:00
return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) =>
plurals.has(match) ? plurals.get(match) : `${match}s`
);
2021-12-07 17:08:49 -05:00
}
function singularlize(text) {
2021-12-22 16:11:05 -05:00
return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => `${match}`);
2021-12-07 17:08:49 -05:00
}
const packageMap = new Map();
async function generatePackageMap() {
const packageRoot = new URL('../../packages/', import.meta.url);
2022-04-02 15:15:41 -05:00
const packages = await glob(['*/package.json', '*/*/package.json'], {
cwd: fileURLToPath(packageRoot),
});
2022-03-19 12:34:21 -05:00
await Promise.all(
packages.map(async (pkg) => {
const pkgFile = fileURLToPath(new URL(pkg, packageRoot));
const content = await readFile(pkgFile).then((res) => JSON.parse(res.toString()));
packageMap.set(content.name, `./packages/${pkg.replace('/package.json', '')}`);
})
);
}
2022-03-08 11:48:12 -05:00
Improve GitHub Actions (#2041) * chore(actions): test new CI action * chore(actions): switch action order * chore(actions): update registry * chore(actions): remove debug * chore(actions): target all packages * chore(actions): test artifacts * chore(actions): try moving artifacts * chore(actions): test moving * chore(actions): test tar approach * chore(actions): test tar approach * chore(actions): use artifacts/packages before tar * chore(actions): test mv -vn * chore(actions): mkdir first * chore(actions): how does tar work? * chore(actions): so good at bash * chore(actions): test matrix * chore(actions): fix test matrix * chore(actions): fix windows? * chore(actions): fix windows? * chore(actions): fix windows! * chore(actions): fix windows! * chore(actions): add lint * chore(actions): add back old actions * chore(actions): test notification action * chore(actions): test notification action again * chore(actions): fix extract action * chore(actions): fix action? * chore(actions): fix action? * chore(actions): fix newlines * chore(actions): test --production flag * chore(actions): test --production flag for test * chore(actions): add execa to production deps * chore(actions): add cheerio to production deps * chore(actions): add production deps for tested examples * chore(actions): fix changelog action * chore(actions): attempt to use --prefer-offline * chore(actions): revert dependencies/devDependencies change * chore(actions): update all actions * chore(actions): add smoke test * chore(actions): update changelog deps * chore(actions): move notify script * chore(actions): consolidate main scripts * chore(actions): update changelog name * chore(actions): update congratsbot * chore(actions): update ci * chore(actions): change lint/format strategy * chore(actions): expose GITHUB_TOKEN to linter * chore(actions): update lint * chore(actions): enable autofix * chore(actions): fetch-depth 0 * chore(actions): fix eslint extensions * chore(actions): debug lint * chore(actions): fix eslint args * chore(actions): fix eslint? * [ci] ESLint fix * [ci] Prettier fix * chore(actions): fix lint! * chore(actions): cleanup comments * chore(actions): fix lint * chore(actions): lint astro only * chore(actions): ignore pattern * chore(actions): no_verify * chore(actions): disable no verify * chore(actions): debug status * chore(actions): add concurrency * chore(actions): add comment about concurrency * chore(actions): make release dependent on lint * chore(actions): move lint first * chore(actions): run CI on PR or `main` only * chore(actions): remove GPR publish step * chore: add back old actions * chore: revert package.json * chore: improve changelog with GitHub info * chore(actions): try pull_request_target * debug lint * debug lint * debug lint * try pull_request_target * update pull_request_target perms * update pull_request_target * fix perms * fix run? * fix run? * fix run? (part 3) * fix run? (part 4) * fix run? (part 5) * fix run! * fix run!! * fix run!!! * fix run!!!! * fix run!!!!! * fix run!!!!!! * add comment about forks Co-authored-by: GitHub Actions <actions-user@github.com>
2021-11-29 16:11:15 -05:00
async function run() {
await generatePackageMap();
2021-12-22 16:11:05 -05:00
const releases = process.argv.slice(2)[0];
const data = JSON.parse(releases);
const packages = await Promise.all(
data.map(({ name, version }) => {
2022-03-08 11:48:12 -05:00
const p = packageMap.get(name);
if (!p) {
throw new Error(`Unable to find entrypoint for "${name}"!`);
}
2022-04-02 15:15:41 -05:00
return {
name,
version,
url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString(),
};
2021-12-22 16:11:05 -05:00
})
);
Improve GitHub Actions (#2041) * chore(actions): test new CI action * chore(actions): switch action order * chore(actions): update registry * chore(actions): remove debug * chore(actions): target all packages * chore(actions): test artifacts * chore(actions): try moving artifacts * chore(actions): test moving * chore(actions): test tar approach * chore(actions): test tar approach * chore(actions): use artifacts/packages before tar * chore(actions): test mv -vn * chore(actions): mkdir first * chore(actions): how does tar work? * chore(actions): so good at bash * chore(actions): test matrix * chore(actions): fix test matrix * chore(actions): fix windows? * chore(actions): fix windows? * chore(actions): fix windows! * chore(actions): fix windows! * chore(actions): add lint * chore(actions): add back old actions * chore(actions): test notification action * chore(actions): test notification action again * chore(actions): fix extract action * chore(actions): fix action? * chore(actions): fix action? * chore(actions): fix newlines * chore(actions): test --production flag * chore(actions): test --production flag for test * chore(actions): add execa to production deps * chore(actions): add cheerio to production deps * chore(actions): add production deps for tested examples * chore(actions): fix changelog action * chore(actions): attempt to use --prefer-offline * chore(actions): revert dependencies/devDependencies change * chore(actions): update all actions * chore(actions): add smoke test * chore(actions): update changelog deps * chore(actions): move notify script * chore(actions): consolidate main scripts * chore(actions): update changelog name * chore(actions): update congratsbot * chore(actions): update ci * chore(actions): change lint/format strategy * chore(actions): expose GITHUB_TOKEN to linter * chore(actions): update lint * chore(actions): enable autofix * chore(actions): fetch-depth 0 * chore(actions): fix eslint extensions * chore(actions): debug lint * chore(actions): fix eslint args * chore(actions): fix eslint? * [ci] ESLint fix * [ci] Prettier fix * chore(actions): fix lint! * chore(actions): cleanup comments * chore(actions): fix lint * chore(actions): lint astro only * chore(actions): ignore pattern * chore(actions): no_verify * chore(actions): disable no verify * chore(actions): debug status * chore(actions): add concurrency * chore(actions): add comment about concurrency * chore(actions): make release dependent on lint * chore(actions): move lint first * chore(actions): run CI on PR or `main` only * chore(actions): remove GPR publish step * chore: add back old actions * chore: revert package.json * chore: improve changelog with GitHub info * chore(actions): try pull_request_target * debug lint * debug lint * debug lint * try pull_request_target * update pull_request_target perms * update pull_request_target * fix perms * fix run? * fix run? * fix run? (part 3) * fix run? (part 4) * fix run? (part 5) * fix run! * fix run!! * fix run!!! * fix run!!!! * fix run!!!!! * fix run!!!!!! * add comment about forks Co-authored-by: GitHub Actions <actions-user@github.com>
2021-11-29 16:11:15 -05:00
2021-12-22 16:11:05 -05:00
const emoji = item(emojis);
const descriptor = item(descriptors);
const verb = item(verbs);
let message = '';
2021-12-22 16:11:05 -05:00
if (packages.length === 1) {
const { name, version, url } = packages[0];
2023-01-12 16:28:30 -05:00
message += `${emoji} \`${name}@${version}\` ${singularlize(
verb
)}\nRead the [release notes ](<${url}>)\n`;
2021-12-22 16:11:05 -05:00
} else {
message += `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
2021-12-22 16:11:05 -05:00
for (const { name, version, url } of packages) {
message += `\`${name}@${version}\` Read the [release notes →](<${url}>)\n`;
}
}
if (message.length < 2000) {
console.log(message);
} else {
2023-01-12 16:28:30 -05:00
const { name, version, url } = packages.find((pkg) => pkg.name === 'astro') ?? packages[0];
message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
2023-01-12 16:28:30 -05:00
message += `\`${name}@${version}\` Read the [release notes →](<${url}>)\n`;
2023-01-12 16:28:30 -05:00
message += `\nAlso ${item(extraVerbs)}:`;
2023-01-12 16:28:30 -05:00
const remainingPackages = packages.filter((p) => p.name !== name);
for (const { name, version, url } of remainingPackages) {
message += `\n\`${name}@${version}\``;
}
if (message.length < 2000) {
console.log(message);
} else {
message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
2023-01-12 16:28:30 -05:00
message += `\`${name}@${version}\` Read the [release notes →](<${url}>)\n`;
message += `\n\nAlso ${item(extraVerbs)}: ${remainingPackages.length} other packages!`;
console.log(message);
2021-12-22 16:11:05 -05:00
}
}
Improve GitHub Actions (#2041) * chore(actions): test new CI action * chore(actions): switch action order * chore(actions): update registry * chore(actions): remove debug * chore(actions): target all packages * chore(actions): test artifacts * chore(actions): try moving artifacts * chore(actions): test moving * chore(actions): test tar approach * chore(actions): test tar approach * chore(actions): use artifacts/packages before tar * chore(actions): test mv -vn * chore(actions): mkdir first * chore(actions): how does tar work? * chore(actions): so good at bash * chore(actions): test matrix * chore(actions): fix test matrix * chore(actions): fix windows? * chore(actions): fix windows? * chore(actions): fix windows! * chore(actions): fix windows! * chore(actions): add lint * chore(actions): add back old actions * chore(actions): test notification action * chore(actions): test notification action again * chore(actions): fix extract action * chore(actions): fix action? * chore(actions): fix action? * chore(actions): fix newlines * chore(actions): test --production flag * chore(actions): test --production flag for test * chore(actions): add execa to production deps * chore(actions): add cheerio to production deps * chore(actions): add production deps for tested examples * chore(actions): fix changelog action * chore(actions): attempt to use --prefer-offline * chore(actions): revert dependencies/devDependencies change * chore(actions): update all actions * chore(actions): add smoke test * chore(actions): update changelog deps * chore(actions): move notify script * chore(actions): consolidate main scripts * chore(actions): update changelog name * chore(actions): update congratsbot * chore(actions): update ci * chore(actions): change lint/format strategy * chore(actions): expose GITHUB_TOKEN to linter * chore(actions): update lint * chore(actions): enable autofix * chore(actions): fetch-depth 0 * chore(actions): fix eslint extensions * chore(actions): debug lint * chore(actions): fix eslint args * chore(actions): fix eslint? * [ci] ESLint fix * [ci] Prettier fix * chore(actions): fix lint! * chore(actions): cleanup comments * chore(actions): fix lint * chore(actions): lint astro only * chore(actions): ignore pattern * chore(actions): no_verify * chore(actions): disable no verify * chore(actions): debug status * chore(actions): add concurrency * chore(actions): add comment about concurrency * chore(actions): make release dependent on lint * chore(actions): move lint first * chore(actions): run CI on PR or `main` only * chore(actions): remove GPR publish step * chore: add back old actions * chore: revert package.json * chore: improve changelog with GitHub info * chore(actions): try pull_request_target * debug lint * debug lint * debug lint * try pull_request_target * update pull_request_target perms * update pull_request_target * fix perms * fix run? * fix run? * fix run? (part 3) * fix run? (part 4) * fix run? (part 5) * fix run! * fix run!! * fix run!!! * fix run!!!! * fix run!!!!! * fix run!!!!!! * add comment about forks Co-authored-by: GitHub Actions <actions-user@github.com>
2021-11-29 16:11:15 -05:00
}
run();