Skip to content

Commit

Permalink
vx: allow for pre-set version update
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed May 6, 2023
1 parent 56be98f commit fb369c3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- release
- release-keep-version
- integration
- integration-*
- next
Expand Down Expand Up @@ -39,6 +40,7 @@ jobs:
run: yarn release
env:
RELEASE_BRANCH: release
RELEASE_KEEP_VERSION_BRANCH: release-keep-version
INTEGRATION_BRANCH: integration
NEXT_BRANCH: next
STABLE_BRANCH: stable
Expand Down
7 changes: 4 additions & 3 deletions vx/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
DEVELOPMENT: 'development',
TEST: 'test',
},

fileNames: {
CHANGELOG: 'CHANGELOG.md',
JEST_CONFIG: 'jest.config.js',
Expand All @@ -29,12 +30,12 @@ module.exports = {
TSCONFIG_JSON: 'tsconfig.json',
VX_BUILD: 'vx.build.js',
},
packageJsonFields: {
VX: 'vx',
},
format: {
UMD: 'umd',
CJS: 'cjs',
ES: 'es',
},
packageJsonFields: {
VX: 'vx',
},
};
14 changes: 12 additions & 2 deletions vx/scripts/release/genDiffData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
isIntegrationBranch,
isReleaseBranch,
isNextBranch,
isReleaseKeepVersionBranch,
} = require('vx/util/taggedBranch');
const { CURRENT_BRANCH } = require('vx/util/taggedBranch');
const { usePackage } = require('vx/vxContext');
Expand All @@ -31,6 +32,11 @@ function genDiffData(commits) {
tag,
tagId,
version,
versionToPublish: isReleaseKeepVersionBranch
? version
: tag
? tagId
: nextVersion,
};
}

Expand All @@ -46,12 +52,16 @@ function pickTagId(nextVersion) {
const commitHash = GITHUB_SHA.substr(0, 6);

if (isNextBranch) {
return `${nextVersion}-${TAG_NEXT}-${commitHash}`;
return getTag(nextVersion, TAG_NEXT, commitHash);
}

if (isIntegrationBranch) {
return `${nextVersion}-${TAG_DEV}-${commitHash}`;
return getTag(nextVersion, TAG_DEV, commitHash);
}

throw Error('pickTagId: Encountered an unexpected input.');
}

function getTag(...keywords) {
return keywords.filter(Boolean).join('-');
}
13 changes: 5 additions & 8 deletions vx/scripts/release/steps/publishPackage.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
const { TAG_NEXT } = require('../releaseKeywords');
const { TAG_NEXT, TAG_DEV } = require('../releaseKeywords');

const exec = require('vx/exec');
const logger = require('vx/logger');
const { TAG_DEV } = require('vx/scripts/release/releaseKeywords');
const joinTruthy = require('vx/util/joinTruthy');
const { isReleaseBranch } = require('vx/util/taggedBranch');
const { usePackage } = require('vx/vxContext');
const vxPath = require('vx/vxPath');

function publishPackage({ tag, tagId, nextVersion }) {
const versionToUse = tag && tagId ? tagId : nextVersion;

function publishPackage({ tag, tagId, versionToPublish }) {
logger.info(`🚀 Publishing package ${usePackage()}.
Version: ${versionToUse}
Version: ${versionToPublish}
Tag Id: ${tagId}
Tag: ${tag}`);

if (!shouldRelease(versionToUse)) {
if (!shouldRelease(versionToPublish)) {
return logger.info(`❌ Not in release branch. Skipping publish.`);
}

const command = genPublishCommand(versionToUse, tag);
const command = genPublishCommand(versionToPublish, tag);
execCommandWithGitConfig(command);
clearTag(tag, tagId);
}
Expand Down
37 changes: 29 additions & 8 deletions vx/scripts/release/steps/setNextVersion.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
const { writeJSONSync } = require('fs-extra');

const { isReleaseKeepVersionBranch } = require('../../../util/taggedBranch');

const logger = require('vx/logger');
const packageJson = require('vx/util/packageJson');
const { usePackage } = require('vx/vxContext');
const vxPath = require('vx/vxPath');

function setNextVersion({ tagId, tag, nextVersion }) {
function setNextVersion({
tagId,
tag,
nextVersion,
versionToPublish,
changeLevel,
}) {
const packageName = usePackage();
const existingPkgJson = packageJson(packageName);

const prevVersion = existingPkgJson.version;
if (isReleaseKeepVersionBranch) {
logger.info(
`🔢 Skipping version update for ${usePackage()} due to release keep version branch.
Version being kept: ${existingPkgJson.version}.
Diff data:
packageName: ${packageName}
changeLevel: ${changeLevel}
tagId: ${tagId}
tag: ${tag}
versionToPublish: ${versionToPublish}`
);
return;
}

nextVersion = tag ? tagId : nextVersion;
const prevVersion = existingPkgJson.version;

const nextPackageJson = { ...existingPkgJson, version: nextVersion };
const nextPackageJson = { ...existingPkgJson, version: versionToPublish };

existingPkgJson.version = nextVersion;
existingPkgJson.version = versionToPublish;

logger.info(
`🔢 Setting next version for ${usePackage()}. From ${prevVersion} to ${nextVersion}`
`🔢 Setting next version for ${usePackage()}. From ${prevVersion} to ${versionToPublish}`
);

writeJSONSync(vxPath.packageJson(packageName), nextPackageJson, {
Expand All @@ -27,9 +48,9 @@ function setNextVersion({ tagId, tag, nextVersion }) {

const updated = packageJson(packageName);

if (updated.version !== nextVersion) {
if (updated.version !== versionToPublish) {
logger.error(
`🚨 Failed to update ${usePackage()} version to: ` + nextVersion
`🚨 Failed to update ${usePackage()} version to: ` + versionToPublish
);
return process.exit(1);
}
Expand Down
5 changes: 5 additions & 0 deletions vx/util/taggedBranch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
LATEST_BRANCH,
STABLE_BRANCH,
RELEASE_BRANCH,
RELEASE_KEEP_VERSION_BRANCH,
} = process.env;
const packageNames = require('vx/packageNames');

Expand All @@ -13,6 +14,9 @@ const isNextBranch = CURRENT_BRANCH.startsWith(NEXT_BRANCH);
const isLatestBranch = CURRENT_BRANCH.startsWith(LATEST_BRANCH);
const isStableBranch = CURRENT_BRANCH.startsWith(STABLE_BRANCH);
const isReleaseBranch = CURRENT_BRANCH.startsWith(RELEASE_BRANCH);
const isReleaseKeepVersionBranch = CURRENT_BRANCH.startsWith(
RELEASE_KEEP_VERSION_BRANCH
);
const [, target = undefined] =
isIntegrationBranch || isNextBranch ? CURRENT_BRANCH.split('-') : [];

Expand All @@ -31,6 +35,7 @@ module.exports = {
isLatestBranch,
isNextBranch,
isReleaseBranch,
isReleaseKeepVersionBranch,
isStableBranch,
targetPackage: packageNames.names[target],
};

0 comments on commit fb369c3

Please sign in to comment.