Skip to content

Commit

Permalink
Stable publish (#5326)
Browse files Browse the repository at this point in the history
* Add automatic stable publish

* Revert

* 14.0.0
  • Loading branch information
tajo authored Dec 21, 2023
1 parent df279c1 commit 186f234
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
15 changes: 15 additions & 0 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Stable Version

Run

```
npm version major
npm version minor
npm version patch
```

commit and merge into `main`. The CI will publish the new version to npm automatically if `package.json` version is higher than the one in the registry.

# Next Version

Every `main` branch commit gets automatically published to npm with `next` tag and `0.0.0-next-df279c1e7` version where `df279c1e7` is the short commit hash.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baseui",
"version": "13.0.0",
"version": "14.0.0",
"description": "A React Component library implementing the Base design language",
"keywords": [
"react",
Expand Down
53 changes: 40 additions & 13 deletions publish/publish-next.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,46 @@

const { execSync } = require("child_process");
const fs = require("fs");
const pkgJson = JSON.parse(fs.readFileSync("./package.json"));

const shortHash = execSync("git rev-parse --short HEAD").toString().trim();
const version = `0.0.0-next-${shortHash}`;
const publishNext = () => {
const shortHash = execSync("git rev-parse --short HEAD").toString().trim();
const version = `0.0.0-next-${shortHash}`;
console.log(`Publishing baseui ${version}`);
pkgJson.version = version;
delete pkgJson.scripts.prepare;
fs.writeFileSync("./dist/package.json", JSON.stringify(pkgJson, null, 2));

console.log(`Publishing baseui ${version}`);
const pkgJson = JSON.parse(fs.readFileSync("./package.json"));
pkgJson.version = version;
delete pkgJson.scripts.prepare;
fs.writeFileSync("./dist/package.json", JSON.stringify(pkgJson, null, 2));
try {
execSync("cd dist && npm publish --tag next");
} catch (e) {
console.log(e);
console.log("Next publish failed.");
}
};

try {
execSync("cd dist && npm publish --tag next");
} catch (e) {
console.log(e);
console.log("Publish failed.");
}
fetch(`https://registry.npmjs.org/baseui`)
.then((response) => response.json())
.then((data) => {
const latest = data["dist-tags"].latest;
console.log(`Latest version of baseui is: ${latest}`);
if (latest !== pkgJson.version) {
console.log(
`The package.json version ${pkgJson.version} is different from the one that's published ${latest}.`
);
console.log(`Publishing baseui@${pkgJson.version}...`);
delete pkgJson.scripts.prepare;
fs.writeFileSync("./dist/package.json", JSON.stringify(pkgJson, null, 2));
try {
execSync("cd dist && npm publish");
} catch (e) {
console.log(e);
console.log("Stable publish failed.");
}
}
publishNext();
})
.catch((error) => {
console.error("Error when fetching latest baseui version:", error);
publishNext();
});

0 comments on commit 186f234

Please sign in to comment.