Skip to content

Update npm-publish.yml #4

Update npm-publish.yml

Update npm-publish.yml #4

Workflow file for this run

name: Js Sdk Package
on:
push:
branches:
- main
jobs:
update-package-json:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- run: |
node -e "
const fs = require('fs');
const path = './package.json';
const pkg = require(path);
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
pkg.name = repo;
const versionParts = pkg.version.split('.');
versionParts[2] = (parseInt(versionParts[2]) + 1).toString();
pkg.version = versionParts.join('.');
fs.writeFileSync(path, JSON.stringify(pkg, null, 2));
console.log('Updated name:', pkg.name);
console.log('Updated version:', pkg.version);
"
env:
GITHUB_REPOSITORY: ${{ github.repository }}
- run: |
echo "Name and version from package.json:"
cat package.json | jq '.name, .version'
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
- run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- run: npm test
publish-npm:
needs: update-package-json
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}