Skip to content

Commit

Permalink
ci: check version has increased on PRs (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
sphars authored Jul 8, 2024
1 parent 35b66db commit 72916d1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/version-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fs = require("fs");
const { execSync } = require("child_process");
const semver = require("semver");

// Read the current branch's package.json
const currentPackage = JSON.parse(fs.readFileSync("package.json", "utf8"));
const currentVersion = currentPackage.version;

// Fetch the package.json from the main branch
execSync("git fetch origin main:main");
const mainPackageJson = execSync("git show main:package.json").toString();
const mainPackage = JSON.parse(mainPackageJson);
const mainVersion = mainPackage.version;

if (semver.gt(currentVersion, mainVersion)) {
console.log(`Version check passed: ${mainVersion} -> ${currentVersion}`);
process.exit(0);
} else {
console.error(`Version check failed: ${mainVersion} -> ${currentVersion}`);
console.error("Please increment the version number in package.json");
process.exit(1);
}
3 changes: 3 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Check version
run: node .github/scripts/version-check.js

- name: Check Prettifier
run: npm run pretty:check

Expand Down
17 changes: 15 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "math-sheets",
"version": "0.2.2",
"version": "0.2.3",
"private": true,
"description": "A simple website for printing math worksheets",
"scripts": {
Expand Down Expand Up @@ -33,6 +33,7 @@
"@types/node": "^20.14.9",
"husky": "^9.0.11",
"prettier": "3.3.2",
"semver": "^7.6.2",
"typescript": "^5.5.2",
"vite": "^5.3.1"
}
Expand Down

0 comments on commit 72916d1

Please sign in to comment.