Skip to content

Commit

Permalink
chore: encode npm disttag in version resolution (#12627)
Browse files Browse the repository at this point in the history
This version is used by check-api-compatibility.sh instead of relying on
the environment variables.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar committed Jan 20, 2021
1 parent 0673966 commit d613447
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion release.json
@@ -1,4 +1,5 @@
{
"majorVersion": 1,
"releaseType": "stable"
"releaseType": "stable",
"distTag": "latest"
}
16 changes: 3 additions & 13 deletions scripts/check-api-compatibility.sh
Expand Up @@ -57,22 +57,12 @@ if ! ${SKIP_DOWNLOAD:-false}; then

echo "Determining baseline version..." >&2
version=$(node -p 'require("./scripts/resolve-version.js").version')
disttag=$(node -p 'require("./scripts/resolve-version.js").npmDistTag')
echo " Current version is $version." >&2

if ! package_exists_on_npm aws-cdk $version; then
echo " Version $version does not exist in npm. Falling back to env vars." >&2
# occurs within a release PR where the version is bumped but is not yet published to npm.
major_version=$(echo $version | cut -d '.' -f 1)
if [ "$major_version" == "1" ]; then
echo " Setting version to $NPM_DISTTAG_V1" >&2
version=$NPM_DISTTAG_V1
elif [ "$major_version" == "2" ]; then
echo " Setting version to $NPM_DISTTAG_V2" >&2
version=$NPM_DISTTAG_V2
else
echo "Unknown major version $major_version. Failing..." >&2
exit 1
fi
echo " Version $version does not exist in npm. Falling back to resolved dist tag '$disttag'" >&2
version=$disttag
fi

echo "Using version '$version' as the baseline..."
Expand Down
2 changes: 2 additions & 0 deletions scripts/resolve-version-lib.js
Expand Up @@ -17,6 +17,7 @@ function resolveVersion(rootdir) {
const releaseConfig = require(releaseFile);
const majorVersion = releaseConfig.majorVersion;
const releaseType = releaseConfig.releaseType;
const distTag = releaseConfig.distTag;
if (!majorVersion) { throw new Error(`"majorVersion"" must be defined in ${releaseFile}`); }
if (!releaseType) { throw new Error(`"releaseType" must be defined in ${releaseFile}`); }
if (typeof(majorVersion) !== 'number') { throw new Error(`majorVersion=${majorVersion} must be a number`); }
Expand Down Expand Up @@ -69,6 +70,7 @@ function resolveVersion(rootdir) {
changelogFile: changelogFile,
prerelease: releaseType !== 'stable' ? releaseType : undefined,
marker: '0.0.0',
...(distTag ? { npmDistTag: distTag } : {}),
};
}

Expand Down
17 changes: 17 additions & 0 deletions scripts/script-tests/resolve-version.test.js
Expand Up @@ -80,6 +80,23 @@ happy({
}
});

happy({
name: 'dist tag is correctly shown',
inputs: {
'release.json': { majorVersion: 2, releaseType: 'alpha', distTag: 'v2-preview' },
'version.v2.json': { version: '2.0.0-alpha.5' }
},
expected: {
changelogFile: 'CHANGELOG.v2.md',
marker: '0.0.0',
prerelease: 'alpha',
version: '2.0.0-alpha.5',
versionFile: 'version.v2.json',
npmDistTag: 'v2-preview',
}
});


failure({
name: 'invalid release type',
inputs: { 'release.json': { majorVersion: 2, releaseType: 'build' } },
Expand Down

0 comments on commit d613447

Please sign in to comment.