Skip to content

Commit

Permalink
ciworkflow: enhance GitHub Actions and bump version script
Browse files Browse the repository at this point in the history
- Add npm registry URL to GitHub Actions workflow for consistent package resolution
- Improve error handling in bump-version.js:
  - Use 'pipe' for stdio to capture and display error messages
  - Exit with code1 on failure to fetch npm version- Remove redundant package.json fallback logic
  • Loading branch information
MrCoder committed Dec 17, 2024
1 parent 9e549aa commit 7a4c814
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
with:
node-version: "18"
cache: pnpm
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: pnpm install
- name: Run tests
Expand All @@ -55,6 +56,7 @@ jobs:
with:
node-version: "18"
cache: pnpm
registry-url: "https://registry.npmjs.org"
- run: pnpm install
- name: Bump Version
id: bump
Expand Down Expand Up @@ -83,6 +85,7 @@ jobs:
with:
node-version: "18"
cache: pnpm
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: pnpm install
- name: Build the site for demo page and embed view
Expand Down
16 changes: 9 additions & 7 deletions scripts/bump-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ const path = require("path");

const getCurrentVersion = () => {
try {
// Get latest version from npm
const pkg = require("../package.json");
const npmVersion = execSync(`npm view ${pkg.name} version`)
const npmVersion = execSync(`npm view ${pkg.name} version`, {
stdio: ["pipe", "pipe", "pipe"],
})
.toString()
.trim();
console.log(`Latest version on npm: ${npmVersion}`);
return npmVersion;
} catch (e) {
// Package not published yet, use package.json as fallback
const pkg = require("../package.json");
console.log("Package not found on npm, using version from package.json");
return pkg.version;
} catch (error) {
console.error(
"Failed to get npm version. Please ensure you have npm registry access.",
);
console.error("Error:", error.message);
process.exit(1);
}
};

Expand Down

0 comments on commit 7a4c814

Please sign in to comment.