Skip to content

Commit

Permalink
Merge branch 'main' into gradle/test-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Churro authored Jan 11, 2025
2 parents 103fcd1 + e1aa9b7 commit 16e50e0
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ concurrency:
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
NODE_VERSION: 22
PDM_VERSION: 2.22.1 # renovate: datasource=pypi depName=pdm
PDM_VERSION: 2.22.2 # renovate: datasource=pypi depName=pdm
DRY_RUN: true
TEST_LEGACY_DECRYPTION: true
SPARSE_CHECKOUT: |-
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
uses: github/codeql-action/init@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
with:
languages: javascript

Expand All @@ -51,7 +51,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
uses: github/codeql-action/autobuild@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -65,4 +65,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
uses: github/codeql-action/analyze@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: 'Upload to code-scanning'
uses: github/codeql-action/upload-sarif@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
uses: github/codeql-action/upload-sarif@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
format: 'sarif'
output: 'trivy-results.sarif'

- uses: github/codeql-action/upload-sarif@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
- uses: github/codeql-action/upload-sarif@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
with:
sarif_file: trivy-results.sarif
category: 'docker-image-${{ matrix.tag }}'
2 changes: 1 addition & 1 deletion lib/modules/datasource/azure-pipelines-tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class AzurePipelinesTasksDatasource extends Datasource {
key: (url: string) => url,
ttlMinutes: 24 * 60,
})
async getTasks<ResT, Schema extends ZodType<ResT> = ZodType<ResT>>(
async getTasks<Schema extends ZodType>(
url: string,
opts: HttpOptions,
schema: Schema,
Expand Down
5 changes: 1 addition & 4 deletions lib/modules/datasource/bitrise/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { parseGitUrl } from '../../../util/git/url';
import { GithubHttp } from '../../../util/http/github';
import { fromBase64 } from '../../../util/string';
import { joinUrlParts } from '../../../util/url';
import { parseSingleYaml } from '../../../util/yaml';
import { GithubContentResponse } from '../../platform/github/schema';
import semver from '../../versioning/semver';
import { Datasource } from '../datasource';
Expand Down Expand Up @@ -111,9 +110,7 @@ export class BitriseDatasource extends Datasource {
}

const content = fromBase64(body.content);
const { published_at, source_code_url } = parseSingleYaml(content, {
customSchema: BitriseStepFile,
});
const { published_at, source_code_url } = BitriseStepFile.parse(content);

result.releases.push({
version: versionDir.name,
Expand Down
11 changes: 7 additions & 4 deletions lib/modules/datasource/bitrise/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { z } from 'zod';
import { Yaml } from '../../../util/schema-utils';

export const BitriseStepFile = z.object({
published_at: z.string(),
source_code_url: z.string().optional(),
});
export const BitriseStepFile = Yaml.pipe(
z.object({
published_at: z.string(),
source_code_url: z.string().optional(),
}),
);
2 changes: 1 addition & 1 deletion lib/modules/datasource/conan/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const defaultRegistryUrl = 'https://center2.conan.io/';
export const datasource = 'conan';

export const conanDatasourceRegex = regEx(
/(?<name>[a-zA-Z\-_0-9]+)\/(?<version>[^@/\n]+)(?<userChannel>@\S+\/\S+)/gim,
/^(?<name>[a-zA-Z\-_0-9]+)\/(?<version>[^@/\n]+)(?<userChannel>@\S+\/\S+)$/im,
);

export function getConanPackage(packageName: string): ConanPackage {
Expand Down
1 change: 1 addition & 0 deletions lib/modules/datasource/conan/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ describe('modules/datasource/conan/index', () => {
version: '1.1.1',
},
],
sourceUrl: 'https://fake.conan.url.com',
});
});

Expand Down
77 changes: 27 additions & 50 deletions lib/modules/datasource/conan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { logger } from '../../../logger';
import { cache } from '../../../util/cache/package/decorator';
import { GithubHttp } from '../../../util/http/github';
import { ensureTrailingSlash, joinUrlParts } from '../../../util/url';
import { parseSingleYaml } from '../../../util/yaml';
import * as allVersioning from '../../versioning';
import { Datasource } from '../datasource';
import type {
Expand All @@ -13,19 +12,14 @@ import type {
ReleaseResult,
} from '../types';
import { isArtifactoryServer } from '../util';
import { datasource, defaultRegistryUrl, getConanPackage } from './common';
import {
conanDatasourceRegex,
datasource,
defaultRegistryUrl,
getConanPackage,
} from './common';
import type {
ConanCenterReleases,
ConanJSON,
ConanLatestRevision,
ConanProperties,
ConanRevisionJSON,
ConanRevisionsJSON,
ConanYAML,
} from './types';
} from './schema';

export class ConanDatasource extends Datasource {
static readonly id = datasource;
Expand Down Expand Up @@ -62,13 +56,7 @@ export class ConanDatasource extends Datasource {
const res = await this.githubHttp.get(url, {
headers: { accept: 'application/vnd.github.v3.raw' },
});
// TODO: use schema (#9610)
const doc = parseSingleYaml<ConanYAML>(res.body);
return {
releases: Object.keys(doc?.versions ?? {}).map((version) => ({
version,
})),
};
return ConanCenterReleases.parse(res.body);
}

@cache({
Expand All @@ -94,10 +82,11 @@ export class ConanDatasource extends Datasource {
conanPackage.userAndChannel,
'/revisions',
);
const revisionRep =
await this.http.getJson<ConanRevisionsJSON>(revisionLookUp);
const revisions = revisionRep?.body.revisions;
return revisions?.[0].revision ?? null;
const { body: digest } = await this.http.getJson(
revisionLookUp,
ConanLatestRevision,
);
return digest;
}

@cache({
Expand Down Expand Up @@ -135,25 +124,16 @@ export class ConanDatasource extends Datasource {
);

try {
const rep = await this.http.getJson<ConanJSON>(lookupUrl);
const versions = rep?.body;
if (versions) {
const rep = await this.http.getJson(lookupUrl);
const conanJson = ConanJSON.parse(rep.body);
if (conanJson) {
logger.trace({ lookupUrl }, 'Got conan api result');
const dep: ReleaseResult = { releases: [] };

for (const resultString of Object.values(versions.results ?? {})) {
conanDatasourceRegex.lastIndex = 0;
const fromMatch = conanDatasourceRegex.exec(resultString);
if (fromMatch?.groups?.version && fromMatch?.groups?.userChannel) {
const version = fromMatch.groups.version;
if (fromMatch.groups.userChannel === userAndChannel) {
const result: Release = {
version,
};
dep.releases.push(result);
}
}
}
const conanJsonReleases: Release[] = conanJson
.filter(({ userChannel }) => userChannel === userAndChannel)
.map(({ version }) => ({ version }));
dep.releases.push(...conanJsonReleases);

try {
if (isArtifactoryServer(rep)) {
Expand Down Expand Up @@ -182,25 +162,22 @@ export class ConanDatasource extends Datasource {
url,
`v2/conans/${conanPackage.conanName}/${latestVersion}/${conanPackage.userAndChannel}/latest`,
);
const revResp =
await this.http.getJson<ConanRevisionJSON>(latestRevisionUrl);
const packageRev = revResp.body.revision;
const {
body: { revision: packageRev },
} = await this.http.getJson(latestRevisionUrl, ConanRevisionJSON);

const [user, channel] = conanPackage.userAndChannel.split('/');
const packageUrl = joinUrlParts(
`${groups.host}/artifactory/api/storage/${groups.repo}`,
`${user}/${conanPackage.conanName}/${latestVersion}/${channel}/${packageRev}/export/conanfile.py?properties=conan.package.url`,
);
const packageUrlResp =
await this.http.getJson<ConanProperties>(packageUrl);

if (
packageUrlResp.body.properties &&
'conan.package.url' in packageUrlResp.body.properties
) {
const conanPackageUrl =
packageUrlResp.body.properties['conan.package.url'][0];
dep.sourceUrl = conanPackageUrl;
const { body: conanProperties } = await this.http.getJson(
packageUrl,
ConanProperties,
);
const { sourceUrl } = conanProperties;
if (sourceUrl) {
dep.sourceUrl = sourceUrl;
}
}
} catch (err) {
Expand Down
66 changes: 66 additions & 0 deletions lib/modules/datasource/conan/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { z } from 'zod';
import { LooseArray, Yaml } from '../../../util/schema-utils';
import type { ReleaseResult } from '../types';
import { conanDatasourceRegex } from './common';

export const ConanCenterReleases = Yaml.pipe(
z.object({
versions: z.record(z.string(), z.unknown()),
}),
)
.transform(
({ versions }): ReleaseResult => ({
releases: Object.keys(versions).map((version) => ({ version })),
}),
)
.nullable()
.catch(null);

export const ConanJSON = z
.object({
results: z
.string()
.array()
.transform((array) =>
array.map((val) => val.match(conanDatasourceRegex)?.groups),
)
.pipe(
LooseArray(
z.object({
name: z.string(),
version: z.string(),
userChannel: z.string(),
}),
),
),
})
.transform(({ results }) => results)
.nullable()
.catch(null);

export const ConanRevisionJSON = z.object({
revision: z.string(),
time: z.string(),
});

export const ConanLatestRevision = z
.object({ revisions: z.unknown().array() })
.transform(({ revisions }) => revisions[0])
.pipe(ConanRevisionJSON)
.transform(({ revision }) => revision)
.nullable()
.catch(null);

export const ConanProperties = z
.object({
properties: z.object({
'conan.package.url': z.union([
z.string().transform((url) => [url]),
z.string().array(),
]),
}),
})
.transform(({ properties }) => {
const sourceUrl = properties['conan.package.url'][0];
return { sourceUrl };
});
31 changes: 0 additions & 31 deletions lib/modules/datasource/conan/types.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
export interface ConanJSON {
results?: Record<string, string>;
}

export interface ConanRevisionJSON {
revision: string;
time: string;
}

export interface ConanRevisionsJSON {
revisions?: Record<string, ConanRevisionJSON>;
}

export interface ConanYAML {
versions?: Record<string, unknown>;
}

export interface ConanPackage {
conanName: string;
userAndChannel: string;
}

export interface ConanRecipeProperties {
'conan.package.channel': string[];
'conan.package.license': string[];
'conan.package.name': string[];
'conan.package.url': string[];
'conan.package.user': string[];
'conan.package.version': string[];
}

export interface ConanProperties {
properties: ConanRecipeProperties;
uri: string;
}
29 changes: 14 additions & 15 deletions lib/modules/manager/gradle/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
PackageVariables,
ParseGradleResult,
} from './types';
import { isDependencyString, parseDependencyString } from './utils';
import { parseDependencyString } from './utils';

const groovy = lang.createLang('groovy');
const ctx: Ctx = {
Expand Down Expand Up @@ -127,28 +127,27 @@ export function parseProps(
): { vars: PackageVariables; deps: PackageDependency<GradleManagerData>[] } {
let offset = 0;
const vars: PackageVariables = {};
const deps: PackageDependency[] = [];
const deps: PackageDependency<GradleManagerData>[] = [];

for (const line of input.split(newlineRegex)) {
const lineMatch = propRegex.exec(line);
if (lineMatch?.groups) {
const { key, value, leftPart } = lineMatch.groups;
if (isDependencyString(value)) {
const dep = parseDependencyString(value);
if (dep) {
deps.push({
...dep,
managerData: {
fileReplacePosition:
offset + leftPart.length + dep.depName!.length + 1,
packageFile,
},
});
}
const replacePosition = offset + leftPart.length;
const dep = parseDependencyString(value);
if (dep) {
deps.push({
...dep,
managerData: {
fileReplacePosition: replacePosition + dep.depName!.length + 1,
packageFile,
},
});
} else {
vars[key] = {
key,
value,
fileReplacePosition: offset + leftPart.length,
fileReplacePosition: replacePosition,
packageFile,
};
}
Expand Down
Loading

0 comments on commit 16e50e0

Please sign in to comment.