Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/hotfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: Update version
run: node common/scripts/install-run-rush.js version --bump

- name: Validate hotfix versions
run: node common/scripts/validate-release-version.js ${{ steps.semver_parser.outputs.full }}

- name: Build packages
run: node common/scripts/install-run-rush.js build --only tag:package

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
- name: Apply prereleaseName
run: node common/scripts/apply-release-version.js ${{ steps.semver_parser.outputs.pre_release_name }} ${{ steps.semver_parser.outputs.main }}

- name: Validate prerelease versions
run: node common/scripts/validate-release-version.js ${{ steps.semver_parser.outputs.full }}

- name: Build packages
run: node common/scripts/install-run-rush.js build --only tag:package

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
- name: Update version
run: node common/scripts/apply-release-version.js 'none' ${{ steps.semver_parser.outputs.main }}

- name: Validate release versions
run: node common/scripts/validate-release-version.js ${{ steps.semver_parser.outputs.main }}

- name: Build packages
run: node common/scripts/install-run-rush.js build --only tag:package

Expand Down
40 changes: 19 additions & 21 deletions common/scripts/pre-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@
const checkAndUpdateNextBump = require('./version-policies');
const getPackageJson = require('./get-package-json');
const writePrereleaseVersion = require('./set-prerelease-version');
const validateReleaseVersion = path.join(__dirname, './validate-release-version.js');


const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(alpha|beta|rc)(?:\.(?:(0|[1-9])))*)$/;

const preReleaseNameReg = /^((alpha|beta|rc)(?:\.(?:0|[1-9]))*)$/;

function runCommand(command) {
const res = spawnSync('sh', ['-c', command], {
stdio: 'inherit',
shell: false,
});

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium

This shell command depends on an uncontrolled
absolute path
.
Comment on lines +19 to +22

if (res.status !== 0) {
process.exit(res.status || 1);
}
}

function run() {
let preReleaseName = process.argv.slice(2)[0];
Expand Down Expand Up @@ -54,41 +65,28 @@

if (preReleaseName && preReleaseType) {
// 1. apply version and update version of package.json
writePrereleaseVersion(checkAndUpdateNextBump(process.argv.slice(2)[1]), preReleaseName)
writePrereleaseVersion(checkAndUpdateNextBump(process.argv.slice(2)[1]), null, preReleaseName)

runCommand(`node ${validateReleaseVersion}`);

// 2. build all the packages
spawnSync('sh', ['-c', `rush build --only tag:package`], {
stdio: 'inherit',
shell: false,
});
runCommand(`rush build --only tag:package`);

// 3. publish to npm
spawnSync('sh', ['-c', `rush publish --publish --include-all --tag ${preReleaseType}`], {
stdio: 'inherit',
shell: false,
});
runCommand(`rush publish --publish --include-all --tag ${preReleaseType} --set-access-level public`);

// 4. update version of local packages to shrinkwrap
spawnSync('sh', ['-c', `rush update`], {
stdio: 'inherit',
shell: false,
});
runCommand(`rush update`);

if (package) {
const pkgJsonPath = path.join(__dirname, '../../', package.projectFolder, 'package.json');
const pkgJson = getPackageJson(pkgJsonPath)

// 5. add the the changes
spawnSync('sh', ['-c', `git add --all`], {
stdio: 'inherit',
shell: false,
});
runCommand(`git add --all`);

// 6. commit all the changes
spawnSync('sh', ['-c', `git commit -m "build: prerelease version ${pkgJson.version}"`], {
stdio: 'inherit',
shell: false,
});
runCommand(`git commit -m "build: prerelease version ${pkgJson.version}"`);
}
}
}
Expand Down
69 changes: 28 additions & 41 deletions common/scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,67 @@
/**
* prelease
* node release.js [alpha.0] [patch | major | minor | 1.0.0]
* release
* node release.js [patch | major | minor | 1.0.0]
*/

const { spawnSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const checkAndUpdateNextBump = require('./version-policies');
const getPackageJson = require('./get-package-json');
const validateReleaseVersion = path.join(__dirname, './validate-release-version.js');

function getPackageJson(pkgJsonPath) {
const pkgJson = fs.readFileSync(pkgJsonPath, { encoding: 'utf-8' })
return JSON.parse(pkgJson)
function runCommand(command) {
const res = spawnSync('sh', ['-c', command], {
stdio: 'inherit',
shell: false,
});

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium

This shell command depends on an uncontrolled
absolute path
.
Comment on lines +13 to +16

if (res.status !== 0) {
process.exit(res.status || 1);
}
}

function getExpectedVersion(releaseVersion) {
return /^\d+\.\d+\.\d+$/.test(releaseVersion || '') ? releaseVersion : '';
}

function run() {
let releaseVersion = process.argv.slice(2)[0];
const cwd = process.cwd();
// 0. update `nextBump`
checkAndUpdateNextBump(releaseVersion);

// 1. update version of package.json, this operation will remove the common/changes
spawnSync('sh', ['-c', `rush version --bump`], {
stdio: 'inherit',
shell: false,
});
runCommand(`rush version --bump`);

runCommand(`node ${validateReleaseVersion} ${getExpectedVersion(releaseVersion)}`);


// 2. build all the packages
spawnSync('sh', ['-c', `rush build --only tag:package`], {
stdio: 'inherit',
shell: false,
});
runCommand(`rush build --only tag:package`);

// 3. publish to npm
spawnSync('sh', ['-c', 'rush publish --publish --include-all'], {
stdio: 'inherit',
shell: false,
});
runCommand('rush publish --publish --include-all --set-access-level public');

// 4. update version of local packages to shrinkwrap
spawnSync('sh', ['-c', `rush update`], {
stdio: 'inherit',
shell: false,
});
runCommand(`rush update`);

const rushJson = getPackageJson(path.join(__dirname, '../../rush.json'));
const package = rushJson.projects.find((project) => project.name === '@visactor/vchart-theme');
const project = rushJson.projects.find((item) => item.packageName === '@visactor/vchart-theme');

if (package) {
if (project) {
const pkgJsonPath = path.join(__dirname, '../../', project.projectFolder, 'package.json')
const pkgJson = getPackageJson(pkgJsonPath)

// 5. add tag
spawnSync('sh', ['-c', `git tag v${pkgJson.versopn}`], {
stdio: 'inherit',
shell: false,
});
runCommand(`git tag v${pkgJson.version}`);

// 6. add all the changes
spawnSync('sh', ['-c', `git add --all`], {
stdio: 'inherit',
shell: false,
});
runCommand(`git add --all`);

// 7. commit all the changes
spawnSync('sh', ['-c', `git commit -m "build: publish version ${pkgJson.version}"`], {
stdio: 'inherit',
shell: false,
});
runCommand(`git commit -m "build: publish version ${pkgJson.version}"`);

// 8. push tag to origin
spawnSync('sh', ['-c', `git push origin v${pkgJson.version}`], {
stdio: 'inherit',
shell: false,
});
runCommand(`git push origin v${pkgJson.version}`);
}
}

Expand Down
58 changes: 58 additions & 0 deletions common/scripts/validate-release-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const path = require('path');
const getPackageJson = require('./get-package-json');

function fail(message) {
console.error(`\x1b[31m[release version error]\x1b[0m ${message}`);
process.exitCode = 1;
}

function run() {
const expectedVersion = process.argv.slice(2)[0];
const rushJson = getPackageJson(path.join(__dirname, '../../rush.json'));
const projects = rushJson.projects || [];
const publishProjects = projects.filter(project => project.shouldPublish);
const mainProject = publishProjects.find(project => project.packageName === '@visactor/vchart-theme');

if (!mainProject) {
fail('Cannot find @visactor/vchart-theme in rush.json.');
return;
}

const mainPkgJson = getPackageJson(path.join(__dirname, '../../', mainProject.projectFolder, 'package.json'));
const releaseVersion = expectedVersion || mainPkgJson.version;
const publishPackages = publishProjects.map(project => project.packageName);

publishProjects.forEach(project => {
const pkgJsonPath = path.join(__dirname, '../../', project.projectFolder, 'package.json');
const pkgJson = getPackageJson(pkgJsonPath);

if (pkgJson.version !== releaseVersion) {
fail(`${project.packageName} version is ${pkgJson.version}, expected ${releaseVersion}.`);
}

['dependencies', 'devDependencies'].forEach(depType => {
const deps = pkgJson[depType];

if (!deps) {
return;
}

publishPackages.forEach(packageName => {
const depVersion = deps[packageName];
const expectedDepVersion = `workspace:${releaseVersion}`;

if (depVersion && depVersion !== expectedDepVersion) {
fail(`${project.packageName} ${depType}.${packageName} is ${depVersion}, expected ${expectedDepVersion}.`);
}
});
});
});

if (process.exitCode) {
return;
}

console.log(`All publish package versions are aligned at ${releaseVersion}.`);
}

run();
Loading