diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6f84492..222fef1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,3 +26,10 @@ jobs: git diff exit 1 fi + - run: | + npm run version + if [ "$(git diff | wc -l)" -gt "0" ]; then + echo "Check version fail, please run 'npm run version' to fix." + git diff + exit 1 + fi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ec5a8ec --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,19 @@ +name: Publish + +on: + release: + types: [published] + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + - run: npm ci + - run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/docs/dev-guide.md b/docs/dev-guide.md new file mode 100644 index 0000000..f8790fa --- /dev/null +++ b/docs/dev-guide.md @@ -0,0 +1,5 @@ +# How to release + +1. Update the version in `package.json` and run `npm run version`. Then merge the PR. +2. Publish a new GitHub release. +3. The npm pacakge will be published automatically. diff --git a/package.json b/package.json index 4bcc7d1..cf459a2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "pretest": "npm run build", "test": "jest __tests__ --passWithNoTests", "integrationTest": "npm run build && jest integration-test --passWithNoTests", - "version": "echo \"export const Version = '$npm_package_version'\" > src/version.ts && git add src/version.ts && npm run build", + "version": "echo \"export const Version = '$npm_package_version'\" > src/version.ts", "prepublishOnly": "npm run build" }, "prettier": {