From 29f4b3a73d917074989624e0003eee9c01584921 Mon Sep 17 00:00:00 2001 From: lenkan Date: Wed, 1 May 2024 10:30:33 +0200 Subject: [PATCH] add publish workflow --- .github/workflows/publish-npm.yml | 53 +++++++++++++++++++++++++++++++ package.json | 3 +- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-npm.yml diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml new file mode 100644 index 00000000..1b6fea3f --- /dev/null +++ b/.github/workflows/publish-npm.yml @@ -0,0 +1,53 @@ +name: Publish NPM + +on: + workflow_dispatch: + inputs: + dry-run: + type: boolean + default: true + description: Dry run publish + dist-tag: + type: choice + options: + - dev + - latest + default: dev + description: Npm dist tag +jobs: + publish: + name: Publish NPM + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + registry-url: 'https://registry.npmjs.org' + - name: Set package name from vars + if: ${{ vars.NPM_PACKAGE_NAME }} + run: | + cat package.json | jq -r '.name = "${{ vars.NPM_PACKAGE_NAME }}"' > package.json.tmp + mv package.json.tmp package.json + - name: Set version from commit + if: ${{ inputs.dist-tag == 'dev' }} + run: | + npm version --no-git-tag-version $(cat package.json | jq .version -r)-dev.$(git rev-parse --short HEAD) + - name: Create git tag + run: git tag $(cat package.json | jq .version -r) + - name: Install dependencies + run: npm ci --ignore-scripts + - name: Publish dev package (Dry run) + if: ${{ inputs.dry-run == true }} + run: npm publish --tag "${{ inputs.dist-tag }}" --dry-run + - name: Publish dev package + if: ${{ inputs.dry-run == false }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish --tag "${{ inputs.dist-tag }}" + - name: Create git tag + run: | + git tag v$(cat package.json | jq .version -r) + git push origin v$(cat package.json | jq .version -r) diff --git a/package.json b/package.json index 1c5e7644..608a0d14 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ "types": "./dist/index.d.ts", "type": "module", "files": [ - "dist", - "src" + "dist" ], "scripts": { "start": "npm run build:esm -- --watch",