Skip to content

Commit

Permalink
Added publish.yml to publish to npm.
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed May 25, 2022
1 parent 9cff6b3 commit b60833a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/change-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs');

const data = fs.readFileSync("package.json")
let json = JSON.parse(data);
let version = process.argv[2];

json.version = version.replace('refs/tags/v', '');

fs.writeFileSync("package.json", JSON.stringify(json, null, 2));
40 changes: 40 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release and Publish
on:
push:
tags:
- 'v*'

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
publish:
name: Publish
runs-on: ubuntu-latest
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Publish
run: |
node .github/change-version.js ${{ github.ref }}
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
npm config set scope "@kydev"
npm config list
npm publish --access public

0 comments on commit b60833a

Please sign in to comment.