From e64d07d19d765b1ed10bb5b85ae841934467b670 Mon Sep 17 00:00:00 2001 From: Hunain Bin Sajid Date: Fri, 13 Sep 2024 18:10:10 +0500 Subject: [PATCH 1/2] feat: add npm publish github action workflow --- .github/workflows/publish-npm.yml | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) 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 0000000..7a41ec5 --- /dev/null +++ b/.github/workflows/publish-npm.yml @@ -0,0 +1,61 @@ +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 + permissions: + contents: write + 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: Install dependencies + run: npm ci --ignore-scripts + + - 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: 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 }}" + git tag v$(cat package.json | jq .version -r) + git push origin v$(cat package.json | jq .version -r) From f71d67de868021b3700d578e8fdb6ace5b5fb317 Mon Sep 17 00:00:00 2001 From: Hunain Bin Sajid Date: Fri, 13 Sep 2024 18:13:25 +0500 Subject: [PATCH 2/2] format: publish-npm file --- .github/workflows/publish-npm.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 7a41ec5..73a88f6 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -18,7 +18,7 @@ jobs: publish: name: Publish NPM permissions: - contents: write + contents: write runs-on: ubuntu-latest steps: - name: Checkout repo @@ -26,9 +26,9 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: '20' - cache: 'npm' - registry-url: 'https://registry.npmjs.org' + node-version: "20" + cache: "npm" + registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci --ignore-scripts @@ -56,6 +56,6 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | - npm publish --tag "${{ inputs.dist-tag }}" - git tag v$(cat package.json | jq .version -r) - git push origin v$(cat package.json | jq .version -r) + npm publish --tag "${{ inputs.dist-tag }}" + git tag v$(cat package.json | jq .version -r) + git push origin v$(cat package.json | jq .version -r)