Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move deployment to single script #1088

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
"lint": "yarn lint:js bin-src node-src test-stories ./isChromatic.js ./isChromatic.mjs",
"lint:js": "cross-env NODE_ENV=production eslint --cache --cache-location=.cache/eslint --report-unused-disable-directives",
"lint:package": "sort-package-json",
"release": "./scripts/versionAndBuildForRelease.mjs && auto shipit",
"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",
Expand All @@ -100,7 +100,6 @@
"@actions/core": "^1.10.0",
"@actions/github": "^5.0.0",
"@antfu/ni": "^0.21.5",
"@auto-it/exec": "^11.0.4",
"@auto-it/slack": "^11.1.6",
"@discoveryjs/json-ext": "^0.5.7",
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
Expand Down Expand Up @@ -233,12 +232,6 @@
"plugins": [
"npm",
"released",
[
"exec",
{
"afterShipIt": "yarn run publish-action"
}
],
[
"slack",
{
Expand Down
64 changes: 25 additions & 39 deletions scripts/publish-action.mjs → scripts/publishAction.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +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}`);
} else {
const data = JSON.parse(process.env.ARG_0);
context = data.context;
version = data.newVersion.replace(/^v/, '');
console.info(`📌 Using auto shipIt context: ${context}`);
console.info(`📌 Using auto shipIt version: ${version}`);
console.info(`Commits in release:`);
data.commitsInRelease.forEach((c) => console.info(`- ${c.hash.slice(0, 8)} ${c.subject}`));
}
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) {
Expand All @@ -93,11 +65,6 @@ const publishAction = async ({ major, version, repo }) => {

switch (context) {
case 'canary':
if (process.argv[2] !== 'canary') {
console.info('Skipping automatic publish of action-canary.');
console.info('Run `yarn publish-action canary` to publish a canary action.');
return;
}
await publishAction({ major, version, repo: 'chromaui/action-canary' });
break;
case 'next':
Expand All @@ -109,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 (process.argv[1] === import.meta.filename) {
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]);
}
15 changes: 15 additions & 0 deletions scripts/versionAndBuildForRelease.mjs → scripts/release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@

import { $ } from 'execa';

import { main as publishAction } from './publishAction.mjs';

async function main() {
const { stdout: status } = await $`git status --porcelain`;
if (status) {
console.error(`❗️ Working directory is not clean:\n${status}`);
return;
}

await build();
await $({ stdout: 'inherit', stderr: 'inherit' })`auto shipit`;

if (process.env.GITHUB_REF === 'main') {
await publishAction('latest');
} else {
console.info('Skipping automatic publish of action-canary.');
console.info('Run `yarn publish-action canary` to publish a canary action.');
return;
}
}

async function build() {
const { stdout: nextVersion } = await $`auto shipit --dry-run --quiet`;

console.info(`📌 Temporarily bumping version to '${nextVersion}' for build step`);
Expand Down
15 changes: 0 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,6 @@ __metadata:
languageName: node
linkType: hard

"@auto-it/exec@npm:^11.0.4":
version: 11.1.6
resolution: "@auto-it/exec@npm:11.1.6"
dependencies:
"@auto-it/core": "npm:11.1.6"
endent: "npm:^2.1.0"
fp-ts: "npm:^2.5.3"
fromentries: "npm:^1.2.0"
io-ts: "npm:^2.1.2"
tslib: "npm:2.1.0"
checksum: 10c0/190cc3f7f8e676bf7fe04ed0dfb9c3b39591ffb472a412f1890e1329cdbc93610c0780a8fe3a38ec86cb9f089b2a585ad819e649c1df77ba12225b6159224503
languageName: node
linkType: hard

"@auto-it/npm@npm:11.1.6":
version: 11.1.6
resolution: "@auto-it/npm@npm:11.1.6"
Expand Down Expand Up @@ -7539,7 +7525,6 @@ __metadata:
"@actions/core": "npm:^1.10.0"
"@actions/github": "npm:^5.0.0"
"@antfu/ni": "npm:^0.21.5"
"@auto-it/exec": "npm:^11.0.4"
"@auto-it/slack": "npm:^11.1.6"
"@discoveryjs/json-ext": "npm:^0.5.7"
"@eslint-community/eslint-plugin-eslint-comments": "npm:^4.3.0"
Expand Down
Loading