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

fix(versioning/poetry): improve poetry prerelease version handling #11733

Merged
merged 24 commits into from Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d020473
Handle prereleases published with Poetry
jvansanten Sep 14, 2021
3e3d041
Update poetry versioning readme
jvansanten Sep 14, 2021
2a4f8b8
Apply formatting suggestions from code review
jvansanten Sep 14, 2021
a210c91
Use one sentence per line in readme
jvansanten Sep 14, 2021
3ff1eb7
Factor out patterns and transformations
jvansanten Sep 14, 2021
af5789b
Merge branch 'main' into poetry-prerelease-support
jvansanten Sep 14, 2021
ad433fa
Apply suggestions from code review
viceice Sep 15, 2021
89a75ff
Use JSDoc comments
jvansanten Sep 15, 2021
f8a69a2
Mollify linters
jvansanten Sep 15, 2021
106cddc
Use only public API in manager/poetry
jvansanten Sep 15, 2021
341b477
Merge branch 'main' into poetry-prerelease-support
rarkins Sep 16, 2021
99b535b
Handle PEP440 ===
jvansanten Sep 16, 2021
00c2b20
Mollify tsc
jvansanten Sep 16, 2021
84aefea
Handle underspecified postreleases
jvansanten Sep 16, 2021
b585c54
v27.10.0-alpha.0
jvansanten Sep 29, 2021
687d574
Prohibit release segments of length > 3
jvansanten Sep 29, 2021
1ff92fb
Revert "v27.10.0-alpha.0"
jvansanten Sep 29, 2021
e8b785f
Merge branch 'main' into poetry-prerelease-support
jvansanten Sep 29, 2021
be9431c
Merge branch 'main' into poetry-prerelease-support
rarkins Sep 30, 2021
8712c42
Merge branch 'main' into poetry-prerelease-support
rarkins Oct 22, 2021
cbbf22f
Fix up test coverage
jvansanten Oct 22, 2021
fb0bee1
Merge branch 'main' into poetry-prerelease-support
jvansanten Oct 22, 2021
1c0f6e2
Validate regexes verbosely
jvansanten Oct 22, 2021
70398fc
Export isValid directly from versioning/poetry
jvansanten Oct 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 74 additions & 13 deletions lib/versioning/poetry/index.spec.ts
Expand Up @@ -7,6 +7,7 @@ describe('versioning/poetry/index', () => {
['1.0', '1'],
['1.0.0', '1'],
['1.9.0', '1.9'],
['1.9b0', '1.9.0-beta.0'],
])('%s == %s', (a, b) => {
expect(versioning.equals(a, b)).toBe(true);
});
Expand All @@ -15,6 +16,7 @@ describe('versioning/poetry/index', () => {
['1', '2'],
['1.9.1', '1.9'],
['1.9-beta', '1.9'],
['1.9b0', '1.9'],
viceice marked this conversation as resolved.
Show resolved Hide resolved
])('%s != %s', (a, b) => {
expect(versioning.equals(a, b)).toBe(false);
});
Expand All @@ -25,6 +27,8 @@ describe('versioning/poetry/index', () => {
['1', 1],
['1.9', 1],
['1.9.0', 1],
['1.9.0b0', 1],
['1.9.0-dev.0', 1],
])('%s -> %i', (version, expected) => {
expect(versioning.getMajor(version)).toEqual(expected);
});
Expand All @@ -35,6 +39,9 @@ describe('versioning/poetry/index', () => {
['1', 0],
['1.9', 9],
['1.9.0', 9],
['1.9.0b0', 9],
['1.9.0-dev.0', 9],
['17.04.01', 4],
])('%s -> %i', (version, expected) => {
expect(versioning.getMinor(version)).toEqual(expected);
});
Expand All @@ -46,6 +53,9 @@ describe('versioning/poetry/index', () => {
['1.9', 0],
['1.9.0', 0],
['1.9.4', 4],
['1.9.4b0', 4],
['1.9.4-dev.0', 4],
['17.04.01', 1],
])('%s -> %i', (version, expected) => {
expect(versioning.getPatch(version)).toEqual(expected);
});
Expand All @@ -58,6 +68,7 @@ describe('versioning/poetry/index', () => {
['2.0.0', '1'],
['1.10.0', '1.9'],
['1.9', '1.9-beta'],
['1.9', '1.9a0'],
])('%s > %s', (a, b) => {
expect(versioning.isGreaterThan(a, b)).toBe(true);
});
Expand All @@ -79,21 +90,30 @@ describe('versioning/poetry/index', () => {
['1.9.0', true],
['1.9.4', true],
['1.9.4-beta', false],
['1.9.4b0', false],
])('%s -> %i', (version, expected) => {
expect(versioning.isStable(version)).toEqual(expected);
});
});

describe('isValid(input)', () => {
it('should return null for irregular versions', () => {
expect(versioning.isValid('17.04.0')).toBeFalsy();
it('should support zero-padded version numbers allowed by PEP440', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(versioning.isValid('17.04.0')).toBeTruthy();
});
it('should return false for irregular version', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(versioning.isValid('17.b4.0')).toBeFalsy();
});
it('should support simple semver', () => {
expect(versioning.isValid('1.2.3')).toBeTruthy();
});
it('should support semver with dash', () => {
expect(versioning.isValid('1.2.3-foo')).toBeTruthy();
});
it('should support PEP440 prereleases', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(versioning.isValid('1.2.3a0')).toBeTruthy();
expect(versioning.isValid('1.2.3b1')).toBeTruthy();
expect(versioning.isValid('1.2.3rc23')).toBeTruthy();
});
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
it('should reject semver without dash', () => {
expect(versioning.isValid('1.2.3foo')).toBeFalsy();
});
Expand Down Expand Up @@ -141,6 +161,10 @@ describe('versioning/poetry/index', () => {
it('handles short', () => {
expect(versioning.matches('1.4', '1.4')).toBe(true);
});
it('handles caret with preleases', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(versioning.matches('0.8.0a1', '^0.8.0-alpha.0')).toBe(true);
expect(versioning.matches('0.7.4', '^0.8.0-alpha.0')).toBe(false);
});
});
describe('isLessThanRange()', () => {
it('handles comma', () => {
Expand Down Expand Up @@ -185,6 +209,14 @@ describe('versioning/poetry/index', () => {
)
).toBeNull();
});
it('handles PyPI preleases', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(
versioning.minSatisfyingVersion(
['0.8.0a2', '0.8.0a7'],
'^0.8.0-alpha.0'
)
).toBe('0.8.0-alpha.2');
});
});
describe('getSatisfyingVersion()', () => {
it('handles comma', () => {
Expand All @@ -201,6 +233,14 @@ describe('versioning/poetry/index', () => {
)
).toBe('5.0.3');
});
it('handles PyPI preleases', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(
versioning.getSatisfyingVersion(
['0.8.0a2', '0.8.0a7'],
'^0.8.0-alpha.0'
)
).toBe('0.8.0-alpha.7');
});
});

describe('getNewValue()', () => {
Expand Down Expand Up @@ -332,7 +372,7 @@ describe('versioning/poetry/index', () => {
})
).toEqual('^2.0.0');
});
it('returns currentValue', () => {
it('returns currentValue for unqualified newVersion', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(
versioning.getNewValue({
currentValue: '^0.5.15',
Expand All @@ -342,6 +382,16 @@ describe('versioning/poetry/index', () => {
})
).toEqual('^0.5.15');
});
it('returns currentValue for invalid newVersion', () => {
jvansanten marked this conversation as resolved.
Show resolved Hide resolved
expect(
versioning.getNewValue({
currentValue: '^0.5.15',
rangeStrategy: 'replace',
currentVersion: '0.5.15',
newVersion: '0.6b.4',
})
).toEqual('^0.5.15');
});
viceice marked this conversation as resolved.
Show resolved Hide resolved
it('bumps naked caret', () => {
expect(
versioning.getNewValue({
Expand Down Expand Up @@ -426,16 +476,25 @@ describe('versioning/poetry/index', () => {
})
).toEqual('=1.1.0');
});
it('bumps caret to prerelease', () => {
expect(
versioning.getNewValue({
currentValue: '^1',
rangeStrategy: 'bump',
currentVersion: '1.0.0',
newVersion: '1.0.7-prerelease.1',
})
).toEqual('^1.0.7-prerelease.1');
});
it.each([
viceice marked this conversation as resolved.
Show resolved Hide resolved
['^1', '1.0.0', '1.0.7-rc.1', '^1.0.7-rc.1'],
['^1', '1.0.0', '1.0.7-alpha.0', '^1.0.7-alpha.0'],
['^0.8.0-alpha.0', '0.8.0-alpha.0', '0.8.0-alpha.1', '^0.8.0-alpha.1'],
['^0.8.0-alpha.0', '0.8.0-alpha.0', '0.8.0a1', '^0.8.0-alpha.1'],
['^1', '1.0.0', '1.0.7a0', '^1.0.7-alpha.0'],
])(
'bumps caret to prerelease',
(currentValue, currentVersion, newVersion, result) => {
expect(
versioning.getNewValue({
currentValue: currentValue,
rangeStrategy: 'bump',
currentVersion: currentVersion,
newVersion: newVersion,
})
).toEqual(result);
}
);
it('replaces with newer', () => {
viceice marked this conversation as resolved.
Show resolved Hide resolved
expect(
versioning.getNewValue({
Expand Down Expand Up @@ -593,6 +652,8 @@ describe('versioning/poetry/index', () => {
['2.0.0', '1'],
['1.10.0', '1.9'],
['1.9', '1.9-beta'],
['1.9', '1.9b'],
['1.9', '1.9rc0'],
])('%s > %s', (a, b) => {
expect(versioning.sortVersions(a, b)).toBe(1);
});
Expand Down