nx/scripts/release-docs.ts
MaxKless b73f1e0e00
fix(core): set windowsHide: true wherever possible (#28073)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-09-24 11:31:22 -04:00

37 lines
1.4 KiB
TypeScript

import { execSync } from 'child_process';
import { gte, major, maxSatisfying } from 'semver';
// The GITHUB_REF_NAME is a full version (i.e. 17.3.2). The branchName will strip the patch version number.
// We will publish docs to the website branch based on the current tag (i.e. website-17)
const currentVersion = process.env.GITHUB_REF_NAME || '';
console.log(`Comparing ${currentVersion} to npm versions`);
const majorVersion = major(currentVersion);
const releasedVersions: string[] = JSON.parse(
execSync(`npm show nx@^${majorVersion} version --json`, {
windowsHide: true,
}).toString()
);
const latestVersion = maxSatisfying(releasedVersions, `^${majorVersion}`);
console.log(`Found npm versions:\n${releasedVersions.join('\n')}`);
// Publish if the current version is greater than or equal to the latest released version
const branchName = `website-${majorVersion}`;
if (currentVersion && latestVersion && gte(currentVersion, latestVersion)) {
console.log(
`Publishing docs site for ${process.env.GITHUB_REF_NAME} to ${branchName}`
);
// We force recreate the branch in order to always be up to date and avoid merge conflicts within the automated workflow
execSync(`git branch -f ${branchName}`, {
windowsHide: true,
});
execSync(`git push -f origin ${branchName}`, {
windowsHide: true,
});
} else {
console.log(`Not publishing docs to ${branchName}`);
}