Skip to content

Update npm-publish.yml #8

Update npm-publish.yml

Update npm-publish.yml #8

Workflow file for this run

name: Js Sdk Package
on:
push:
branches:
- main
jobs:
update-package-json:
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 { execSync } = require('child_process');
const path = './package.json';
const pkg = require(path);
const repo = process.env.GITHUB_REPOSITORY.split('/')[1];
pkg.name = repo;
try {
const latestVersion = execSync('npm view ' + repo + ' version').toString().trim();
const versionParts = latestVersion.split('.');
versionParts[2] = (parseInt(versionParts[2]) + 1).toString();
pkg.version = versionParts.join('.');
} catch (error) {
console.error('Error fetching latest version:', error);
pkg.version = '1.0.0';
}
fs.writeFileSync(path, JSON.stringify(pkg, null, 2));
console.log('Updated name:', pkg.name);
console.log('Updated version:', pkg.version);
"
- run: |
echo "Name and version from package.json:"
cat package.json | jq '.name, .version'
- run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- run: npm test
- run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}