chore: add release-pr workflow

This commit is contained in:
shadcn
2023-03-08 11:55:08 +04:00
parent 385cc1a57d
commit 9cee5cd83e
4 changed files with 71 additions and 45 deletions

8
.github/version-pr/action.yml vendored Normal file
View File

@@ -0,0 +1,8 @@
name: "Determine version"
description: "Determines npm package version based on PR number and commit SHA"
outputs:
version:
description: "npm package version"
runs:
using: "node16"
main: "index.js"

19
.github/version-pr/index.js vendored Normal file
View File

@@ -0,0 +1,19 @@
// This is based on the work done by the next-auth team.
const fs = require("fs")
const path = require("path")
const core = require("@actions/core")
try {
const packageJSONPath = path.join(process.cwd(), "packages/cli/package.json")
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf8"))
const sha8 = process.env.GITHUB_SHA.substring(0, 8)
const prNumber = process.env.PR_NUMBER
const packageVersion = `0.0.0-pr.${prNumber}.${sha8}`
packageJSON.version = packageVersion
core.setOutput("version", packageVersion)
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON))
} catch (error) {
core.setFailed(error.message)
}