Skip to content

Commit

Permalink
Update npm-publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
ucatbas authored Jul 29, 2024
1 parent 9ff5657 commit 477a45c
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,34 @@ jobs:
- run: |
node -e "
const fs = require('fs');
const { execSync } = require('child_process');
const path = './package.json';
const pkg = require(path);
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const repo = process.env.GITHUB_REPOSITORY.split('/')[1];
pkg.name = repo;
const versionParts = pkg.version.split('.');
versionParts[2] = (parseInt(versionParts[2]) + 1).toString();
pkg.version = versionParts.join('.');
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);
"
env:
GITHUB_REPOSITORY: ${{ github.repository }}
- run: |
echo "Name and version from package.json:"
cat package.json | jq '.name, .version'
build:
needs: update-package-json
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: build
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
Expand Down

0 comments on commit 477a45c

Please sign in to comment.