Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@aws-amplify/backend should inherit version bump of same kind from dependencies #2042

Merged
merged 17 commits into from
Sep 24, 2024
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@aws-sdk/client-ssm": "^3.624.0",
"@changesets/cli": "^2.26.1",
"@changesets/get-release-plan": "^4.0.0",
"@changesets/types": "^6.0.0",
"@microsoft/api-extractor": "7.43.8",
"@octokit/webhooks-types": "^7.5.1",
"@shopify/eslint-plugin": "^43.0.0",
Expand Down
117 changes: 105 additions & 12 deletions scripts/check_changeset_completeness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,108 @@ import getReleasePlan from '@changesets/get-release-plan';
import { GitClient } from './components/git_client.js';
import { readPackageJson } from './components/package-json/package_json.js';
import { EOL } from 'os';
import { ReleasePlan, VersionType } from '@changesets/types';

enum VersionTypeEnum {
'NONE' = 0,
'PATCH' = 1,
'MINOR' = 2,
'MAJOR' = 3,
}

const getModifiedPackages = (changedFiles: string[]): Set<string> => {
const modifiedPackageDirs = new Set<string>();

changedFiles
.filter(
(changedFile) =>
changedFile.startsWith('packages/') && !changedFile.endsWith('test.ts')
)
.forEach((changedPackageFile) => {
modifiedPackageDirs.add(
changedPackageFile.split('/').slice(0, 2).join('/')
);
});
return modifiedPackageDirs;
};

const versionTypeConverter = (version: VersionType): VersionTypeEnum => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const versionTypeConverter = (version: VersionType): VersionTypeEnum => {
const convertVersionType = (version: VersionType): VersionTypeEnum => {

function name should be verb-ish.

switch (version) {
case 'major':
return VersionTypeEnum.MAJOR;
case 'minor':
return VersionTypeEnum.MINOR;
case 'patch':
return VersionTypeEnum.PATCH;
case 'none':
return VersionTypeEnum.NONE;
}
};

const findEffectiveVersion = (
releasePlan: ReleasePlan,
packageName: string
): VersionTypeEnum => {
let effectiveVersion: VersionTypeEnum = VersionTypeEnum.NONE;

for (const changeset of releasePlan.changesets) {
for (const release of changeset.releases) {
if (release.name === packageName) {
const releaseVersionType = versionTypeConverter(release.type);
if (releaseVersionType > effectiveVersion) {
effectiveVersion = releaseVersionType;
}
}
}
}
return effectiveVersion;
};

const maxVersion = (
version1: VersionTypeEnum,
version2: VersionTypeEnum,
version3: VersionTypeEnum,
version4: VersionTypeEnum
) => {
return Math.max(version1, version2, version3, version4);
};

const checkBackendDependenciesVersion = (releasePlan: ReleasePlan) => {
const backendVersion: VersionTypeEnum = findEffectiveVersion(
releasePlan,
'@aws-amplify/backend'
);
const backendAuthVersion: VersionTypeEnum = findEffectiveVersion(
releasePlan,
'@aws-amplify/backend-auth'
);
const backendDataVersion: VersionTypeEnum = findEffectiveVersion(
releasePlan,
'@aws-amplify/backend-data'
);
const backendFunctionVersion: VersionTypeEnum = findEffectiveVersion(
releasePlan,
'@aws-amplify/backend-function'
);
const backendStorageVersion: VersionTypeEnum = findEffectiveVersion(
releasePlan,
'@aws-amplify/backend-storage'
);

if (
backendVersion <
maxVersion(
backendAuthVersion,
backendDataVersion,
backendFunctionVersion,
backendStorageVersion
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maxVersion(
backendAuthVersion,
backendDataVersion,
backendFunctionVersion,
backendStorageVersion
)
Math.max(
backendAuthVersion,
backendDataVersion,
backendFunctionVersion,
backendStorageVersion
)

would this just work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, the function is unnecessary

) {
throw new Error(
`@aws-amplify/backend has a version bump of a different kind from its dependencies (@aws-amplify/backend-auth, @aws-amplify/backend-data, @aws-amplify/backend-function, and @aws-amplify/backend-storage) but is expected to have a version bump of the same kind.${EOL}`
);
}
};

const gitClient = new GitClient();

Expand All @@ -18,18 +120,7 @@ const packagesWithChangeset = new Set(

const changedFiles = await gitClient.getChangedFiles(baseRef);

const modifiedPackageDirs = new Set<string>();

changedFiles
.filter(
(changedFile) =>
changedFile.startsWith('packages/') && !changedFile.endsWith('test.ts')
)
.forEach((changedPackageFile) => {
modifiedPackageDirs.add(
changedPackageFile.split('/').slice(0, 2).join('/')
);
});
const modifiedPackageDirs = getModifiedPackages(changedFiles);

const packagesMissingChangesets = [];
for (const modifiedPackageDir of modifiedPackageDirs) {
Expand All @@ -50,3 +141,5 @@ if (packagesMissingChangesets.length > 0) {
)}${EOL}${EOL}Add a changeset using 'npx changeset add'.`
);
}

checkBackendDependenciesVersion(releasePlan);