Skip to content

Commit

Permalink
feat: Switch to Timestamp type (#33648)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored Jan 22, 2025
1 parent 2de047e commit a33d3ea
Show file tree
Hide file tree
Showing 87 changed files with 573 additions and 401 deletions.
3 changes: 2 additions & 1 deletion lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { HostRule, SkipReason } from '../types';
import type { StageName } from '../types/skip-reason';
import type { GitNoVerifyOption } from '../util/git/types';
import type { MergeConfidence } from '../util/merge-confidence/types';
import type { Timestamp } from '../util/timestamp';

export type RenovateConfigStage =
| 'global'
Expand Down Expand Up @@ -552,7 +553,7 @@ export interface PackageRuleInputConfig extends Record<string, unknown> {
manager?: string;
datasource?: string;
packageRules?: (PackageRule & PackageRuleInputConfig)[];
releaseTimestamp?: string | null;
releaseTimestamp?: Timestamp | null;
repository?: string;
currentVersionAgeInDays?: number;
currentVersionTimestamp?: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/aws-machine-image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Filter, Image } from '@aws-sdk/client-ec2';
import { DescribeImagesCommand, EC2Client } from '@aws-sdk/client-ec2';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { cache } from '../../../util/cache/package/decorator';
import { asTimestamp } from '../../../util/timestamp';
import * as amazonMachineImageVersioning from '../../versioning/aws-machine-image';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
Expand Down Expand Up @@ -147,7 +148,7 @@ export class AwsMachineImageDatasource extends Datasource {
releases: [
{
version: latestImage.ImageId,
releaseTimestamp: latestImage.CreationDate,
releaseTimestamp: asTimestamp(latestImage.CreationDate),
isDeprecated:
Date.parse(latestImage.DeprecationTime ?? this.now.toString()) <
this.now,
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/bitbucket-tags/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cache } from '../../../util/cache/package/decorator';
import type { PackageCacheNamespace } from '../../../util/cache/package/types';
import { BitbucketHttp } from '../../../util/http/bitbucket';
import { asTimestamp } from '../../../util/timestamp';
import { ensureTrailingSlash } from '../../../util/url';
import { RepoInfo } from '../../platform/bitbucket/schema';
import type { PagedResult } from '../../platform/bitbucket/types';
Expand Down Expand Up @@ -79,7 +80,7 @@ export class BitbucketTagsDatasource extends Datasource {
releases: bitbucketTags.map(({ name, target }) => ({
version: name,
gitRef: name,
releaseTimestamp: target?.date,
releaseTimestamp: asTimestamp(target?.date),
})),
};

Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/bitrise/schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { z } from 'zod';
import { Yaml } from '../../../util/schema-utils';
import { MaybeTimestamp } from '../../../util/timestamp';

export const BitriseStepFile = Yaml.pipe(
z.object({
published_at: z.string(),
published_at: MaybeTimestamp,
source_code_url: z.string().optional(),
}),
);
3 changes: 2 additions & 1 deletion lib/modules/datasource/cpan/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod';
import { LooseArray } from '../../../util/schema-utils';
import { MaybeTimestamp } from '../../../util/timestamp';
import type { CpanRelease } from './types';

/**
Expand All @@ -14,7 +15,7 @@ const MetaCpanApiFileSchema = z
}),
),
distribution: z.string(),
date: z.string(),
date: MaybeTimestamp,
deprecated: z.boolean(),
maturity: z.string(),
status: z.union([
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/crate/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe('modules/datasource/crate/index', () => {

expect(res).toEqual({
version: '4.5.17',
releaseTimestamp: '2024-09-04T19:16:41.355243+00:00',
releaseTimestamp: '2024-09-04T19:16:41.355Z',
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/crate/schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { z } from 'zod';
import { MaybeTimestamp } from '../../../util/timestamp';

export const ReleaseTimestampSchema = z
.object({
version: z.object({
created_at: z.string(),
created_at: MaybeTimestamp,
}),
})
.transform(({ version: { created_at } }) => created_at)
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/custom/schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { z } from 'zod';
import { MaybeTimestamp } from '../../../util/timestamp';

export const ReleaseResultZodSchema = z.object({
releases: z.array(
z
.object({
version: z.string(),
isDeprecated: z.boolean().optional(),
releaseTimestamp: z.string().optional(),
releaseTimestamp: MaybeTimestamp,
sourceUrl: z.string().optional(),
sourceDirectory: z.string().optional(),
changelogUrl: z.string().optional(),
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/dart/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { HttpResponse } from '../../../util/http/types';
import { asTimestamp } from '../../../util/timestamp';
import { ensureTrailingSlash } from '../../../util/url';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
Expand Down Expand Up @@ -49,7 +50,7 @@ export class DartDatasource extends Datasource {
?.filter(({ retracted }) => !retracted)
?.map(({ version, published }) => ({
version,
releaseTimestamp: published,
releaseTimestamp: asTimestamp(published),
}));
if (releases && latest) {
result = { releases };
Expand Down
10 changes: 8 additions & 2 deletions lib/modules/datasource/deno/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from 'zod';
import { getSourceUrl as getGithubSourceUrl } from '../../../util/github/url';
import { LooseArray } from '../../../util/schema-utils';
import { MaybeTimestamp } from '../../../util/timestamp';
import type { Release } from '../types';

export const DenoApiTag = z.object({
Expand Down Expand Up @@ -31,7 +32,7 @@ export const DenoAPIUploadOptions = z.object({
export const DenoAPIModuleVersionResponse = z
.object({
upload_options: DenoAPIUploadOptions,
uploaded_at: z.string(),
uploaded_at: MaybeTimestamp,
version: z.string(),
})
.transform(
Expand All @@ -41,6 +42,11 @@ export const DenoAPIModuleVersionResponse = z
if (type === 'github') {
sourceUrl = getGithubSourceUrl(repository);
}
return { version, gitRef, releaseTimestamp, sourceUrl };
return {
version,
gitRef,
releaseTimestamp,
sourceUrl,
};
},
);
3 changes: 2 additions & 1 deletion lib/modules/datasource/devbox/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { z } from 'zod';
import { MaybeTimestamp } from '../../../util/timestamp';

export const DevboxRelease = z.object({
version: z.string(),
last_updated: z.string(),
last_updated: MaybeTimestamp,
});

export const DevboxResponse = z
Expand Down
8 changes: 3 additions & 5 deletions lib/modules/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { hasKey } from '../../../util/object';
import { regEx } from '../../../util/regex';
import { type AsyncResult, Result } from '../../../util/result';
import { isDockerDigest } from '../../../util/string-match';
import { asTimestamp } from '../../../util/timestamp';
import {
ensurePathPrefix,
joinUrlParts,
Expand Down Expand Up @@ -1001,13 +1002,10 @@ export class DockerDatasource extends Datasource {

const items = cache.getItems();
return items.map(
({
name: version,
tag_last_pushed: releaseTimestamp,
digest: newDigest,
}) => {
({ name: version, tag_last_pushed, digest: newDigest }) => {
const release: Release = { version };

const releaseTimestamp = asTimestamp(tag_last_pushed);
if (releaseTimestamp) {
release.releaseTimestamp = releaseTimestamp;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/dotnet-version/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod';
import { LooseArray } from '../../../util/schema-utils';
import { MaybeTimestamp } from '../../../util/timestamp';
import type { Release } from '../types';

export const ReleasesIndex = z
Expand All @@ -15,7 +16,7 @@ export const ReleasesIndex = z
.transform(({ 'releases-index': releasesIndex }) => releasesIndex);

const ReleaseBase = z.object({
'release-date': z.string(),
'release-date': MaybeTimestamp,
'release-notes': z.string(),
});
const ReleaseDetails = z.object({
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/endoflife-date/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DateTime } from 'luxon';
import { z } from 'zod';
import { UtcDate } from '../../../util/schema-utils';
import { MaybeTimestamp } from '../../../util/timestamp';
import type { Release } from '../types';

const ExpireableField = z.union([
Expand All @@ -15,7 +16,7 @@ export const EndoflifeDateVersions = z
.object({
cycle: z.string(),
latest: z.optional(z.string()),
releaseDate: z.optional(z.string()),
releaseDate: MaybeTimestamp,
eol: z.optional(ExpireableField),
discontinued: z.optional(ExpireableField),
})
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/flutter-version/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { regEx } from '../../../util/regex';
import { asTimestamp } from '../../../util/timestamp';
import { id as semverId } from '../../versioning/semver';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
Expand Down Expand Up @@ -58,7 +59,7 @@ export class FlutterVersionDatasource extends Datasource {
})
.map(({ version, release_date, channel }) => ({
version,
releaseTimestamp: release_date,
releaseTimestamp: asTimestamp(release_date),
isStable: channel === 'stable',
}));
return result.releases.length ? result : null;
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/galaxy-collection/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from 'zod';
import { MaybeTimestamp } from '../../../util/timestamp';

export type GalaxyV3 = z.infer<typeof GalaxyV3>;
export const GalaxyV3 = z.object({
Expand All @@ -14,7 +15,7 @@ export const GalaxyV3Versions = z
data: z.array(
z.object({
version: z.string(),
created_at: z.string().datetime(),
created_at: MaybeTimestamp,
}),
),
})
Expand Down
19 changes: 7 additions & 12 deletions lib/modules/datasource/galaxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,13 @@ export class GalaxyDatasource extends Datasource {
result.sourceUrl = `https://github.com/${user}/${repo}`;
}

result.releases = versions.map(
(version: { name: string; created?: string }) => {
const release: Release = {
version: version.name,
};

if (is.nonEmptyString(version.created)) {
release.releaseTimestamp = version.created;
}
return release;
},
);
result.releases = versions.map(({ version, releaseTimestamp }) => {
const release: Release = { version };
if (releaseTimestamp) {
release.releaseTimestamp = releaseTimestamp;
}
return release;
});

return result;
}
Expand Down
14 changes: 10 additions & 4 deletions lib/modules/datasource/galaxy/schema.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { z } from 'zod';
import { MaybeTimestamp } from '../../../util/timestamp';

export type GalaxyV1 = z.infer<typeof GalaxyV1>;
export const GalaxyV1 = z.object({
results: z.array(
z.object({
summary_fields: z.object({
versions: z.array(
z.object({
name: z.string(),
created: z.string().optional(),
}),
z
.object({
name: z.string(),
created: MaybeTimestamp,
})
.transform(({ name, created }) => ({
version: name,
releaseTimestamp: created,
})),
),
}),
github_user: z.string().optional(),
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/gitea-releases/schema.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { z } from 'zod';
import { MaybeTimestamp } from '../../../util/timestamp';

export const ReleaseSchema = z.object({
name: z.string(),
tag_name: z.string(),
body: z.string(),
prerelease: z.boolean(),
published_at: z.string().datetime({ offset: true }),
published_at: MaybeTimestamp,
});

export const ReleasesSchema = z.array(ReleaseSchema);
3 changes: 2 additions & 1 deletion lib/modules/datasource/gitea-tags/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from 'zod';
import { MaybeTimestamp } from '../../../util/timestamp';

export const CommitSchema = z.object({
sha: z.string(),
Expand All @@ -8,7 +9,7 @@ export const CommitsSchema = z.array(CommitSchema);

const TagCommitSchema = z.object({
sha: z.string(),
created: z.string().datetime({ offset: true }),
created: MaybeTimestamp,
});

export const TagSchema = z.object({
Expand Down
11 changes: 6 additions & 5 deletions lib/modules/datasource/github-release-attachments/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getDigest, getPkgReleases } from '..';
import { mocked } from '../../../../test/util';
import * as githubGraphql from '../../../util/github/graphql';
import * as _hostRules from '../../../util/host-rules';
import type { Timestamp } from '../../../util/timestamp';
import { GitHubReleaseAttachmentMocker } from './test';
import { GithubReleaseAttachmentsDatasource } from '.';

Expand All @@ -28,39 +29,39 @@ describe('modules/datasource/github-release-attachments/index', () => {
name: 'some/dep2',
description: 'some description',
version: 'a',
releaseTimestamp: '2020-03-09T13:00:00Z',
releaseTimestamp: '2020-03-09T13:00:00Z' as Timestamp,
},
{
id: 2,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: 'v',
releaseTimestamp: '2020-03-09T12:00:00Z',
releaseTimestamp: '2020-03-09T12:00:00Z' as Timestamp,
},
{
id: 3,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: '1.0.0',
releaseTimestamp: '2020-03-09T11:00:00Z',
releaseTimestamp: '2020-03-09T11:00:00Z' as Timestamp,
},
{
id: 4,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: 'v1.1.0',
releaseTimestamp: '2020-03-09T10:00:00Z',
releaseTimestamp: '2020-03-09T10:00:00Z' as Timestamp,
},
{
id: 5,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: '2.0.0',
releaseTimestamp: '2020-04-09T10:00:00Z',
releaseTimestamp: '2020-04-09T10:00:00Z' as Timestamp,
isStable: false,
},
]);
Expand Down
Loading

0 comments on commit a33d3ea

Please sign in to comment.