diff --git a/package.json b/package.json index 7766edd6c..c64a3c85c 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "release": "./scripts/release.mjs", "prepack": "clean-package", "postpack": "clean-package restore", - "publish-action": "./scripts/publish-action.mjs", + "publish-action": "./scripts/publishAction.mjs", "trace": "./dist/bin.js trace", "trim-stats": "./dist/bin.js trim-stats-file", "storybook": "storybook dev -p 9009", diff --git a/scripts/publish-action.mjs b/scripts/publishAction.mjs similarity index 87% rename from scripts/publish-action.mjs rename to scripts/publishAction.mjs index da1d9f058..4a9b78725 100755 --- a/scripts/publish-action.mjs +++ b/scripts/publishAction.mjs @@ -51,31 +51,11 @@ const publishAction = async ({ major, version, repo }) => { return cleanup(); }; -/** - * Generally, this script is invoked by auto's `afterShipIt` hook. - * - * For manual (local) use: - * yarn publish-action {context} [--dry-run] - * e.g. yarn publish-action canary - * or yarn publish-action latest --dry-run - * - * Make sure to build the action before publishing manually. - */ -(async () => { - const { stdout: status } = await $`git status --porcelain`; - if (status) { - console.error(`❗️ Working directory is not clean:\n${status}`); - return; - } - - let context, version; - if (['canary', 'next', 'latest'].includes(process.argv[2])) { - const pkg = JSON.parse(readFileSync('package.json', 'utf8')); - context = process.argv[2]; - version = pkg.version; - console.info(`📌 Using context arg: ${context}`); - console.info(`📌 Using package.json version: ${version}`); - } +export async function main(context) { + const pkg = JSON.parse(readFileSync('package.json', 'utf8')); + const version = pkg.version; + console.info(`📌 Using context arg: ${context}`); + console.info(`📌 Using package.json version: ${version}`); const [, major, minor, patch] = version.match(/^(\d+)\.(\d+)\.(\d+)-*(\w+)?/) || []; if (!major || !minor || !patch) { @@ -96,4 +76,23 @@ const publishAction = async ({ major, version, repo }) => { default: console.error(`❗️ Unknown context: ${context}`); } -})(); +} + +/** + * For manual (local) use: + * yarn publish-action {context} [--dry-run] + * e.g. yarn publish-action canary + * or yarn publish-action latest --dry-run + * + * Make sure to build the action before publishing manually. + */ +// eslint-disable-next-line unicorn/prefer-module +if (require.main === module) { + const { stdout: status } = await $`git status --porcelain`; + if (status) { + console.error(`❗️ Working directory is not clean:\n${status}`); + process.exit(1); + } + + main(process.argv[2]); +} diff --git a/scripts/release.mjs b/scripts/release.mjs index 4fe00ec32..db8a3f0d2 100755 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -2,6 +2,8 @@ import { $ } from 'execa'; +import { main as publishAction } from './publishAction.mjs'; + async function main() { const { stdout: status } = await $`git status --porcelain`; if (status) { @@ -13,7 +15,7 @@ async function main() { await $({ stdout: 'inherit', stderr: 'inherit' })`auto shipit`; if (process.env.GITHUB_REF === 'main') { - await $({ stdout: 'inherit', stderr: 'inherit' })`yarn publish-action latest`; + await publishAction('latest'); } else { console.info('Skipping automatic publish of action-canary.'); console.info('Run `yarn publish-action canary` to publish a canary action.');