Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

build: release preview package when triggered via comment (#4750)

Aakansha Doshia60860867cef
diff --git a/.github/workflows/autorelease-excalidraw.yml b/.github/workflows/autorelease-excalidraw.yml
index 230ea63046..ce7cc2fde2 100644
--- a/.github/workflows/autorelease-excalidraw.yml
+++ b/.github/workflows/autorelease-excalidraw.yml
@@ -23,4 +23,5 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Auto release
run: |
+ yarn add @actions/core
yarn autorelease
diff --git a/.github/workflows/autorelease-preview.yml b/.github/workflows/autorelease-preview.yml
new file mode 100644
index 0000000000..c471e5749e
--- /dev/null
+++ b/.github/workflows/autorelease-preview.yml
@@ -0,0 +1,55 @@
+name: Auto release preview @excalidraw/excalidraw-preview
+on:
+ issue_comment:
+ types: [created, edited]
+
+jobs:
+ Auto-release-excalidraw-preview:
+ name: Auto release preview
+ if: github.event.comment.body == '@excalibot trigger release' && github.event.issue.pull_request
+ runs-on: ubuntu-latest
+ steps:
+ - name: React to trigger comment
+ uses: peter-evans/create-or-update-comment@v1
+ with:
+ token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
+ comment-id: ${{ github.event.comment.id }}
+ reactions: "+1"
+ - name: Get PR SHA
+ id: sha
+ uses: actions/github-script@v4
+ with:
+ result-encoding: string
+ script: |
+ const { owner, repo, number } = context.issue;
+ const pr = await github.pulls.get({
+ owner,
+ repo,
+ pull_number: number,
+ });
+ return pr.data.head.sha
+ - uses: actions/checkout@v2
+ with:
+ ref: ${{ steps.sha.outputs.result }}
+ fetch-depth: 2
+ - name: Setup Node.js 14.x
+ uses: actions/setup-node@v2
+ with:
+ node-version: 14.x
+ - name: Set up publish access
+ run: |
+ npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
+ env:
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
+ - name: Auto release preview
+ id: "autorelease"
+ run: |
+ yarn add @actions/core
+ yarn autorelease preview ${{ github.event.issue.number }}
+ - name: Post comment post release
+ if: always()
+ uses: peter-evans/create-or-update-comment@v1
+ with:
+ token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }}
+ issue-number: ${{ github.event.issue.number }}
+ body: "@${{ github.event.comment.user.login }} ${{ steps.autorelease.outputs.result }}"
diff --git a/scripts/autorelease.js b/scripts/autorelease.js
index f567546b09..7e2513387e 100644
--- a/scripts/autorelease.js
+++ b/scripts/autorelease.js
@@ -1,5 +1,6 @@
const fs = require("fs");
const { exec, execSync } = require("child_process");
+const core = require("@actions/core");
const excalidrawDir = `${__dirname}/../src/packages/excalidraw`;
const excalidrawPackage = `${excalidrawDir}/package.json`;
@@ -15,18 +16,25 @@ const publish = () => {
execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir });
execSync(`yarn run build:umd`, { cwd: excalidrawDir });
execSync(`yarn --cwd ${excalidrawDir} publish`);
+ console.info("Published 🎉");
+ core.setOutput(
+ "result",
+ `**Preview version has been shipped** :rocket:
+ You can use [@excalidraw/excalidraw-preview@${pkg.version}](https://www.npmjs.com/package/@excalidraw/excalidraw-preview/v/${pkg.version}) for testing!`,
+ );
} catch (error) {
+ core.setOutput("result", "package couldn't be published :warning:!");
console.error(error);
+ process.exit(1);
}
};
-
// 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);
+ core.setOutput("result", ":warning: Package couldn't be published!");
process.exit(1);
}
-
const changedFiles = stdout.trim().split("\n");
const filesToIgnoreRegex = /src\/excalidraw-app|packages\/utils/;
@@ -37,16 +45,33 @@ exec(`git diff --name-only HEAD^ HEAD`, async (error, stdout, stderr) => {
);
});
if (!excalidrawPackageFiles.length) {
+ console.info("Skipping release as no valid diff found");
+ core.setOutput("result", "Skipping release as no valid diff found");
process.exit(0);
}
// update package.json
- pkg.version = `${pkg.version}-${getShortCommitHash()}`;
pkg.name = "@excalidraw/excalidraw-next";
- fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
+ let version = `${pkg.version}-${getShortCommitHash()}`;
// update readme
- const data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
+ let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8");
+
+ const isPreview = process.argv.slice(2)[0] === "preview";
+ if (isPreview) {
+ // use pullNumber-commithash as the version for preview
+ const pullRequestNumber = process.argv.slice(3)[0];
+ version = `${pkg.version}-${pullRequestNumber}-${getShortCommitHash()}`;
+ // replace "excalidraw-next" with "excalidraw-preview"
+ pkg.name = "@excalidraw/excalidraw-preview";
+ data = data.replace(/excalidraw-next/g, "excalidraw-preview");
+ data = data.trim();
+ }
+ pkg.version = version;
+
+ fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8");
+
fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8");
+ console.info("Publish in progress...");
publish();
});
diff --git a/src/packages/excalidraw/CHANGELOG.md b/src/packages/excalidraw/CHANGELOG.md
index 178c14d7e3..2047cd4167 100644
--- a/src/packages/excalidraw/CHANGELOG.md
+++ b/src/packages/excalidraw/CHANGELOG.md
@@ -75,6 +75,14 @@ Please add the latest change on the top under the correct section.
### Build
+- Release preview package [@excalidraw/excalidraw-preview](https://www.npmjs.com/package/@excalidraw/excalidraw-preview) when triggered via comment
+
+```
+ @excalibot trigger release
+```
+
+[#4750](https://github.com/excalidraw/excalidraw/pull/4750).
+
- Added an example to test and develop the package [locally](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#Development) using `yarn start` [#4488](https://github.com/excalidraw/excalidraw/pull/4488)
- Remove `file-loader` so font assets are not duplicated by webpack and use webpack asset modules for font generation [#4380](https://github.com/excalidraw/excalidraw/pull/4380).
diff --git a/src/packages/excalidraw/README_NEXT.md b/src/packages/excalidraw/README_NEXT.md
index 0912296672..7d84a80c5f 100644
--- a/src/packages/excalidraw/README_NEXT.md
+++ b/src/packages/excalidraw/README_NEXT.md
@@ -1061,3 +1061,13 @@ yarn start
[http://localhost:3001](http://localhost:3001) will open in your default browser.
The example is same as the [codesandbox example](https://ehlz3.csb.app/)
+
+#### Create a test release
+
+You can create a test release by posting the below comment in your pull request
+
+```
+@excalibot trigger release
+```
+
+Once the version is released `@excalibot` will post a comment with the release version.