From 79c4acf033fc65c938af58133e3008e34a71cf45 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 17 Dec 2021 16:35:49 +0530 Subject: [PATCH] Add npm release workflow --- .github/workflows/node-release.yml | 69 ++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/node-release.yml diff --git a/.github/workflows/node-release.yml b/.github/workflows/node-release.yml new file mode 100644 index 0000000..c60082e --- /dev/null +++ b/.github/workflows/node-release.yml @@ -0,0 +1,69 @@ +name: Publish Package +on: + release: + types: [created] + workflow_dispatch: + inputs: + skip: + description: Skip release to repository + required: false + tag: + description: Tag name + required: true +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Harden Runner + uses: step-security/harden-runner@v1 + with: + allowed-endpoints: + github.com:443 + npm.pkg.github.com:443 + registry.npmjs.org:443 + + - name: Checkout release + if: github.event_name != 'workflow_dispatch' + uses: actions/checkout@v2 + + - name: Checkout tag + uses: actions/checkout@v2 + if: github.event_name == 'workflow_dispatch' + with: + ref: ${{ github.event.inputs.tag }} + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '16.x' + registry-url: https://registry.npmjs.org + + - name: Install dependencies and add lib + run: | + npm install + npm run build + sed -i -e '/lib\//d' .gitignore + + - name: Publish to NPM + if: "!contains(github.event.inputs.skip, 'skip-npm')" + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Change to GitHub Packages registry + uses: actions/setup-node@v2 + with: + registry-url: https://npm.pkg.github.com + scope: '@shivammathur' + + - name: Patch package.json + run: | + sed -i 's#"name": "#"name": "@shivammathur/#' package.json + - name: Publish to GitHub Packages + if: "!contains(github.event.inputs.skip, 'skip-github-packages')" + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}