Skip to content

Commit

Permalink
build: release with package option
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVidra committed Nov 9, 2024
1 parent acb0c91 commit 25d7891
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ on:
- patch
- minor
- major
package:
description: "Package"
required: true
type: choice
options:
- react
- js

jobs:
npm-publish:
Expand Down Expand Up @@ -39,4 +46,4 @@ jobs:
- run: git config user.email "170794745+flowsbotapp[bot]@users.noreply.github.com"
- run: npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
- run: pnpm install
- run: node scripts/release.js --${{ github.event.inputs.type }}
- run: node scripts/release.js --release=${{ github.event.inputs.type }} --package=${{ github.event.inputs.package }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"concurrently": "^9.0.1",
"eslint": "^8.57.0",
"husky": "^9.1.6",
"minimist": "^1.2.8",
"prettier": "^3.3.3"
},
"packageManager": "pnpm@9.12.2"
Expand Down
8 changes: 6 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
const util = require("util");
const exec = util.promisify(require("child_process").exec);

const canary = process.argv.includes("--canary");
const patch = process.argv.includes("--patch");
const minor = process.argv.includes("--minor");
const major = process.argv.includes("--major");
const argv = require("minimist")(process.argv.slice(2));
const { release, package } = argv;

if (!patch && !minor && !major && !canary)
throw new Error("You must specify a release type: --patch, --minor, --major or --canary");
const allowedReleases = ["canary", "patch", "minor", "major"];

if (!allowedReleases.includes(release))
throw new Error(`You must specify a release type (--release=...): ${allowedReleases.join(", ")}`);

const allowedPackages = ["js", "react"];
if (!allowedPackages.includes(package))
throw new Error(`You must specify a package (--package=...): ${allowedPackages.join(", ")}`);

const main = async () => {
if (canary) await exec("pnpm js version prerelease --preid=canary");
else await exec(`pnpm js version ${patch ? "patch" : minor ? "minor" : "major"}`);
if (release === "canary") await exec(`pnpm ${package} version prerelease --preid=canary`);
else await exec(`pnpm ${package} version ${release}`);

const currentVersion = require("../workspaces/js/package.json").version;
const currentVersion = require(`../workspaces/${package}/package.json`).version;
await exec(`git commit -am "${currentVersion}"`);
const gitTagName = `v${currentVersion}`;
await exec(`git tag -a ${gitTagName} -m '${gitTagName}'`);
await exec("git push --no-verify");
await exec(`git push --no-verify --tags`);

await exec("pnpm js build");
await exec("cp README.md workspaces/js");
await exec(`pnpm ${package} build`);
await exec(`cp README.md workspaces/${package}`);
await exec(
`pnpm js publish --access=public --provenance --no-git-checks ${canary ? "--tag=canary" : ""}`,
`pnpm ${package} publish --access=public --provenance --no-git-checks ${release === "canary" ? "--tag=canary" : ""}`,
);
};

Expand Down

0 comments on commit 25d7891

Please sign in to comment.