Skip to content

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

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

Merged
merged 17 commits into from
Sep 24, 2024
Merged
82 changes: 70 additions & 12 deletions scripts/check_changeset_completeness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,73 @@ 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';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ReleasePlan } from '@changesets/types';
Copy link
Member

Choose a reason for hiding this comment

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

we should just add this package as dev dep.


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 checkBackendDependenciesVersion = (releasePlan: ReleasePlan) => {
const backendDependencies: string[] = [
'@aws-amplify/backend-auth',
'@aws-amplify/backend-data',
'@aws-amplify/backend-function',
'@aws-amplify/backend-storage',
];
const backendName: string = '@aws-amplify/backend';
const versionBumpOfWrongKind: string[] = [];
let backendMaxVersionType: string = 'none';

for (const changeset of releasePlan.changesets) {
for (const release of changeset.releases) {
if (release.name === backendName) {
if (
release.type === 'major' ||
backendMaxVersionType === 'none' ||
(backendMaxVersionType === 'patch' && release.type === 'minor')
) {
backendMaxVersionType = release.type;
}
}
}
}

for (const changeset of releasePlan.changesets) {
for (const release of changeset.releases) {
if (backendDependencies.includes(release.name)) {
if (
backendMaxVersionType !== release.type &&
(release.type === 'major' ||
backendMaxVersionType === 'none' ||
(backendMaxVersionType === 'patch' && release.type === 'minor'))
) {
versionBumpOfWrongKind.push(release.name);
}
}
}
}

if (versionBumpOfWrongKind.length > 0) {
throw new Error(
`${backendName} has a version bump of a different kind of the following packages but is expected to have a version bump of the same kind:${EOL}${versionBumpOfWrongKind.join(
EOL
)}`
);
}
};

const gitClient = new GitClient();

Expand All @@ -18,18 +85,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 +106,5 @@ if (packagesMissingChangesets.length > 0) {
)}${EOL}${EOL}Add a changeset using 'npx changeset add'.`
);
}

checkBackendDependenciesVersion(releasePlan);