Publish package to NPM #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish package to NPM | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Enter the new version for the package' | |
required: true | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: # Job-level permissions configuration starts here | |
contents: write # 'write' access to repository contents | |
pull-requests: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 14 | |
- name: Install dependencies | |
run: npm install | |
- name: Update version in package.json | |
run: | | |
sed -i "s/\"version\": \".*\"/\"version\": \"${{ github.event.inputs.version }}\"/" package.json | |
- name: Commit and push changes | |
run: | | |
git config --global user.email ${{secrets.ADMIN_EMAIL}} | |
git config --global user.name ${{secrets.ORG_NAME}} | |
git add package.json | |
if git diff --exit-code; then | |
echo "No changes to commit." | |
else | |
git add . | |
git commit -am "Bump version to ${{ github.event.inputs.version }}" | |
git pull origin main | |
git push https://${{secrets.WORKFLOW_TOKEN}}@github.com/ingrammicro-xvantage/xi-sdk-resellers-node.git main | |
fi | |
- name: Build SDK | |
run: | | |
npm ci | |
- name: Authenticate with npm | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN}} |