Skip to content

Commit

Permalink
Check for clean working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Oct 6, 2023
1 parent b59aa3a commit aa764cb
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions scripts/publish-action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const command = (cmd, opts) => execaCommand(cmd, { stdio: 'inherit', ...opts });
const publishAction = async ({ version, repo }) => {
const dryRun = process.argv.includes('--dry-run');

console.info(`\n✅ Publishing ${version} to ${repo} ${dryRun ? '(dry run)' : ''}\n`);
console.info(`✅ Publishing ${version} to ${repo} ${dryRun ? '(dry run)' : ''}`);

const { path, cleanup } = await tmp.dir({ unsafeCleanup: true, prefix: `chromatic-action-` });
const run = (cmd) => command(cmd, { cwd: path });
Expand All @@ -27,7 +27,7 @@ const publishAction = async ({ version, repo }) => {
await run('git tag -f latest');

if (dryRun) {
console.info('\n✅ Skipping git push due to --dry-run\n');
console.info('✅ Skipping git push due to --dry-run');
} else {
await run('git push origin HEAD:main --force');
await run('git push --tags --force');
Expand All @@ -47,13 +47,23 @@ const publishAction = async ({ version, repo }) => {
* Make sure to build the action before publishing manually.
*/
(async () => {
const { stdout: status } = await execaCommand('git status --porcelain');
if (status) {
console.error(`❗️ Working directory is not clean:\n${status}`);
return;
}

const { default: pkg } = await import('../package.json', { assert: { type: 'json' } });

const [, major, minor, patch, tag = 'latest'] =
pkg.version.match(/(\d+)\.(\d+)\.(\d+)-?(\w+)?/) || [];
if (!major || !minor || !patch) throw new Error(`Invalid version: ${pkg.version}`);
const [, major, minor, patch, tag] = pkg.version.match(/(\d+)\.(\d+)\.(\d+)-?(\w+)?/) || [];
if (!major || !minor || !patch) {
console.error(`❗️ Invalid version: ${pkg.version}`);
return;
}

const context = ['canary', 'next', 'latest'].includes(process.argv[2]) ? process.argv[2] : tag;
const context = ['canary', 'next', 'latest'].includes(process.argv[2])
? process.argv[2]
: tag || 'latest';

switch (context) {
case 'canary':
Expand All @@ -71,6 +81,6 @@ const publishAction = async ({ version, repo }) => {
await publishAction({ version: pkg.version, repo: 'chromaui/action' });
break;
default:
throw new Error(`Unknown tag: ${tag}`);
console.error(`❗️ Unknown tag: ${tag}`);
}
})();

0 comments on commit aa764cb

Please sign in to comment.