From b73308b0dbaadbd4b342d1fb56d6ed775919c68f Mon Sep 17 00:00:00 2001 From: Steven Petryk Date: Sun, 24 Mar 2024 21:12:11 -0700 Subject: [PATCH] Automatically publish PRs from non-forks Collaborators can get a published npm package, as a treat. --- .github/workflows/ci.yml | 11 +++++++++++ jest.config.js => jest.config.mjs | 0 scripts/publish-branch.ts | 14 ++++++++++++++ 3 files changed, 25 insertions(+) rename jest.config.js => jest.config.mjs (100%) create mode 100644 scripts/publish-branch.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9639228..b585262c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,3 +57,14 @@ jobs: cache: "pnpm" - run: pnpm install - run: pnpm tsc + + publish-branch: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v3 + - uses: actions/setup-node@v4 + with: + cache: "pnpm" + - run: pnpm install + - run: pnpm publish-branch diff --git a/jest.config.js b/jest.config.mjs similarity index 100% rename from jest.config.js rename to jest.config.mjs diff --git a/scripts/publish-branch.ts b/scripts/publish-branch.ts new file mode 100644 index 00000000..cb5a56de --- /dev/null +++ b/scripts/publish-branch.ts @@ -0,0 +1,14 @@ +import childProcess from "node:child_process" +import fs from "node:fs" + +const shortCommit = childProcess.execSync("git rev-parse --short HEAD", { encoding: "utf8" }).trim() + +const version = `0.0.0-${shortCommit}` + +console.log(`Publishing ${version} to npm...`) + +const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8")) +packageJson.version = version +fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2)) + +childProcess.execSync("npm publish --access public --tag experimental", { stdio: "inherit" })