Skip to content

Commit

Permalink
chore(release-npm.yaml): set package version using set-version.js script
Browse files Browse the repository at this point in the history
chore(release-npm.yaml): authenticate registry with NPM_TOKEN
feat(release-npm.yaml): add support for publishing canary release
feat(release-npm.yaml): add support for publishing regular release
feat(set-version.js): create script to update package version in package.json
  • Loading branch information
chronark committed Jul 21, 2023
1 parent 771585f commit d60a0b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/release-npm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,26 @@ jobs:
${{ runner.os }}-pnpm-store-
- name: Set package version
run: node ./scripts/set-version.js ./packages/sdk ${{ env.VERSION }}

- name: Install
run: pnpm install -r

- name: Build package
run: pnpm turbo run build --filter=@unkey/api

- name: Authenticate Registry
run: npm set "//registry.npmjs.org/:_authToken" ${{ secrets.NPM_TOKEN }}

- name: Publish canary
if: "github.event.release.prerelease"
working-directory: ./packages/sdk
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
npm publish --access public --tag=canary
run: pnpm publish --access public --tag=canary --no-git-checks

- name: Publish
if: "!github.event.release.prerelease"
working-directory: ./packages/sdk
run: |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
npm publish --access public
run: pnpm publish --access public --no-git-checks


19 changes: 19 additions & 0 deletions scripts/set-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

const fs = require("fs");
const path = require("path");


// usage
// node set-version.js <path-to-project-root> <new-version>
// e.g. node set-version.js ./packages/sdk v1.0.0

const root = process.argv[2]; // path to project root
const version = process.argv[3].replace(/^v/, ""); // new version

console.log(`Updating version=${version} in ${root}`);

const content = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf-8"));

content.version = version;

fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(content, null, 2));

1 comment on commit d60a0b8

@vercel
Copy link

@vercel vercel bot commented on d60a0b8 Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

unkey – ./

unkey-git-main-unkey.vercel.app
unkey.vercel.app
www.unkey.dev
unkey.dev
unkey-unkey.vercel.app

Please sign in to comment.