2021-05-22 16:13:28 +02:00
|
|
|
const fs = require("fs");
|
|
|
|
const { exec, execSync } = require("child_process");
|
2022-02-14 09:24:24 +01:00
|
|
|
const core = require("@actions/core");
|
2021-05-22 16:13:28 +02:00
|
|
|
|
2023-12-12 07:02:51 +01:00
|
|
|
const excalidrawDir = `${__dirname}/../packages/excalidraw`;
|
2021-05-22 16:13:28 +02:00
|
|
|
const excalidrawPackage = `${excalidrawDir}/package.json`;
|
|
|
|
const pkg = require(excalidrawPackage);
|
2022-07-04 18:49:08 +02:00
|
|
|
const isPreview = process.argv.slice(2)[0] === "preview";
|
2021-05-22 16:13:28 +02:00
|
|
|
|
|
|
|
const getShortCommitHash = () => {
|
|
|
|
return execSync("git rev-parse --short HEAD").toString().trim();
|
|
|
|
};
|
|
|
|
|
|
|
|
const publish = () => {
|
2022-07-04 18:49:08 +02:00
|
|
|
const tag = isPreview ? "preview" : "next";
|
|
|
|
|
2021-05-22 16:13:28 +02:00
|
|
|
try {
|
|
|
|
execSync(`yarn --frozen-lockfile`);
|
2024-01-01 15:48:44 +01:00
|
|
|
execSync(`yarn run build:esm`, { cwd: excalidrawDir });
|
2022-07-04 18:49:08 +02:00
|
|
|
execSync(`yarn --cwd ${excalidrawDir} publish --tag ${tag}`);
|
|
|
|
console.info(`Published ${pkg.name}@${tag}🎉`);
|
2022-02-14 09:24:24 +01:00
|
|
|
core.setOutput(
|
|
|
|
"result",
|
|
|
|
`**Preview version has been shipped** :rocket:
|
2022-07-04 18:49:08 +02:00
|
|
|
You can use [@excalidraw/excalidraw@${pkg.version}](https://www.npmjs.com/package/@excalidraw/excalidraw/v/${pkg.version}) for testing!`,
|
2022-02-14 09:24:24 +01:00
|
|
|
);
|
2021-11-02 13:24:16 +01:00
|
|
|
} catch (error) {
|
2022-02-14 09:24:24 +01:00
|
|
|
core.setOutput("result", "package couldn't be published :warning:!");
|
2021-11-02 13:24:16 +01:00
|
|
|
console.error(error);
|
2022-02-14 09:24:24 +01:00
|
|
|
process.exit(1);
|
2021-05-22 16:13:28 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
// get files changed between prev and head commit
|
|
|
|
exec(`git diff --name-only HEAD^ HEAD`, async (error, stdout, stderr) => {
|
|
|
|
if (error || stderr) {
|
|
|
|
console.error(error);
|
2022-02-14 09:24:24 +01:00
|
|
|
core.setOutput("result", ":warning: Package couldn't be published!");
|
2021-05-22 16:13:28 +02:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
const changedFiles = stdout.trim().split("\n");
|
|
|
|
|
|
|
|
const excalidrawPackageFiles = changedFiles.filter((file) => {
|
2024-01-01 15:48:44 +01:00
|
|
|
return (
|
|
|
|
file.indexOf("packages/excalidraw") >= 0 ||
|
|
|
|
file.indexOf("buildPackage.js") > 0
|
|
|
|
);
|
2021-05-22 16:13:28 +02:00
|
|
|
});
|
|
|
|
if (!excalidrawPackageFiles.length) {
|
2022-02-14 09:24:24 +01:00
|
|
|
console.info("Skipping release as no valid diff found");
|
|
|
|
core.setOutput("result", "Skipping release as no valid diff found");
|
2021-05-22 16:13:28 +02:00
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// update package.json
|
2022-02-14 09:24:24 +01:00
|
|
|
let version = `${pkg.version}-${getShortCommitHash()}`;
|
2021-05-22 16:13:28 +02:00
|
|
|
|
|
|
|
// update readme
|
2022-02-14 09:24:24 +01:00
|
|
|
|
|
|
|
if (isPreview) {
|
|
|
|
// use pullNumber-commithash as the version for preview
|
|
|
|
const pullRequestNumber = process.argv.slice(3)[0];
|
|
|
|
version = `${pkg.version}-${pullRequestNumber}-${getShortCommitHash()}`;
|
|
|
|
}
|
|
|
|
pkg.version = version;
|
|
|
|
|
|
|
|
fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
|
|
|
|
|
|
|
|
console.info("Publish in progress...");
|
2021-05-22 16:13:28 +02:00
|
|
|
publish();
|
|
|
|
});
|