Skip to content

Commit

Permalink
Automatically publish PRs from non-forks
Browse files Browse the repository at this point in the history
Collaborators can get a published npm package, as a treat.
  • Loading branch information
stevenpetryk committed Mar 25, 2024
1 parent 143bbca commit b73308b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
14 changes: 14 additions & 0 deletions scripts/publish-branch.ts
Original file line number Diff line number Diff line change
@@ -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" })

0 comments on commit b73308b

Please sign in to comment.