-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 65c6794.
|
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { ReleasePlan } from '@changesets/types'; |
There was a problem hiding this comment.
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 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 | ||
)}` | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is a bit hard to read.
Consider adding const maxVersion = (...versionType: Array<string>): string => { // some logic to pick max }
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 backendName: string = '@aws-amplify/backend'; | |
let effectiveBackendVersionType: string = 'none'; | |
let effectiveBackendDependenciesVersionType: string = 'none'; | |
for (const changeset of releasePlan.changesets) { | |
for (const release of changeset.releases) { | |
if (release.name === backendName) { | |
effectiveBackendVersionType = maxVersion(effectiveBackendVersionType, release.type); | |
} | |
} | |
} | |
for (const changeset of releasePlan.changesets) { | |
for (const release of changeset.releases) { | |
if (backendDependencies.includes(release.name)) { | |
effectiveBackendDependenciesVersionType = maxVersion(effectiveBackendDependenciesVersionType, release.type); | |
} | |
} | |
} | |
if (effectiveBackendVersionType !== effectiveBackendDependenciesVersionType) { | |
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 | |
)}` | |
); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also consider something like this.
Assuming maxVersion(...versions)
and findEffectiveVersion(releasePlan, packageName
have something like that:
const backendVersion = findEffectiveVersion(releasePlan, '@aws-amplify/backend`);
const backendAuthVersion = findEffectiveVersion(releasePlan, '@aws-amplify/backend-auth`);
const backendDataVersion = findEffectiveVersion(releasePlan, '@aws-amplify/backend-data`);
...
if (backendVersion !== maxVersion(backendAuthVersion, backendDataVersion, ...)) { throw}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And. don't worry about optimizing loops. These arrays have ~10-20 items. Ability to understand what code is doing is more important here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer I remove the versionBumpOfWrongKind
array as well? Since with this rework, it won't have anything in it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And.. there's one interesting edge case here.
It might happen that @aws-amplify/backend
will get version bump but all of backend-X
will not. That should be a legit case.
I.e. the condition should be if(effectiveBackendVersionType < effectiveBackendDependenciesVersionType) { throw }
(this is pesudocode).
For that you might either consider either creating some kind of comparator function for minor|major|patch|none
or create enum with numerical values like enum { MAJOR: 3, MINOR: 2... }
..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum sounds like the cleaner option. My original code was able to handle cases where backend
got changes but backend-X
didn't through this: backendMaxVersionType !== release.type && (release.type === 'major' || backendMaxVersionType === 'none' || (backendMaxVersionType === 'patch' && release.type === 'minor'))
but it is a fairly ugly looking set of code that is not intuitive to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
} | ||
} | ||
} | ||
const versionTypeConverter = (version: VersionType): VersionTypeEnum => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const versionTypeConverter = (version: VersionType): VersionTypeEnum => { | |
const convertVersionType = (version: VersionType): VersionTypeEnum => { |
function name should be verb-ish.
maxVersion( | ||
backendAuthVersion, | ||
backendDataVersion, | ||
backendFunctionVersion, | ||
backendStorageVersion | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxVersion( | |
backendAuthVersion, | |
backendDataVersion, | |
backendFunctionVersion, | |
backendStorageVersion | |
) | |
Math.max( | |
backendAuthVersion, | |
backendDataVersion, | |
backendFunctionVersion, | |
backendStorageVersion | |
) |
would this just work?
There was a problem hiding this comment.
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
Problem
@aws-amplify/backend
sometimes does not properly inherit the right kind of version bump from its dependencies.Issue number, if available: #1693
Changes
Corresponding docs PR, if applicable:
Validation
backend
and its dependenciesbackend: none
, dependencies have version bump ofminor
backend: minor
, dependencies arepatch
ornone
backend: patch
, dependencies areminor
orpatch
backend: patch
, no dependency versionsbackend: minor
, one dependency ismajor
Checklist
run-e2e
label set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.