refactor: always set currentVersionTimestamp (#28949)

This commit is contained in:
Rhys Arkins 2024-05-09 15:05:00 +02:00 committed by GitHub
parent a91abaa54e
commit b5ea61b435
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 17 deletions

View file

@ -3155,6 +3155,7 @@ describe('workers/repository/process/lookup/index', () => {
expect(res).toEqual({ expect(res).toEqual({
currentVersion: '1.3.0', currentVersion: '1.3.0',
currentVersionTimestamp: '2015-04-26T16:42:11.311Z',
fixedVersion: '1.3.0', fixedVersion: '1.3.0',
isSingleVersion: true, isSingleVersion: true,
registryUrl: 'https://registry.npmjs.org', registryUrl: 'https://registry.npmjs.org',
@ -3195,6 +3196,7 @@ describe('workers/repository/process/lookup/index', () => {
).unwrapOrThrow(); ).unwrapOrThrow();
expect(res).toEqual({ expect(res).toEqual({
currentVersion: '1.3.0', currentVersion: '1.3.0',
currentVersionTimestamp: '2015-04-26T16:42:11.311Z',
fixedVersion: '1.3.0', fixedVersion: '1.3.0',
isSingleVersion: true, isSingleVersion: true,
registryUrl: 'https://registry.npmjs.org', registryUrl: 'https://registry.npmjs.org',
@ -3247,6 +3249,7 @@ describe('workers/repository/process/lookup/index', () => {
expect(res).toEqual({ expect(res).toEqual({
currentVersion: '1.3.0', currentVersion: '1.3.0',
currentVersionTimestamp: '2015-04-26T16:42:11.311Z',
deprecationMessage: codeBlock` deprecationMessage: codeBlock`
On registry \`https://registry.npmjs.org\`, the "latest" version of dependency \`q3\` has the following deprecation notice: On registry \`https://registry.npmjs.org\`, the "latest" version of dependency \`q3\` has the following deprecation notice:
@ -4039,14 +4042,15 @@ describe('workers/repository/process/lookup/index', () => {
allowedVersions: '< 19.0.0', allowedVersions: '< 19.0.0',
}, },
]; ];
const releaseTimestamp = new Date(
Date.now() - 25 * 60 * 60 * 1000,
).toISOString();
getDockerReleases.mockResolvedValueOnce({ getDockerReleases.mockResolvedValueOnce({
releases: [ releases: [
{ {
version: '17.0.0', version: '17.0.0',
// a day old release // a day old release
releaseTimestamp: new Date( releaseTimestamp,
Date.now() - 25 * 60 * 60 * 1000,
).toISOString(),
}, },
{ {
version: '18.0.0', version: '18.0.0',
@ -4063,6 +4067,7 @@ describe('workers/repository/process/lookup/index', () => {
expect(res).toEqual({ expect(res).toEqual({
currentVersion: '17.0.0', currentVersion: '17.0.0',
currentVersionTimestamp: releaseTimestamp,
fixedVersion: '17.0.0', fixedVersion: '17.0.0',
isSingleVersion: true, isSingleVersion: true,
registryUrl: 'https://index.docker.io', registryUrl: 'https://index.docker.io',
@ -4078,7 +4083,6 @@ describe('workers/repository/process/lookup/index', () => {
], ],
versioning: 'docker', versioning: 'docker',
warnings: [], warnings: [],
currentVersionTimestamp: undefined,
}); });
}); });

View file

@ -36,6 +36,17 @@ import {
isReplacementRulesConfigured, isReplacementRulesConfigured,
} from './utils'; } from './utils';
function getTimestamp(
versions: Release[],
version: string,
versioning: allVersioning.VersioningApi,
): string | null | undefined {
return versions.find(
(v) =>
versioning.isValid(v.version) && versioning.equals(v.version, version),
)?.releaseTimestamp;
}
export async function lookupUpdates( export async function lookupUpdates(
inconfig: LookupUpdateConfig, inconfig: LookupUpdateConfig,
): Promise<Result<UpdateResult, Error>> { ): Promise<Result<UpdateResult, Error>> {
@ -287,21 +298,22 @@ export async function lookupUpdates(
} }
res.currentVersion = currentVersion!; res.currentVersion = currentVersion!;
const currentVersionTimestamp = allVersions.find( const currentVersionTimestamp = getTimestamp(
(v) => allVersions,
versioning.isValid(v.version) && currentVersion,
versioning.equals(v.version, currentVersion), versioning,
)?.releaseTimestamp; );
if ( if (is.nonEmptyString(currentVersionTimestamp)) {
is.nonEmptyString(currentVersionTimestamp) &&
config.packageRules?.some((rules) =>
is.nonEmptyString(rules.matchCurrentAge),
)
) {
res.currentVersionTimestamp = currentVersionTimestamp; res.currentVersionTimestamp = currentVersionTimestamp;
// Reapply package rules to check matches for matchCurrentAge if (
config = applyPackageRules({ ...config, currentVersionTimestamp }); config.packageRules?.some((rules) =>
is.nonEmptyString(rules.matchCurrentAge),
)
) {
// Reapply package rules to check matches for matchCurrentAge
config = applyPackageRules({ ...config, currentVersionTimestamp });
}
} }
if ( if (