Minor fixes
This commit is contained in:
@@ -8,7 +8,7 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: 'Release tag, e.g. v0.1.1 (the tag is created at the current commit on this branch)'
|
description: 'Release tag, e.g. v0.3.2.1 (the tag is created at the current commit on this branch)'
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
prerelease:
|
prerelease:
|
||||||
@@ -42,7 +42,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
VERSION: ${{ inputs.version }}
|
VERSION: ${{ inputs.version }}
|
||||||
run: npm version "${VERSION#v}" --no-git-tag-version --allow-same-version
|
run: node scripts/stamp-version.js "${VERSION#v}"
|
||||||
|
|
||||||
- name: Configure Windows code signing
|
- name: Configure Windows code signing
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -86,7 +86,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
VERSION: ${{ inputs.version }}
|
VERSION: ${{ inputs.version }}
|
||||||
run: npm version "${VERSION#v}" --no-git-tag-version --allow-same-version
|
run: node scripts/stamp-version.js "${VERSION#v}"
|
||||||
|
|
||||||
- name: Package Linux artifacts (tarball + .deb)
|
- name: Package Linux artifacts (tarball + .deb)
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
|
||||||
|
function readJson(file) {
|
||||||
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeJson(file, value) {
|
||||||
|
fs.writeFileSync(file, JSON.stringify(value, null, 2) + '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
function stampVersion(rootDir, version) {
|
||||||
|
if (!version || typeof version !== 'string') {
|
||||||
|
throw new Error('version is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
const pkgPath = path.join(rootDir, 'package.json');
|
||||||
|
const pkg = readJson(pkgPath);
|
||||||
|
pkg.version = version;
|
||||||
|
writeJson(pkgPath, pkg);
|
||||||
|
|
||||||
|
const lockPath = path.join(rootDir, 'package-lock.json');
|
||||||
|
if (!fs.existsSync(lockPath)) return;
|
||||||
|
|
||||||
|
const lock = readJson(lockPath);
|
||||||
|
lock.version = version;
|
||||||
|
if (lock.packages && lock.packages['']) {
|
||||||
|
lock.packages[''].version = version;
|
||||||
|
}
|
||||||
|
writeJson(lockPath, lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
try {
|
||||||
|
const version = process.argv[2] || process.env.VERSION;
|
||||||
|
stampVersion(process.cwd(), version);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err && err.message ? err.message : err);
|
||||||
|
process.exitCode = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { stampVersion };
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
|
||||||
|
const { makeTmpDir, rmrf } = require('./helpers');
|
||||||
|
const { stampVersion } = require('../../scripts/stamp-version');
|
||||||
|
|
||||||
|
test('stampVersion updates package metadata without semver validation', () => {
|
||||||
|
const root = makeTmpDir('stamp-version');
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({
|
||||||
|
name: 'stepforge',
|
||||||
|
version: '0.1.0',
|
||||||
|
private: true,
|
||||||
|
}, null, 2));
|
||||||
|
|
||||||
|
fs.writeFileSync(path.join(root, 'package-lock.json'), JSON.stringify({
|
||||||
|
name: 'stepforge',
|
||||||
|
version: '0.1.0',
|
||||||
|
lockfileVersion: 3,
|
||||||
|
requires: true,
|
||||||
|
packages: {
|
||||||
|
'': {
|
||||||
|
name: 'stepforge',
|
||||||
|
version: '0.1.0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, null, 2));
|
||||||
|
|
||||||
|
stampVersion(root, '0.3.2.1');
|
||||||
|
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||||
|
const lock = JSON.parse(fs.readFileSync(path.join(root, 'package-lock.json'), 'utf8'));
|
||||||
|
|
||||||
|
assert.equal(pkg.version, '0.3.2.1');
|
||||||
|
assert.equal(lock.version, '0.3.2.1');
|
||||||
|
assert.equal(lock.packages[''].version, '0.3.2.1');
|
||||||
|
} finally {
|
||||||
|
rmrf(root);
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user