Skip to content

Commit

Permalink
Run script after shipit
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Oct 2, 2023
1 parent 033cbbf commit cee8471
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.eslint.json'],
extraFileExtensions: ['.cjs'],
extraFileExtensions: ['.cjs', '.mjs'],
},
rules: {
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"lint:js": "cross-env NODE_ENV=production eslint --fix --cache --cache-location=.cache/eslint --ext .js,.json,.mjs,.ts,.cjs --report-unused-disable-directives",
"lint:package": "sort-package-json",
"release": "yarn run build && auto shipit",
"publish-action": "./scripts/publish-action.mjs $ARG_0 $ARG_1 $ARG_2 $ARG_3",
"trace": "./dist/bin.js trace",
"trim-stats": "./dist/bin.js trim-stats-file",
"storybook": "start-storybook -p 9009 -s static",
Expand Down Expand Up @@ -107,6 +108,7 @@
"@actions/core": "^1.10.0",
"@actions/github": "^5.0.0",
"@antfu/ni": "^0.21.5",
"@auto-it/exec": "^11.0.4",
"@babel/cli": "^7.14.8",
"@babel/core": "^7.15.0",
"@babel/node": "^7.15.4",
Expand Down Expand Up @@ -207,7 +209,13 @@
"auto": {
"plugins": [
"npm",
"released"
"released",
[
"exec",
{
"afterShipIt": "yarn docs && push-dir --dir=docs --branch=gh-pages"
}
]
],
"shipit": {
"onlyGraduateWithReleaseLabel": true
Expand Down
55 changes: 55 additions & 0 deletions scripts/publish-action.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

import cpy from 'cpy';
import { execaCommand } from 'execa';
import tmp from 'tmp-promise';

const command = (cmd, opts) => execaCommand(cmd, { stdio: 'inherit', ...opts });

const publishAction = async ({ repo, tag, version }) => {
console.info(`✅ Publishing '${tag}' action to https://github.com/${repo}`);

const { path, cleanup } = await tmp.dir({ unsafeCleanup: true, prefix: `chromatic-action-` });
const run = (cmd) => command(cmd, { cwd: path });

await cpy(['action/*.js', 'action/*.json', 'action.yml', 'package.json'], path, {
parents: true,
});
await cpy(['action-src/CHANGELOG.md', 'action-src/LICENSE', 'action-src/README.md'], path);

await run('git init -b main');
await run(`git remote add origin git@github.com:${repo}.git`);
await run('git add .');
await run(`git commit -m ${version}`);
await run('git tag v1');
await run('git push origin head --force');
await run('git push --tags --force');

return cleanup();
};

/**
* Usage:
* release <major | minor | patch> <canary | next | latest> [--dry-run]
* release action <canary | next | latest> [--dry-run]
*/
(async () => {
// const [bump, tag, ...rest] = process.argv.slice(2);

console.log(JSON.stringify(process.argv.slice(1)));
return;

// if (tag === 'canary') {
// await publishAction({ repo: 'chromaui/action-canary', tag, version });
// } else if (tag === 'next') {
// await publishAction({ repo: 'chromaui/action-next', tag, version });
// } else {
// await publishAction({ repo: 'chromaui/action-next', tag, version });
// await publishAction({ repo: 'chromaui/action', tag, version });
// }

// if (tag === 'latest' && bump !== 'action') {
// const tagCommand = `npm dist-tag add chromatic@${version} next`;
// console.log(`⚠️ Don't forget to update the 'next' tag by running:\n ${tagCommand}`);
// }
})();
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@
typescript-memoize "^1.0.0-alpha.3"
url-join "^4.0.0"

"@auto-it/exec@^11.0.4":
version "11.0.4"
resolved "https://registry.yarnpkg.com/@auto-it/exec/-/exec-11.0.4.tgz#97efbc9fbc14f2b777ef874c029a40fda8be7a3e"
integrity sha512-n/kB8k/dwci9UeTsLCs8mig8ZQuS2dMHcHlsKXBeM18EmcbGHxDxyaPeMHJsnSlfKNmGtCXhHBHBhGVP18Ia+w==
dependencies:
"@auto-it/core" "11.0.4"
endent "^2.1.0"
fp-ts "^2.5.3"
fromentries "^1.2.0"
io-ts "^2.1.2"
tslib "2.1.0"

"@auto-it/npm@11.0.4":
version "11.0.4"
resolved "https://registry.yarnpkg.com/@auto-it/npm/-/npm-11.0.4.tgz#67b6bf78fb6d3f814365796f15541b014db73fcb"
Expand Down

0 comments on commit cee8471

Please sign in to comment.