renovate 44.85.0 → 44.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/error-messages.d.ts +3 -2
- package/dist/constants/error-messages.js +3 -1
- package/dist/constants/error-messages.js.map +1 -1
- package/dist/modules/manager/apm/artifacts.js +2 -1
- package/dist/modules/manager/apm/artifacts.js.map +1 -1
- package/dist/modules/manager/bazel-module/artifacts.js +2 -1
- package/dist/modules/manager/bazel-module/artifacts.js.map +1 -1
- package/dist/modules/manager/bazelisk/artifacts.js +2 -1
- package/dist/modules/manager/bazelisk/artifacts.js.map +1 -1
- package/dist/modules/manager/bun/artifacts.js +2 -1
- package/dist/modules/manager/bun/artifacts.js.map +1 -1
- package/dist/modules/manager/bundler/artifacts.js +1 -1
- package/dist/modules/manager/bundler/artifacts.js.map +1 -1
- package/dist/modules/manager/bundler/common.js +11 -16
- package/dist/modules/manager/bundler/common.js.map +1 -1
- package/dist/modules/manager/cargo/artifacts.js +5 -3
- package/dist/modules/manager/cargo/artifacts.js.map +1 -1
- package/dist/modules/manager/composer/artifacts.js +6 -7
- package/dist/modules/manager/composer/artifacts.js.map +1 -1
- package/dist/modules/manager/composer/utils.js +1 -10
- package/dist/modules/manager/composer/utils.js.map +1 -1
- package/dist/modules/manager/conan/artifacts.js +2 -1
- package/dist/modules/manager/conan/artifacts.js.map +1 -1
- package/dist/modules/manager/copier/artifacts.js +3 -3
- package/dist/modules/manager/copier/artifacts.js.map +1 -1
- package/dist/modules/manager/deno/artifacts.js +2 -1
- package/dist/modules/manager/deno/artifacts.js.map +1 -1
- package/dist/modules/manager/devbox/artifacts.js +8 -5
- package/dist/modules/manager/devbox/artifacts.js.map +1 -1
- package/dist/modules/manager/fingerprint.generated.js +34 -34
- package/dist/modules/manager/fingerprint.generated.js.map +1 -1
- package/dist/modules/manager/github-actions/artifacts.js +6 -4
- package/dist/modules/manager/github-actions/artifacts.js.map +1 -1
- package/dist/modules/manager/gleam/artifacts.js +2 -1
- package/dist/modules/manager/gleam/artifacts.js.map +1 -1
- package/dist/modules/manager/gomod/artifacts.js +8 -6
- package/dist/modules/manager/gomod/artifacts.js.map +1 -1
- package/dist/modules/manager/gradle/artifacts.js +2 -1
- package/dist/modules/manager/gradle/artifacts.js.map +1 -1
- package/dist/modules/manager/gradle-wrapper/artifacts.js +2 -1
- package/dist/modules/manager/gradle-wrapper/artifacts.js.map +1 -1
- package/dist/modules/manager/helmfile/artifacts.js +4 -3
- package/dist/modules/manager/helmfile/artifacts.js.map +1 -1
- package/dist/modules/manager/helmv3/artifacts.js +2 -1
- package/dist/modules/manager/helmv3/artifacts.js.map +1 -1
- package/dist/modules/manager/jsonnet-bundler/artifacts.js +2 -1
- package/dist/modules/manager/jsonnet-bundler/artifacts.js.map +1 -1
- package/dist/modules/manager/kustomize/artifacts.js +4 -2
- package/dist/modules/manager/kustomize/artifacts.js.map +1 -1
- package/dist/modules/manager/kustomize/common.js +2 -2
- package/dist/modules/manager/kustomize/common.js.map +1 -1
- package/dist/modules/manager/maven-wrapper/artifacts.js +2 -1
- package/dist/modules/manager/maven-wrapper/artifacts.js.map +1 -1
- package/dist/modules/manager/mise/artifacts.js +13 -11
- package/dist/modules/manager/mise/artifacts.js.map +1 -1
- package/dist/modules/manager/mix/artifacts.js +3 -2
- package/dist/modules/manager/mix/artifacts.js.map +1 -1
- package/dist/modules/manager/nix/artifacts.js +2 -1
- package/dist/modules/manager/nix/artifacts.js.map +1 -1
- package/dist/modules/manager/npm/artifacts.js +2 -1
- package/dist/modules/manager/npm/artifacts.js.map +1 -1
- package/dist/modules/manager/npm/post-update/node-version.js +2 -1
- package/dist/modules/manager/npm/post-update/node-version.js.map +1 -1
- package/dist/modules/manager/npm/post-update/npm.js +2 -1
- package/dist/modules/manager/npm/post-update/npm.js.map +1 -1
- package/dist/modules/manager/npm/post-update/pnpm.js +2 -1
- package/dist/modules/manager/npm/post-update/pnpm.js.map +1 -1
- package/dist/modules/manager/npm/post-update/yarn.js +5 -3
- package/dist/modules/manager/npm/post-update/yarn.js.map +1 -1
- package/dist/modules/manager/nuget/artifacts.js +2 -1
- package/dist/modules/manager/nuget/artifacts.js.map +1 -1
- package/dist/modules/manager/pep621/processors/pdm.js +3 -2
- package/dist/modules/manager/pep621/processors/pdm.js.map +1 -1
- package/dist/modules/manager/pep621/processors/pixi.js +4 -3
- package/dist/modules/manager/pep621/processors/pixi.js.map +1 -1
- package/dist/modules/manager/pep621/processors/uv.js +3 -3
- package/dist/modules/manager/pep621/processors/uv.js.map +1 -1
- package/dist/modules/manager/pip-compile/common.js +14 -36
- package/dist/modules/manager/pip-compile/common.js.map +1 -1
- package/dist/modules/manager/pip_requirements/artifacts.js +3 -2
- package/dist/modules/manager/pip_requirements/artifacts.js.map +1 -1
- package/dist/modules/manager/pipenv/artifacts.js +3 -2
- package/dist/modules/manager/pipenv/artifacts.js.map +1 -1
- package/dist/modules/manager/pixi/artifacts.js +2 -1
- package/dist/modules/manager/pixi/artifacts.js.map +1 -1
- package/dist/modules/manager/poetry/artifacts.js +3 -2
- package/dist/modules/manager/poetry/artifacts.js.map +1 -1
- package/dist/modules/manager/pub/artifacts.js +11 -10
- package/dist/modules/manager/pub/artifacts.js.map +1 -1
- package/dist/modules/manager/types.d.ts +23 -3
- package/dist/modules/manager/util.js +28 -1
- package/dist/modules/manager/util.js.map +1 -1
- package/dist/modules/manager/vendir/artifacts.js +3 -2
- package/dist/modules/manager/vendir/artifacts.js.map +1 -1
- package/dist/modules/platform/gitlab/index.js +11 -3
- package/dist/modules/platform/gitlab/index.js.map +1 -1
- package/dist/workers/repository/error.js +5 -0
- package/dist/workers/repository/error.js.map +1 -1
- package/dist/workers/repository/process/lookup/index.js +2 -2
- package/dist/workers/repository/process/lookup/index.js.map +1 -1
- package/dist/workers/repository/updates/generate.js +11 -4
- package/dist/workers/repository/updates/generate.js.map +1 -1
- package/package.json +1 -1
- package/renovate-schema.json +2 -2
- package/dist/modules/manager/copier/utils.js +0 -24
- package/dist/modules/manager/copier/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":["hostRules.find"],"sources":["../../../../lib/modules/manager/github-actions/artifacts.ts"],"sourcesContent":["import { quote } from 'shlex';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { findGithubToken } from '../../../util/check-token.ts';\nimport { detectPlatform } from '../../../util/common.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions, ExtraEnv } from '../../../util/exec/types.ts';\nimport { readLocalFile, writeLocalFile } from '../../../util/fs/index.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport type { FileChange } from '../../../util/git/types.ts';\nimport * as hostRules from '../../../util/host-rules.ts';\nimport { parseUrl } from '../../../util/url.ts';\nimport type { PackageFile, PostUpdateConfig } from '../types.ts';\nimport { artifactErrorMessageFromExecError } from '../util.ts';\nimport { actionsLockFile, isLockfileManaged } from './common.ts';\nimport { ActionsLockfile } from './schema.ts';\nimport type { ActionsLockfileResult, OnboardedWorkflows } from './types.ts';\n\n/** The `gh` CLI extension that generates and verifies the lockfile. */\nconst extensionName = 'github/gh-actions-lock';\n\n/** The `uses:` dep types the lockfile graph is built from. */\nconst lockedDepTypes = ['action', 'workflow', 'docker'];\n\nfunction findToken(url: string): string | undefined {\n return findGithubToken(hostRules.find({ hostType: 'github', url }));\n}\n\n/**\n * `gh` takes the token from a different variable for GitHub Enterprise Server, and has to be told which host to talk to.\n *\n * Public actions are still resolved against github.com from there, so pass a token for both hosts.\n */\nfunction getTokenEnv(): ExtraEnv {\n const githubComEndpoint = 'https://api.github.com/';\n const configuredEndpoint = GlobalConfig.get('endpoint');\n // The configured endpoint only says where GitHub lives when Renovate is talking to GitHub: workflows mirrored onto another platform still resolve their actions against github.com.\n const endpoint =\n configuredEndpoint && detectPlatform(configuredEndpoint) === 'github'\n ? configuredEndpoint\n : githubComEndpoint;\n\n const hostname = parseUrl(endpoint)?.hostname;\n const isEnterprise =\n !!hostname && hostname !== 'api.github.com' && hostname !== 'github.com';\n\n const env: ExtraEnv = {};\n\n if (isEnterprise) {\n const enterpriseToken = findToken(endpoint);\n if (enterpriseToken) {\n env.GH_HOST = hostname;\n env.GH_ENTERPRISE_TOKEN = enterpriseToken;\n }\n }\n\n const token = findToken(githubComEndpoint);\n if (token) {\n env.GH_TOKEN = token;\n }\n\n if (!Object.keys(env).length) {\n logger.debug('No GitHub token found for `gh actions-lock`');\n }\n\n return env;\n}\n\n/**\n * Whether any updated dependency is one the lockfile records an edge for, and sits in a file `gh actions-lock` will look at.\n */\nfunction hasLockedUpdate(\n config: PostUpdateConfig,\n onboardedWorkflows: OnboardedWorkflows,\n): boolean {\n return config.upgrades.some((upgrade) => {\n if (upgrade.manager !== 'github-actions') {\n return false;\n }\n\n if (!upgrade.depType || !lockedDepTypes.includes(upgrade.depType)) {\n return false;\n }\n\n const packageFile = upgrade.packageFile;\n if (!packageFile) {\n return false;\n }\n\n return isLockfileManaged(packageFile, onboardedWorkflows);\n });\n}\n\n/**\n * Regenerate `.github/workflows/actions.lock` once per branch.\n *\n * The lockfile records a transitive graph - resolved commits, numeric owner and repository IDs, and each composite action's own `uses:` edges - so it is regenerated by its own tool rather than patched here.\n * `gh actions-lock` re-reads every workflow from disk and rewrites the whole file, so this runs after all of the branch's package file updates have been flushed, in the same shape as npm's `getAdditionalFiles`.\n */\nexport async function updateActionsLockfile(\n config: PostUpdateConfig,\n packageFiles: Record<string, PackageFile[]> | undefined,\n): Promise<ActionsLockfileResult> {\n const empty: ActionsLockfileResult = {\n updatedArtifacts: [],\n artifactErrors: [],\n };\n\n const ghaPackageFiles = packageFiles?.['github-actions'];\n if (!ghaPackageFiles?.length) {\n return empty;\n }\n\n if (config.skipArtifactsUpdate) {\n logger.debug(`Skipping ${actionsLockFile} generation`);\n return empty;\n }\n\n const existingLockFileContent = await readLocalFile(actionsLockFile, 'utf8');\n if (!existingLockFileContent) {\n logger.debug(`No ${actionsLockFile} found`);\n return empty;\n }\n\n const parsedLockfile = ActionsLockfile.safeParse(existingLockFileContent);\n if (!parsedLockfile.success) {\n logger.warn(\n { err: parsedLockfile.error, lockFile: actionsLockFile },\n 'Failed to parse the GitHub Actions lockfile, so not regenerating it',\n );\n return empty;\n }\n\n if (!hasLockedUpdate(config, parsedLockfile.data.workflows)) {\n logger.debug(`No locked dependencies updated for ${actionsLockFile}`);\n return empty;\n }\n\n logger.debug(`Regenerating ${actionsLockFile}`);\n\n const ghaPackageFilePaths = new Set(\n ghaPackageFiles.map((file) => file.packageFile),\n );\n\n // Ensure that in-memory file contents are flushed to disk, so `actions-lock` can run against it.\n // A branch can group updates from other managers, whose contents may be binary - a Gradle wrapper JAR, say - so only write the workflows which the tool actually reads.\n const writtenContent = new Map<string, string>();\n for (const file of coerceArray(config.updatedPackageFiles)) {\n if (file.type === 'addition' && ghaPackageFilePaths.has(file.path)) {\n const contents = file.contents!.toString();\n await writeLocalFile(file.path, contents);\n writtenContent.set(file.path, contents);\n }\n }\n\n const tokenEnv = getTokenEnv();\n\n const execOptions: ExecOptions = {\n // The tool rescans every workflow, so it runs from the repository root\n cwd: GlobalConfig.get('localDir'),\n // `extraEnv` is what forwards a variable into the Docker sidecar, but on its own it is only a default: `getChildEnv` lets a same-named variable in Renovate's own environment win.\n // The token we resolved from the host rules must not be shadowed by an ambient `GH_TOKEN`, so force it as well.\n extraEnv: tokenEnv,\n env: tokenEnv,\n toolConstraints: [{ toolName: 'gh', constraint: config.constraints?.gh }],\n docker: {},\n };\n\n // `--no-interactive`: we have no terminal to answer prompts with\n // `--no-narrow`: keep the ref that we wrote, to avoid a `@v4` being rewritten as `@v4.2.1`\n // `--no-migrate-local-actions`: on-by-default, but unrelated to our lockfile updates\n const commands = [\n 'gh actions-lock --no-interactive --no-narrow --no-migrate-local-actions',\n ];\n\n // `binarySource=global` means the administrator provisions tooling, so we must not reach into their `gh` install to add or re-pin an extension.\n // They own the extension version, and `constraints.ghActionsLock` does not apply.\n // TODO replace once containerbase/base#7279 is available\n if (GlobalConfig.get('binarySource') === 'global') {\n // Debug rather than warn: `constraints.ghActionsLock` ships with a default, so we cannot tell an explicit override from the default here, and warning would fire for every repository on this `binarySource`.\n logger.once.debug(\n { constraint: config.constraints?.ghActionsLock },\n 'Not installing the `gh-actions-lock` extension, and ignoring `constraints.ghActionsLock`, because `binarySource=global` leaves tooling to the administrator',\n );\n } else {\n // `--force` makes an install a no-op when the specified version is already installed\n if (config.constraints?.ghActionsLock) {\n commands.unshift(\n `gh extension install ${extensionName} --force --pin ${quote(config.constraints?.ghActionsLock)}`,\n );\n } else {\n commands.unshift(`gh extension install ${extensionName} --force`);\n }\n }\n\n try {\n await exec(commands, execOptions);\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, `Error updating ${actionsLockFile}`);\n return {\n updatedArtifacts: [],\n artifactErrors: [\n {\n fileName: actionsLockFile,\n // an `ExecError` always carries a `stderr`, so fall back to the message rather than rendering an artifact error with nothing in it\n stderr: artifactErrorMessageFromExecError(err, err.message),\n },\n ],\n };\n }\n\n const updatedArtifacts: FileChange[] = [];\n\n const newLockFileContent = await readLocalFile(actionsLockFile, 'utf8');\n if (newLockFileContent && newLockFileContent !== existingLockFileContent) {\n updatedArtifacts.push({\n type: 'addition',\n path: actionsLockFile,\n contents: newLockFileContent,\n });\n }\n\n // `actions-lock` may annotate workflows being managed with i.e. `# This workflow is managed by gh actions-lock.`, even if there were no updates to that workflow in this branch.\n // We should diff against Git, rather than against the branch's own updated package files, otherwise those annotations are left behind as uncommitted changes\n const status = await getRepoStatus();\n for (const path of status.modified) {\n // ignore the lockfile, as we've already committed it above, and any file which another manager owns\n if (path === actionsLockFile || !ghaPackageFilePaths.has(path)) {\n continue;\n }\n\n const newContent = await readLocalFile(path, 'utf8');\n // Whatever this branch wrote is committed as a package file update already, so only content which the tool changed on top of it is an artifact\n if (!newContent || newContent === writtenContent.get(path)) {\n continue;\n }\n logger.debug(`\\`gh actions-lock\\` annotated ${path}`);\n updatedArtifacts.push({\n type: 'addition',\n path,\n contents: newContent,\n });\n }\n\n if (!updatedArtifacts.length) {\n logger.debug(`${actionsLockFile} is unchanged`);\n }\n\n return { updatedArtifacts, artifactErrors: [] };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,MAAM,gBAAgB;;AAGtB,MAAM,iBAAiB;CAAC;CAAU;CAAY;AAAQ;AAEtD,SAAS,UAAU,KAAiC;CAClD,OAAO,gBAAgBA,KAAe;EAAE,UAAU;EAAU;CAAI,CAAC,CAAC;AACpE;;;;;;AAOA,SAAS,cAAwB;CAC/B,MAAM,oBAAoB;CAC1B,MAAM,qBAAqB,aAAa,IAAI,UAAU;CAEtD,MAAM,WACJ,sBAAsB,eAAe,kBAAkB,MAAM,WACzD,qBACA;CAEN,MAAM,WAAW,SAAS,QAAQ,CAAC,EAAE;CACrC,MAAM,eACJ,CAAC,CAAC,YAAY,aAAa,oBAAoB,aAAa;CAE9D,MAAM,MAAgB,CAAC;CAEvB,IAAI,cAAc;EAChB,MAAM,kBAAkB,UAAU,QAAQ;EAC1C,IAAI,iBAAiB;GACnB,IAAI,UAAU;GACd,IAAI,sBAAsB;EAC5B;CACF;CAEA,MAAM,QAAQ,UAAU,iBAAiB;CACzC,IAAI,OACF,IAAI,WAAW;CAGjB,IAAI,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,QACpB,OAAO,MAAM,6CAA6C;CAG5D,OAAO;AACT;;;;AAKA,SAAS,gBACP,QACA,oBACS;CACT,OAAO,OAAO,SAAS,MAAM,YAAY;EACvC,IAAI,QAAQ,YAAY,kBACtB,OAAO;EAGT,IAAI,CAAC,QAAQ,WAAW,CAAC,eAAe,SAAS,QAAQ,OAAO,GAC9D,OAAO;EAGT,MAAM,cAAc,QAAQ;EAC5B,IAAI,CAAC,aACH,OAAO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":["../../../../lib/modules/manager/github-actions/artifacts.ts"],"sourcesContent":["import { quote } from 'shlex';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { findGithubToken } from '../../../util/check-token.ts';\nimport { detectPlatform } from '../../../util/common.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions, ExtraEnv } from '../../../util/exec/types.ts';\nimport { readLocalFile, writeLocalFile } from '../../../util/fs/index.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport type { FileChange } from '../../../util/git/types.ts';\nimport * as hostRules from '../../../util/host-rules.ts';\nimport { parseUrl } from '../../../util/url.ts';\nimport type { PackageFile, PostUpdateConfig } from '../types.ts';\nimport {\n artifactErrorMessageFromExecError,\n resolveToolConstraint,\n} from '../util.ts';\nimport { actionsLockFile, isLockfileManaged } from './common.ts';\nimport { ActionsLockfile } from './schema.ts';\nimport type { ActionsLockfileResult, OnboardedWorkflows } from './types.ts';\n\n/** The `gh` CLI extension that generates and verifies the lockfile. */\nconst extensionName = 'github/gh-actions-lock';\n\n/** The `uses:` dep types the lockfile graph is built from. */\nconst lockedDepTypes = ['action', 'workflow', 'docker'];\n\nfunction findToken(url: string): string | undefined {\n return findGithubToken(hostRules.find({ hostType: 'github', url }));\n}\n\n/**\n * `gh` takes the token from a different variable for GitHub Enterprise Server, and has to be told which host to talk to.\n *\n * Public actions are still resolved against github.com from there, so pass a token for both hosts.\n */\nfunction getTokenEnv(): ExtraEnv {\n const githubComEndpoint = 'https://api.github.com/';\n const configuredEndpoint = GlobalConfig.get('endpoint');\n // The configured endpoint only says where GitHub lives when Renovate is talking to GitHub: workflows mirrored onto another platform still resolve their actions against github.com.\n const endpoint =\n configuredEndpoint && detectPlatform(configuredEndpoint) === 'github'\n ? configuredEndpoint\n : githubComEndpoint;\n\n const hostname = parseUrl(endpoint)?.hostname;\n const isEnterprise =\n !!hostname && hostname !== 'api.github.com' && hostname !== 'github.com';\n\n const env: ExtraEnv = {};\n\n if (isEnterprise) {\n const enterpriseToken = findToken(endpoint);\n if (enterpriseToken) {\n env.GH_HOST = hostname;\n env.GH_ENTERPRISE_TOKEN = enterpriseToken;\n }\n }\n\n const token = findToken(githubComEndpoint);\n if (token) {\n env.GH_TOKEN = token;\n }\n\n if (!Object.keys(env).length) {\n logger.debug('No GitHub token found for `gh actions-lock`');\n }\n\n return env;\n}\n\n/**\n * Whether any updated dependency is one the lockfile records an edge for, and sits in a file `gh actions-lock` will look at.\n */\nfunction hasLockedUpdate(\n config: PostUpdateConfig,\n onboardedWorkflows: OnboardedWorkflows,\n): boolean {\n return config.upgrades.some((upgrade) => {\n if (upgrade.manager !== 'github-actions') {\n return false;\n }\n\n if (!upgrade.depType || !lockedDepTypes.includes(upgrade.depType)) {\n return false;\n }\n\n const packageFile = upgrade.packageFile;\n if (!packageFile) {\n return false;\n }\n\n return isLockfileManaged(packageFile, onboardedWorkflows);\n });\n}\n\n/**\n * Regenerate `.github/workflows/actions.lock` once per branch.\n *\n * The lockfile records a transitive graph - resolved commits, numeric owner and repository IDs, and each composite action's own `uses:` edges - so it is regenerated by its own tool rather than patched here.\n * `gh actions-lock` re-reads every workflow from disk and rewrites the whole file, so this runs after all of the branch's package file updates have been flushed, in the same shape as npm's `getAdditionalFiles`.\n */\nexport async function updateActionsLockfile(\n config: PostUpdateConfig,\n packageFiles: Record<string, PackageFile[]> | undefined,\n): Promise<ActionsLockfileResult> {\n const empty: ActionsLockfileResult = {\n updatedArtifacts: [],\n artifactErrors: [],\n };\n\n const ghaPackageFiles = packageFiles?.['github-actions'];\n if (!ghaPackageFiles?.length) {\n return empty;\n }\n\n if (config.skipArtifactsUpdate) {\n logger.debug(`Skipping ${actionsLockFile} generation`);\n return empty;\n }\n\n const existingLockFileContent = await readLocalFile(actionsLockFile, 'utf8');\n if (!existingLockFileContent) {\n logger.debug(`No ${actionsLockFile} found`);\n return empty;\n }\n\n const parsedLockfile = ActionsLockfile.safeParse(existingLockFileContent);\n if (!parsedLockfile.success) {\n logger.warn(\n { err: parsedLockfile.error, lockFile: actionsLockFile },\n 'Failed to parse the GitHub Actions lockfile, so not regenerating it',\n );\n return empty;\n }\n\n if (!hasLockedUpdate(config, parsedLockfile.data.workflows)) {\n logger.debug(`No locked dependencies updated for ${actionsLockFile}`);\n return empty;\n }\n\n logger.debug(`Regenerating ${actionsLockFile}`);\n\n const ghaPackageFilePaths = new Set(\n ghaPackageFiles.map((file) => file.packageFile),\n );\n\n // Ensure that in-memory file contents are flushed to disk, so `actions-lock` can run against it.\n // A branch can group updates from other managers, whose contents may be binary - a Gradle wrapper JAR, say - so only write the workflows which the tool actually reads.\n const writtenContent = new Map<string, string>();\n for (const file of coerceArray(config.updatedPackageFiles)) {\n if (file.type === 'addition' && ghaPackageFilePaths.has(file.path)) {\n const contents = file.contents!.toString();\n await writeLocalFile(file.path, contents);\n writtenContent.set(file.path, contents);\n }\n }\n\n const tokenEnv = getTokenEnv();\n\n const ghConstraint = await resolveToolConstraint(config, 'gh');\n const ghActionsLockConstraint = await resolveToolConstraint(\n config,\n 'ghActionsLock',\n );\n\n const execOptions: ExecOptions = {\n // The tool rescans every workflow, so it runs from the repository root\n cwd: GlobalConfig.get('localDir'),\n // `extraEnv` is what forwards a variable into the Docker sidecar, but on its own it is only a default: `getChildEnv` lets a same-named variable in Renovate's own environment win.\n // The token we resolved from the host rules must not be shadowed by an ambient `GH_TOKEN`, so force it as well.\n extraEnv: tokenEnv,\n env: tokenEnv,\n toolConstraints: [{ toolName: 'gh', constraint: ghConstraint }],\n docker: {},\n };\n\n // `--no-interactive`: we have no terminal to answer prompts with\n // `--no-narrow`: keep the ref that we wrote, to avoid a `@v4` being rewritten as `@v4.2.1`\n // `--no-migrate-local-actions`: on-by-default, but unrelated to our lockfile updates\n const commands = [\n 'gh actions-lock --no-interactive --no-narrow --no-migrate-local-actions',\n ];\n\n // `binarySource=global` means the administrator provisions tooling, so we must not reach into their `gh` install to add or re-pin an extension.\n // They own the extension version, and `constraints.ghActionsLock` does not apply.\n // TODO replace once containerbase/base#7279 is available\n if (GlobalConfig.get('binarySource') === 'global') {\n // Debug rather than warn: `constraints.ghActionsLock` ships with a default, so we cannot tell an explicit override from the default here, and warning would fire for every repository on this `binarySource`.\n logger.once.debug(\n { constraint: ghActionsLockConstraint },\n 'Not installing the `gh-actions-lock` extension, and ignoring `constraints.ghActionsLock`, because `binarySource=global` leaves tooling to the administrator',\n );\n } else {\n // `--force` makes an install a no-op when the specified version is already installed\n if (ghActionsLockConstraint) {\n commands.unshift(\n `gh extension install ${extensionName} --force --pin ${quote(ghActionsLockConstraint)}`,\n );\n } else {\n commands.unshift(`gh extension install ${extensionName} --force`);\n }\n }\n\n try {\n await exec(commands, execOptions);\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, `Error updating ${actionsLockFile}`);\n return {\n updatedArtifacts: [],\n artifactErrors: [\n {\n fileName: actionsLockFile,\n // an `ExecError` always carries a `stderr`, so fall back to the message rather than rendering an artifact error with nothing in it\n stderr: artifactErrorMessageFromExecError(err, err.message),\n },\n ],\n };\n }\n\n const updatedArtifacts: FileChange[] = [];\n\n const newLockFileContent = await readLocalFile(actionsLockFile, 'utf8');\n if (newLockFileContent && newLockFileContent !== existingLockFileContent) {\n updatedArtifacts.push({\n type: 'addition',\n path: actionsLockFile,\n contents: newLockFileContent,\n });\n }\n\n // `actions-lock` may annotate workflows being managed with i.e. `# This workflow is managed by gh actions-lock.`, even if there were no updates to that workflow in this branch.\n // We should diff against Git, rather than against the branch's own updated package files, otherwise those annotations are left behind as uncommitted changes\n const status = await getRepoStatus();\n for (const path of status.modified) {\n // ignore the lockfile, as we've already committed it above, and any file which another manager owns\n if (path === actionsLockFile || !ghaPackageFilePaths.has(path)) {\n continue;\n }\n\n const newContent = await readLocalFile(path, 'utf8');\n // Whatever this branch wrote is committed as a package file update already, so only content which the tool changed on top of it is an artifact\n if (!newContent || newContent === writtenContent.get(path)) {\n continue;\n }\n logger.debug(`\\`gh actions-lock\\` annotated ${path}`);\n updatedArtifacts.push({\n type: 'addition',\n path,\n contents: newContent,\n });\n }\n\n if (!updatedArtifacts.length) {\n logger.debug(`${actionsLockFile} is unchanged`);\n }\n\n return { updatedArtifacts, artifactErrors: [] };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,MAAM,gBAAgB;;AAGtB,MAAM,iBAAiB;CAAC;CAAU;CAAY;AAAQ;AAEtD,SAAS,UAAU,KAAiC;CAClD,OAAO,gBAAgBA,KAAe;EAAE,UAAU;EAAU;CAAI,CAAC,CAAC;AACpE;;;;;;AAOA,SAAS,cAAwB;CAC/B,MAAM,oBAAoB;CAC1B,MAAM,qBAAqB,aAAa,IAAI,UAAU;CAEtD,MAAM,WACJ,sBAAsB,eAAe,kBAAkB,MAAM,WACzD,qBACA;CAEN,MAAM,WAAW,SAAS,QAAQ,CAAC,EAAE;CACrC,MAAM,eACJ,CAAC,CAAC,YAAY,aAAa,oBAAoB,aAAa;CAE9D,MAAM,MAAgB,CAAC;CAEvB,IAAI,cAAc;EAChB,MAAM,kBAAkB,UAAU,QAAQ;EAC1C,IAAI,iBAAiB;GACnB,IAAI,UAAU;GACd,IAAI,sBAAsB;EAC5B;CACF;CAEA,MAAM,QAAQ,UAAU,iBAAiB;CACzC,IAAI,OACF,IAAI,WAAW;CAGjB,IAAI,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,QACpB,OAAO,MAAM,6CAA6C;CAG5D,OAAO;AACT;;;;AAKA,SAAS,gBACP,QACA,oBACS;CACT,OAAO,OAAO,SAAS,MAAM,YAAY;EACvC,IAAI,QAAQ,YAAY,kBACtB,OAAO;EAGT,IAAI,CAAC,QAAQ,WAAW,CAAC,eAAe,SAAS,QAAQ,OAAO,GAC9D,OAAO;EAGT,MAAM,cAAc,QAAQ;EAC5B,IAAI,CAAC,aACH,OAAO;EAGT,O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2,6 +2,7 @@ import "../../../constants/error-messages.js";
|
|
|
2
2
|
import { logger } from "../../../logger/index.js";
|
|
3
3
|
import { deleteLocalFile, getSiblingFileName, readLocalFile, writeLocalFile } from "../../../util/fs/index.js";
|
|
4
4
|
import { exec } from "../../../util/exec/index.js";
|
|
5
|
+
import { resolveToolConstraint } from "../util.js";
|
|
5
6
|
import { isEmptyArray, isString } from "@sindresorhus/is";
|
|
6
7
|
import { quote } from "shlex";
|
|
7
8
|
//#region lib/modules/manager/gleam/artifacts.ts
|
|
@@ -27,7 +28,7 @@ async function updateArtifacts(updateArtifact) {
|
|
|
27
28
|
docker: {},
|
|
28
29
|
toolConstraints: [{
|
|
29
30
|
toolName: "gleam",
|
|
30
|
-
constraint: config
|
|
31
|
+
constraint: await resolveToolConstraint(config, "gleam")
|
|
31
32
|
}]
|
|
32
33
|
};
|
|
33
34
|
const updateCommand = ["gleam deps update", ...(isLockFileMaintenance ? [] : updatedDeps.map((dep) => dep.depName).filter(isString)).map(quote)].join(" ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":[],"sources":["../../../../lib/modules/manager/gleam/artifacts.ts"],"sourcesContent":["import { isEmptyArray, isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n deleteLocalFile,\n getSiblingFileName,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\n\nexport async function updateArtifacts(\n updateArtifact: UpdateArtifact,\n): Promise<UpdateArtifactsResult[] | null> {\n const { packageFileName, updatedDeps, newPackageFileContent, config } =\n updateArtifact;\n logger.debug(`gleam.updateArtifacts(${packageFileName})`);\n const { isLockFileMaintenance } = config;\n\n if (isEmptyArray(updatedDeps) && !isLockFileMaintenance) {\n logger.debug('No updated gleam deps - returning null');\n return null;\n }\n\n const lockFileName = getSiblingFileName(packageFileName, 'manifest.toml');\n\n const oldLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!oldLockFileContent) {\n logger.debug(`No ${lockFileName} found`);\n return null;\n }\n\n try {\n await writeLocalFile(packageFileName, newPackageFileContent);\n if (isLockFileMaintenance) {\n await deleteLocalFile(lockFileName);\n }\n\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n docker: {},\n toolConstraints: [\n {\n toolName: 'gleam',\n constraint: config
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":[],"sources":["../../../../lib/modules/manager/gleam/artifacts.ts"],"sourcesContent":["import { isEmptyArray, isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n deleteLocalFile,\n getSiblingFileName,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { resolveToolConstraint } from '../util.ts';\n\nexport async function updateArtifacts(\n updateArtifact: UpdateArtifact,\n): Promise<UpdateArtifactsResult[] | null> {\n const { packageFileName, updatedDeps, newPackageFileContent, config } =\n updateArtifact;\n logger.debug(`gleam.updateArtifacts(${packageFileName})`);\n const { isLockFileMaintenance } = config;\n\n if (isEmptyArray(updatedDeps) && !isLockFileMaintenance) {\n logger.debug('No updated gleam deps - returning null');\n return null;\n }\n\n const lockFileName = getSiblingFileName(packageFileName, 'manifest.toml');\n\n const oldLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!oldLockFileContent) {\n logger.debug(`No ${lockFileName} found`);\n return null;\n }\n\n try {\n await writeLocalFile(packageFileName, newPackageFileContent);\n if (isLockFileMaintenance) {\n await deleteLocalFile(lockFileName);\n }\n\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n docker: {},\n toolConstraints: [\n {\n toolName: 'gleam',\n constraint: await resolveToolConstraint(config, 'gleam'),\n },\n ],\n };\n\n // `gleam deps update` with no packages rebuilds the lock file\n const packagesToUpdate = isLockFileMaintenance\n ? []\n : updatedDeps.map((dep) => dep.depName).filter(isString);\n\n const updateCommand = [\n 'gleam deps update',\n ...packagesToUpdate.map(quote),\n ].join(' ');\n await exec(updateCommand, execOptions);\n const newLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!newLockFileContent) {\n logger.debug(`No ${lockFileName} found`);\n return null;\n }\n if (oldLockFileContent === newLockFileContent) {\n logger.debug(`No changes in ${lockFileName} content`);\n return null;\n }\n return [\n {\n file: {\n type: 'addition',\n path: lockFileName,\n contents: newLockFileContent,\n },\n },\n ];\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.warn({ lockfile: lockFileName, err }, `Failed to update lock file`);\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,gBACpB,gBACyC;CACzC,MAAM,EAAE,iBAAiB,aAAa,uBAAuB,WAC3D;CACF,OAAO,MAAM,yBAAyB,gBAAgB,EAAE;CACxD,MAAM,EAAE,0BAA0B;CAElC,IAAI,aAAa,WAAW,KAAK,CAAC,uBAAuB;EACvD,OAAO,MAAM,wCAAwC;EACrD,OAAO;CACT;CAEA,MAAM,eAAe,mBAAmB,iBAAiB,eAAe;CAExE,MAAM,qBAAqB,MAAM,cAAc,cAAc,MAAM;CACnE,IAAI,CAAC,oBAAoB;EACvB,OAAO,MAAM,MAAM,aAAa,OAAO;EACvC,OAAO;CACT;CAEA,IAAI;EACF,MAAM,eAAe,iBAAiB,qBAAqB;EAC3D,IAAI,uBACF,MAAM,gBAAgB,YAAY;EAGpC,MAAM,cAA2B;GAC/B,SAAS;GACT,QAAQ,CAAC;GACT,iBAAiB,CACf;IACE,UAAU;IACV,YAAY,MAAM,sBAAsB,QAAQ,OAAO;GACzD,CACF;EACF;EAOA,MAAM,gBAAgB,CACpB,qBACA,IANuB,wBACrB,CAAC,IACD,YAAY,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,OAAO,QAAQ,EAAA,CAInC,IAAI,KAAK,CAC/B,CAAC,CAAC,KAAK,GAAG;EACV,MAAM,KAAK,eAAe,WAAW;EACrC,MAAM,qBAAqB,MAAM,cAAc,cAAc,MAAM;EACnE,IAAI,CAAC,oBAAoB;GACvB,OAAO,MAAM,MAAM,aAAa,OAAO;GACvC,OAAO;EACT;EACA,IAAI,uBAAuB,oBAAoB;GAC7C,OAAO,MAAM,iBAAiB,aAAa,SAAS;GACpD,OAAO;EACT;EACA,OAAO,CACL,EACE,MAAM;GACJ,MAAM;GACN,MAAM;GACN,UAAU;EACZ,EACF,CACF;CACF,SAAS,KAAK;EACZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAER,OAAO,KAAK;GAAE,UAAU;GAAc;EAAI,GAAG,4BAA4B;EACzE,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF"}
|
|
@@ -8,6 +8,7 @@ import { ensureCacheDir, findLocalSiblingOrParent, isValidLocalPath, readLocalFi
|
|
|
8
8
|
import { filterMap } from "../../../util/filter-map.js";
|
|
9
9
|
import { isValid as isVersion } from "../../versioning/semver/index.js";
|
|
10
10
|
import { getRepoStatus } from "../../../util/git/index.js";
|
|
11
|
+
import { resolveToolConstraint } from "../util.js";
|
|
11
12
|
import { withGitEnvironment } from "../../../util/git/exec.js";
|
|
12
13
|
import { getExtraDepsNotice } from "./artifacts-extra.js";
|
|
13
14
|
import { getGoModulesInTidyOrder } from "./package-tree.js";
|
|
@@ -18,7 +19,7 @@ import semver from "semver";
|
|
|
18
19
|
//#region lib/modules/manager/gomod/artifacts.ts
|
|
19
20
|
const { major: major$1, valid: valid$1 } = semver;
|
|
20
21
|
const gitExec = withGitEnvironment(["go"]);
|
|
21
|
-
function getUpdateImportPathCmds(updatedDeps,
|
|
22
|
+
async function getUpdateImportPathCmds(updatedDeps, config) {
|
|
22
23
|
const invalidMajorDeps = updatedDeps.filter(({ newVersion }) => !valid$1(newVersion));
|
|
23
24
|
if (invalidMajorDeps.length > 0) invalidMajorDeps.forEach(({ depName }) => logger.warn({ depName }, "Ignoring dependency: Could not get major version"));
|
|
24
25
|
const updateImportCommands = updatedDeps.filter(({ newVersion }) => valid$1(newVersion) && !newVersion.endsWith("+incompatible")).map(({ depName, newVersion }) => ({
|
|
@@ -27,7 +28,7 @@ function getUpdateImportPathCmds(updatedDeps, { constraints }) {
|
|
|
27
28
|
})).filter(({ depName, newMajor }) => depName.startsWith("gopkg.in/") || newMajor > 1).map(({ depName, newMajor }) => `mod upgrade --mod-name=${quote(depName)} -t=${newMajor}`);
|
|
28
29
|
if (updateImportCommands.length > 0) {
|
|
29
30
|
let installMarwanModArgs = "install github.com/marwan-at-work/mod/cmd/mod@latest";
|
|
30
|
-
const gomodModCompatibility =
|
|
31
|
+
const gomodModCompatibility = await resolveToolConstraint(config, "gomodMod");
|
|
31
32
|
if (gomodModCompatibility) {
|
|
32
33
|
if (gomodModCompatibility.startsWith("v") && isVersion(gomodModCompatibility.replace(regEx(/^v/), ""))) installMarwanModArgs = installMarwanModArgs.replace(regEx(/@latest$/), `@${gomodModCompatibility}`);
|
|
33
34
|
else logger.debug({ gomodModCompatibility }, "marwan-at-work/mod compatibility range is not valid - skipping");
|
|
@@ -75,7 +76,7 @@ async function updateArtifacts({ packageFileName: goModFileName, updatedDeps, ne
|
|
|
75
76
|
massagedGoMod = massagedGoMod.replace(inlineReplaceRegEx, inlineCommentOut).replace(blockReplaceRegEx, blockCommentOut);
|
|
76
77
|
if (massagedGoMod !== newGoModContent) logger.debug("Removed some relative replace statements and comments from go.mod");
|
|
77
78
|
}
|
|
78
|
-
const goConstraints = deriveGoToolchainConstraints(config, newGoModContent);
|
|
79
|
+
const goConstraints = await deriveGoToolchainConstraints(config, newGoModContent);
|
|
79
80
|
try {
|
|
80
81
|
await writeLocalFile(goModFileName, massagedGoMod);
|
|
81
82
|
const cmd = "go";
|
|
@@ -120,7 +121,7 @@ async function updateArtifacts({ packageFileName: goModFileName, updatedDeps, ne
|
|
|
120
121
|
execCommands.push(`${cmd} ${args}`);
|
|
121
122
|
const isImportPathUpdateRequired = config.postUpdateOptions?.includes("gomodUpdateImportPaths") && config.updateType === "major";
|
|
122
123
|
if (isImportPathUpdateRequired) {
|
|
123
|
-
const updateImportCmds = getUpdateImportPathCmds(updatedDeps, config);
|
|
124
|
+
const updateImportCmds = await getUpdateImportPathCmds(updatedDeps, config);
|
|
124
125
|
if (updateImportCmds.length > 0) {
|
|
125
126
|
logger.debug(updateImportCmds, "update import path commands included");
|
|
126
127
|
execCommands.push(...updateImportCmds);
|
|
@@ -299,11 +300,12 @@ function getGoConstraints(content) {
|
|
|
299
300
|
* 1. config: \`constraints.go\`
|
|
300
301
|
* 1. \`go.mod\`: \`toolchain\` directive
|
|
301
302
|
* 1. \`go.mod\`: \`go\` directive
|
|
303
|
+
* 1. the \`go\` constraint collected during extraction
|
|
302
304
|
*
|
|
303
305
|
* NOTE that the \`constraints.golang\` is not used (TODO #42601)
|
|
304
306
|
*/
|
|
305
|
-
function deriveGoToolchainConstraints(config, newGoModContent) {
|
|
306
|
-
return config
|
|
307
|
+
async function deriveGoToolchainConstraints(config, newGoModContent) {
|
|
308
|
+
return await resolveToolConstraint(config, "go", () => getGoConstraints(newGoModContent));
|
|
307
309
|
}
|
|
308
310
|
//#endregion
|
|
309
311
|
export { deriveGoToolchainConstraints, updateArtifacts };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":["valid","major","isValid"],"sources":["../../../../lib/modules/manager/gomod/artifacts.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport semver from 'semver';\nimport { quote } from 'shlex';\nimport upath from 'upath';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { getEnv } from '../../../util/env.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport { filterMap } from '../../../util/filter-map.ts';\nimport {\n ensureCacheDir,\n findLocalSiblingOrParent,\n isValidLocalPath,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../util/git/exec.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { isValid } from '../../versioning/semver/index.ts';\nimport type {\n PackageDependency,\n UpdateArtifact,\n UpdateArtifactsConfig,\n UpdateArtifactsResult,\n} from '../types.ts';\nimport { getExtraDepsNotice } from './artifacts-extra.ts';\nimport { getGoModulesInTidyOrder } from './package-tree.ts';\n\nconst { major, valid } = semver;\nconst gitExec = withGitEnvironment(['go']);\n\nfunction getUpdateImportPathCmds(\n updatedDeps: PackageDependency[],\n { constraints }: UpdateArtifactsConfig,\n): string[] {\n // Check if we fail to parse any major versions and log that they're skipped\n const invalidMajorDeps = updatedDeps.filter(\n ({ newVersion }) => !valid(newVersion),\n );\n if (invalidMajorDeps.length > 0) {\n invalidMajorDeps.forEach(({ depName }) =>\n logger.warn(\n { depName },\n 'Ignoring dependency: Could not get major version',\n ),\n );\n }\n\n const updateImportCommands = updatedDeps\n .filter(\n ({ newVersion }) =>\n valid(newVersion) && !newVersion!.endsWith('+incompatible'),\n )\n .map(({ depName, newVersion }) => ({\n depName: depName!,\n newMajor: major(newVersion!),\n }))\n // Skip path updates going from v0 to v1\n .filter(\n ({ depName, newMajor }) =>\n depName.startsWith('gopkg.in/') || newMajor > 1,\n )\n\n .map(\n ({ depName, newMajor }) =>\n `mod upgrade --mod-name=${quote(depName)} -t=${newMajor}`,\n );\n\n if (updateImportCommands.length > 0) {\n let installMarwanModArgs =\n 'install github.com/marwan-at-work/mod/cmd/mod@latest';\n const gomodModCompatibility = constraints?.gomodMod;\n if (gomodModCompatibility) {\n if (\n gomodModCompatibility.startsWith('v') &&\n isValid(gomodModCompatibility.replace(regEx(/^v/), ''))\n ) {\n installMarwanModArgs = installMarwanModArgs.replace(\n regEx(/@latest$/),\n `@${gomodModCompatibility}`,\n );\n } else {\n logger.debug(\n { gomodModCompatibility },\n 'marwan-at-work/mod compatibility range is not valid - skipping',\n );\n }\n } else {\n logger.debug(\n 'No marwan-at-work/mod compatibility range found - installing marwan-at-work/mod latest',\n );\n }\n updateImportCommands.unshift(`go ${installMarwanModArgs}`);\n }\n\n return updateImportCommands;\n}\n\nfunction useModcacherw(goVersion: string | undefined): boolean {\n if (!isString(goVersion)) {\n return true;\n }\n\n return semver.intersects(goVersion, `>=1.14`);\n}\n\nexport async function updateArtifacts({\n packageFileName: goModFileName,\n updatedDeps,\n newPackageFileContent: newGoModContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.debug(`gomod.updateArtifacts(${goModFileName})`);\n\n const sumFileName = goModFileName.replace(regEx(/\\.mod$/), '.sum');\n const existingGoSumContent = await readLocalFile(sumFileName);\n if (!existingGoSumContent) {\n logger.debug('No go.sum found');\n return null;\n }\n const goModDir = upath.dirname(goModFileName);\n const goModFileBaseName = upath.basename(goModFileName);\n const modFileFlag =\n goModFileBaseName === 'go.mod'\n ? ''\n : ` -modfile=${quote(goModFileBaseName)}`;\n\n // The \"vendor\" directory can be next to the go.mod, but also in the parent directory in case\n // the go workspaces are used.\n const vendorDir = await findLocalSiblingOrParent(goModFileName, 'vendor');\n const vendorModulesFileName = upath.join(vendorDir ?? '', 'modules.txt');\n const useVendor =\n !!config.postUpdateOptions?.includes('gomodVendor') ||\n (!config.postUpdateOptions?.includes('gomodSkipVendor') &&\n vendorDir &&\n (await readLocalFile(vendorModulesFileName)) !== null);\n let massagedGoMod = newGoModContent;\n const useGoGenerate = !!config.postUpdateOptions?.includes('goGenerate');\n const allowedUnsafeExecutions = GlobalConfig.get('allowedUnsafeExecutions');\n const goGenerateAllowed = allowedUnsafeExecutions?.includes('goGenerate');\n\n if (config.postUpdateOptions?.includes('gomodMassage')) {\n // Regex match inline replace directive, example:\n // replace golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5\n // https://go.dev/ref/mod#go-mod-file-replace\n\n // replace bracket after comments, so it doesn't break the regex, doing a complex regex causes problems\n // when there's a comment and \")\" after it, the regex will read replace block until comment.. and stop.\n massagedGoMod = massagedGoMod\n .split('\\n')\n .map((line) => {\n if (line.trim().startsWith('//')) {\n return line.replace(')', 'renovate-replace-bracket');\n }\n return line;\n })\n .join('\\n');\n\n const inlineReplaceRegEx = regEx(\n /(?<newline>\\r?\\n)(?<directive>replace\\s+[^\\s]+\\s+=>\\s+\\.\\.\\/.*)/g,\n );\n\n // $<newline> will be matched with the (\\r?\\n) group\n // $<directive> will be matched with the inline replace match, example\n // \"// renovate-replace replace golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5\"\n const inlineCommentOut = '$<newline>// renovate-replace $<directive>';\n\n // Regex match replace directive block, example:\n // replace (\n // golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5\n // )\n const blockReplaceRegEx = regEx(/(?:\\r?\\n)replace\\s*\\([^)]+\\s*\\)/g);\n\n /**\n * replacerFunction for commenting out replace blocks\n * @param match A string representing a golang replace directive block\n * @returns A commented out block with // renovate-replace\n */\n function blockCommentOut(match: string): string {\n return match.replace(\n regEx(/(?<newline>\\r?\\n)/g),\n '$<newline>// renovate-replace ',\n );\n }\n\n // Comment out golang replace directives\n massagedGoMod = massagedGoMod\n .replace(inlineReplaceRegEx, inlineCommentOut)\n .replace(blockReplaceRegEx, blockCommentOut);\n\n if (massagedGoMod !== newGoModContent) {\n logger.debug(\n 'Removed some relative replace statements and comments from go.mod',\n );\n }\n }\n const goConstraints = deriveGoToolchainConstraints(config, newGoModContent);\n\n try {\n await writeLocalFile(goModFileName, massagedGoMod);\n\n const cmd = 'go';\n const env = getEnv();\n const execOptions: ExecOptions = {\n cwdFile: goModFileName,\n extraEnv: {\n GOPATH: await ensureCacheDir('go'),\n GOPROXY: env.GOPROXY,\n GOPRIVATE: env.GOPRIVATE,\n GONOPROXY: env.GONOPROXY,\n GONOSUMDB: env.GONOSUMDB,\n GOSUMDB: env.GOSUMDB,\n GOINSECURE: env.GOINSECURE,\n /* v8 ignore next -- TODO: add test */\n GOFLAGS: useModcacherw(goConstraints) ? '-modcacherw' : null,\n CGO_ENABLED: GlobalConfig.get('binarySource') === 'docker' ? '0' : null,\n },\n docker: {},\n toolConstraints: [\n {\n toolName: 'golang',\n constraint: goConstraints,\n },\n ],\n };\n\n const execCommands: string[] = [];\n\n let goGetDirs: string | undefined;\n if (config.goGetDirs) {\n goGetDirs = config.goGetDirs\n .filter((dir) => {\n const isValid = isValidLocalPath(dir);\n if (!isValid) {\n logger.warn({ dir }, 'Invalid path in goGetDirs');\n }\n return isValid;\n })\n .map(quote)\n .join(' ');\n\n if (goGetDirs === '') {\n throw new Error('Invalid goGetDirs');\n }\n }\n\n let args = `get${modFileFlag} `;\n\n if (goConstraints && !semver.intersects(goConstraints, `>=1.18`)) {\n // For Go versions < 1.18, we need to use the -d flag to avoid builds or installs\n // https://go.dev/doc/go1.18#go-get\n args += `-d `;\n }\n\n args += `-t ${goGetDirs ?? './...'}`;\n logger.trace({ cmd, args }, 'go get command included');\n execCommands.push(`${cmd} ${args}`);\n\n // Update import paths on major updates\n const isImportPathUpdateRequired =\n config.postUpdateOptions?.includes('gomodUpdateImportPaths') &&\n config.updateType === 'major';\n\n if (isImportPathUpdateRequired) {\n const updateImportCmds = getUpdateImportPathCmds(updatedDeps, config);\n if (updateImportCmds.length > 0) {\n logger.debug(updateImportCmds, 'update import path commands included');\n // The updates\n execCommands.push(...updateImportCmds);\n }\n }\n\n const mustSkipGoModTidy =\n !config.postUpdateOptions?.includes('gomodUpdateImportPaths') &&\n config.updateType === 'major';\n if (mustSkipGoModTidy) {\n logger.debug('go mod tidy command skipped');\n }\n\n let tidyOpts = '';\n if (config.postUpdateOptions?.includes('gomodTidy1.17')) {\n tidyOpts += ' -compat=1.17';\n }\n if (config.postUpdateOptions?.includes('gomodTidyE')) {\n tidyOpts += ' -e';\n }\n\n // dependent modules can only be tidied once the updated module is settled\n const isGoModTidyAllRequired =\n config.postUpdateOptions?.includes('gomodTidyAll') === true;\n const isGoModTidyRequired =\n !mustSkipGoModTidy &&\n (config.postUpdateOptions?.includes('gomodTidy') === true ||\n config.postUpdateOptions?.includes('gomodTidy1.17') === true ||\n config.postUpdateOptions?.includes('gomodTidyE') === true ||\n isGoModTidyAllRequired ||\n (config.updateType === 'major' && isImportPathUpdateRequired));\n if (isGoModTidyRequired) {\n args = `mod tidy${modFileFlag}${tidyOpts}`;\n logger.debug('go mod tidy command included');\n execCommands.push(`${cmd} ${args}`);\n }\n\n let goWorkSumFileName = upath.join(goModDir, 'go.work.sum');\n if (useVendor) {\n // If we find a go.work, then use go workspace vendoring.\n const goWorkFile = await findLocalSiblingOrParent(\n goModFileName,\n 'go.work',\n );\n\n if (goWorkFile) {\n goWorkSumFileName = upath.join(\n upath.dirname(goWorkFile),\n 'go.work.sum',\n );\n\n args = 'work vendor';\n logger.debug('using go work vendor');\n execCommands.push(`${cmd} ${args}`);\n\n args = 'work sync';\n logger.debug('using go work sync');\n execCommands.push(`${cmd} ${args}`);\n } else {\n args = `mod vendor${modFileFlag}`;\n logger.debug('using go mod vendor');\n execCommands.push(`${cmd} ${args}`);\n }\n\n if (isGoModTidyRequired) {\n args = `mod tidy${modFileFlag}${tidyOpts}`;\n logger.debug('go mod tidy command included');\n execCommands.push(`${cmd} ${args}`);\n }\n }\n\n // We tidy one more time as a solution for #6795\n if (isGoModTidyRequired) {\n args = `mod tidy${modFileFlag}${tidyOpts}`;\n logger.debug('go mod tidy command included');\n execCommands.push(`${cmd} ${args}`);\n }\n\n let dependentModules: string[] = [];\n if (isGoModTidyAllRequired) {\n try {\n dependentModules = await getGoModulesInTidyOrder(goModFileName);\n for (const dependent of dependentModules) {\n const dir = upath.relative(goModDir, upath.dirname(dependent));\n execCommands.push(`${cmd} -C ${quote(dir)} mod tidy${tidyOpts}`);\n }\n logger.debug({ dependentModules }, 'go mod tidy commands included');\n } catch (err) {\n logger.warn({ err }, 'Failed to find dependent Go modules');\n }\n }\n\n if (useGoGenerate) {\n if (goGenerateAllowed) {\n logger.debug('go generate command included');\n execCommands.push(`${cmd} generate ./...`);\n } else {\n logger.once.warn(\n `go generate command requested as a post update action, but goGenerate is not permitted in the allowedUnsafeExecutions`,\n );\n }\n }\n\n await gitExec(execCommands, execOptions);\n\n const status = await getRepoStatus();\n const dependentFiles = dependentModules.flatMap((f) => [\n f,\n f.replace(regEx(/\\.mod$/), '.sum'),\n ]);\n\n if (\n !status.modified.includes(sumFileName) &&\n !status.modified.includes(goModFileName) &&\n !status.modified.includes(goWorkSumFileName) &&\n !dependentFiles.some((f) => status.modified.includes(f))\n ) {\n return null;\n }\n\n const res: UpdateArtifactsResult[] = [];\n if (status.modified.includes(sumFileName)) {\n logger.debug('Returning updated go.sum');\n res.push({\n file: {\n type: 'addition',\n path: sumFileName,\n contents: await readLocalFile(sumFileName),\n },\n });\n }\n\n if (status.modified.includes(goWorkSumFileName)) {\n logger.debug('Returning updated go.work.sum');\n res.push({\n file: {\n type: 'addition',\n path: goWorkSumFileName,\n contents: await readLocalFile(goWorkSumFileName),\n },\n });\n }\n\n for (const f of dependentFiles) {\n if (status.modified.includes(f)) {\n logger.trace(`Returning updated ${f}`);\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n\n // Include all the .go file import changes\n if (isImportPathUpdateRequired) {\n logger.debug('Returning updated go source files for import path changes');\n for (const f of status.modified) {\n if (f.endsWith('.go')) {\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n }\n\n const alreadyAdded = new Set<string>();\n const alreadyDeleted = new Set<string>();\n if (useVendor) {\n for (const f of status.modified.concat(status.not_added)) {\n if (vendorDir && f.startsWith(vendorDir)) {\n alreadyAdded.add(f);\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n for (const f of coerceArray(status.deleted)) {\n if (vendorDir && f.startsWith(vendorDir)) {\n alreadyDeleted.add(f);\n res.push({\n file: {\n type: 'deletion',\n path: f,\n },\n });\n }\n }\n }\n\n // TODO: throws in tests (#22198)\n const finalGoModContent = (await readLocalFile(goModFileName, 'utf8'))!\n .replace(regEx(/\\/\\/ renovate-replace /g), '')\n .replace(regEx(/renovate-replace-bracket/g), ')');\n if (finalGoModContent !== newGoModContent) {\n const artifactResult: UpdateArtifactsResult = {\n file: {\n type: 'addition',\n path: goModFileName,\n contents: finalGoModContent,\n },\n };\n\n const updatedDepNames = filterMap(updatedDeps, (dep) => dep?.depName);\n const extraDepsNotice = getExtraDepsNotice(\n newGoModContent,\n finalGoModContent,\n updatedDepNames,\n config,\n );\n\n if (extraDepsNotice) {\n artifactResult.notice = {\n file: goModFileName,\n message: extraDepsNotice,\n };\n }\n\n logger.debug('Found updated go.mod after go.sum update');\n res.push(artifactResult);\n alreadyAdded.add(goModFileName);\n }\n\n // add all files added when in `go generate` mode.\n // unfortunately there is not a good way as there is with vendoring or go import path updates to detect this.\n // Do this at the very very end to ensure we only capture files which would have been explicitly\n // modified, added, or deleted from a `go generate` invocation\n if (useGoGenerate && goGenerateAllowed) {\n logger.debug(\n 'Updating all modified files since generated files were added',\n );\n for (const f of status.modified.concat(status.created)) {\n if (!alreadyAdded.has(f)) {\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n for (const f of coerceArray(status.deleted)) {\n if (!alreadyDeleted.has(f)) {\n res.push({\n file: {\n type: 'deletion',\n path: f,\n },\n });\n }\n }\n }\n return res;\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update go.sum');\n return [\n {\n artifactError: {\n fileName: sumFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n\nfunction getGoConstraints(content: string): string | undefined {\n // prefer toolchain directive when go.mod has one\n const toolchainMatch = regEx(/^toolchain\\s*go(?<gover>\\d+\\.\\d+\\.\\d+)$/m).exec(\n content,\n );\n const toolchainVer = toolchainMatch?.groups?.gover;\n if (toolchainVer) {\n logger.debug(\n `Using go version ${toolchainVer} found in toolchain directive`,\n );\n return toolchainVer;\n }\n\n // If go.mod doesn't have toolchain directive and has a full go version spec,\n // for example `go 1.23.6`, pick this version, this doesn't match major.minor version spec.\n //\n // This is because when go.mod have same version defined in go directive and toolchain directive,\n // go will remove toolchain directive from go.mod.\n //\n // For example, go will rewrite `go 1.23.5\\ntoolchain go1.23.5` to `go 1.23.5` by default,\n // in this case, the go directive is the toolchain directive.\n const goFullVersion = regEx(/^go\\s*(?<gover>\\d+\\.\\d+\\.\\d+)$/m).exec(content)\n ?.groups?.gover;\n if (goFullVersion) {\n return goFullVersion;\n }\n\n const re = regEx(/^go\\s*(?<gover>\\d+\\.\\d+)$/m);\n const match = re.exec(content);\n if (!match?.groups?.gover) {\n return undefined;\n }\n return `^${match.groups.gover}`;\n}\n\n/**\n * Derive the version of the Go toolchain needed to run this project.\n *\n * This matches with the `golang` Containerbase tool.\n *\n * In precedence order:\n *\n * 1. config: \\`constraints.go\\`\n * 1. \\`go.mod\\`: \\`toolchain\\` directive\n * 1. \\`go.mod\\`: \\`go\\` directive\n *\n * NOTE that the \\`constraints.golang\\` is not used (TODO #42601)\n */\nexport function deriveGoToolchainConstraints(\n config: UpdateArtifactsConfig,\n newGoModContent: string,\n): string | undefined {\n return config.constraints?.go ?? getGoConstraints(newGoModContent);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAM,EAAE,OAAA,SAAO,OAAA,YAAU;AACzB,MAAM,UAAU,mBAAmB,CAAC,IAAI,CAAC;AAEzC,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OAAO,MAAM,0CAA0C;GACvD,IAAI,KAAK,cAAc;GACvB,aAAa,IAAI,aAAa;EAChC;EAMA,IAAI,iBAAiB,mBAAmB;GACtC,OAAO,MACL,8DACF;GACA,KAAK,MAAM,KAAK,OAAO,SAAS,OAAO,OAAO,OAAO,GACnD,IAAI,CAAC,aAAa,IAAI,CAAC,GACrB,IAAI,KAAK,EACP,MAAM;IACJ,MAAM;IACN,MAAM;IACN,UAAU,MAAM,cAAc,CAAC;GACjC,EACF,CAAC;GAGL,KAAK,MAAM,KAAK,YAAY,OAAO,OAAO,GACxC,IAAI,CAAC,eAAe,IAAI,CAAC,GACvB,IAAI,KAAK,EACP,MAAM;IACJ,MAAM;IACN,MAAM;GACR,EACF,CAAC;EAGP;EACA,OAAO;CACT,SAAS,KAAK;EACZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAER,OAAO,MAAM,EAAE,IAAI,GAAG,yBAAyB;EAC/C,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF;AAEA,SAAS,iBAAiB,SAAqC;CAK7D,MAAM,eAHiB,MAAM,0CAA0C,CAAC,CAAC,KACvE,OAEgC,CAAC,EAAE,QAAQ;CAC7C,IAAI,cAAc;EAChB,OAAO,MACL,oBAAoB,aAAa,8BACnC;EACA,OAAO;CACT;CAUA,MAAM,gBAAgB,MAAM,iCAAiC,CAAC,CAAC,KAAK,OAAO,CAAC,EACxE,QAAQ;CACZ,IAAI,eACF,OAAO;CAIT,MAAM,QADK,MAAM,4BACF,CAAC,CAAC,KAAK,OAAO;CAC7B,IAAI,CAAC,OAAO,QAAQ,OAClB;CAEF,OAAO,IAAI,MAAM,OAAO;AAC1B;;;;;;;;;;;;;;AAeA,SAAgB,6BACd,QACA,iBACoB;CACpB,OAAO,OAAO,aAAa,MAAM,iBAAiB,eAAe;AACnE"}
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":["valid","major","isValid"],"sources":["../../../../lib/modules/manager/gomod/artifacts.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport semver from 'semver';\nimport { quote } from 'shlex';\nimport upath from 'upath';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { getEnv } from '../../../util/env.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport { filterMap } from '../../../util/filter-map.ts';\nimport {\n ensureCacheDir,\n findLocalSiblingOrParent,\n isValidLocalPath,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../util/git/exec.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { isValid } from '../../versioning/semver/index.ts';\nimport type {\n PackageDependency,\n UpdateArtifact,\n UpdateArtifactsConfig,\n UpdateArtifactsResult,\n} from '../types.ts';\nimport { resolveToolConstraint } from '../util.ts';\nimport { getExtraDepsNotice } from './artifacts-extra.ts';\nimport { getGoModulesInTidyOrder } from './package-tree.ts';\n\nconst { major, valid } = semver;\nconst gitExec = withGitEnvironment(['go']);\n\nasync function getUpdateImportPathCmds(\n updatedDeps: PackageDependency[],\n config: UpdateArtifactsConfig,\n): Promise<string[]> {\n // Check if we fail to parse any major versions and log that they're skipped\n const invalidMajorDeps = updatedDeps.filter(\n ({ newVersion }) => !valid(newVersion),\n );\n if (invalidMajorDeps.length > 0) {\n invalidMajorDeps.forEach(({ depName }) =>\n logger.warn(\n { depName },\n 'Ignoring dependency: Could not get major version',\n ),\n );\n }\n\n const updateImportCommands = updatedDeps\n .filter(\n ({ newVersion }) =>\n valid(newVersion) && !newVersion!.endsWith('+incompatible'),\n )\n .map(({ depName, newVersion }) => ({\n depName: depName!,\n newMajor: major(newVersion!),\n }))\n // Skip path updates going from v0 to v1\n .filter(\n ({ depName, newMajor }) =>\n depName.startsWith('gopkg.in/') || newMajor > 1,\n )\n\n .map(\n ({ depName, newMajor }) =>\n `mod upgrade --mod-name=${quote(depName)} -t=${newMajor}`,\n );\n\n if (updateImportCommands.length > 0) {\n let installMarwanModArgs =\n 'install github.com/marwan-at-work/mod/cmd/mod@latest';\n const gomodModCompatibility = await resolveToolConstraint(\n config,\n 'gomodMod',\n );\n if (gomodModCompatibility) {\n if (\n gomodModCompatibility.startsWith('v') &&\n isValid(gomodModCompatibility.replace(regEx(/^v/), ''))\n ) {\n installMarwanModArgs = installMarwanModArgs.replace(\n regEx(/@latest$/),\n `@${gomodModCompatibility}`,\n );\n } else {\n logger.debug(\n { gomodModCompatibility },\n 'marwan-at-work/mod compatibility range is not valid - skipping',\n );\n }\n } else {\n logger.debug(\n 'No marwan-at-work/mod compatibility range found - installing marwan-at-work/mod latest',\n );\n }\n updateImportCommands.unshift(`go ${installMarwanModArgs}`);\n }\n\n return updateImportCommands;\n}\n\nfunction useModcacherw(goVersion: string | undefined): boolean {\n if (!isString(goVersion)) {\n return true;\n }\n\n return semver.intersects(goVersion, `>=1.14`);\n}\n\nexport async function updateArtifacts({\n packageFileName: goModFileName,\n updatedDeps,\n newPackageFileContent: newGoModContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.debug(`gomod.updateArtifacts(${goModFileName})`);\n\n const sumFileName = goModFileName.replace(regEx(/\\.mod$/), '.sum');\n const existingGoSumContent = await readLocalFile(sumFileName);\n if (!existingGoSumContent) {\n logger.debug('No go.sum found');\n return null;\n }\n const goModDir = upath.dirname(goModFileName);\n const goModFileBaseName = upath.basename(goModFileName);\n const modFileFlag =\n goModFileBaseName === 'go.mod'\n ? ''\n : ` -modfile=${quote(goModFileBaseName)}`;\n\n // The \"vendor\" directory can be next to the go.mod, but also in the parent directory in case\n // the go workspaces are used.\n const vendorDir = await findLocalSiblingOrParent(goModFileName, 'vendor');\n const vendorModulesFileName = upath.join(vendorDir ?? '', 'modules.txt');\n const useVendor =\n !!config.postUpdateOptions?.includes('gomodVendor') ||\n (!config.postUpdateOptions?.includes('gomodSkipVendor') &&\n vendorDir &&\n (await readLocalFile(vendorModulesFileName)) !== null);\n let massagedGoMod = newGoModContent;\n const useGoGenerate = !!config.postUpdateOptions?.includes('goGenerate');\n const allowedUnsafeExecutions = GlobalConfig.get('allowedUnsafeExecutions');\n const goGenerateAllowed = allowedUnsafeExecutions?.includes('goGenerate');\n\n if (config.postUpdateOptions?.includes('gomodMassage')) {\n // Regex match inline replace directive, example:\n // replace golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5\n // https://go.dev/ref/mod#go-mod-file-replace\n\n // replace bracket after comments, so it doesn't break the regex, doing a complex regex causes problems\n // when there's a comment and \")\" after it, the regex will read replace block until comment.. and stop.\n massagedGoMod = massagedGoMod\n .split('\\n')\n .map((line) => {\n if (line.trim().startsWith('//')) {\n return line.replace(')', 'renovate-replace-bracket');\n }\n return line;\n })\n .join('\\n');\n\n const inlineReplaceRegEx = regEx(\n /(?<newline>\\r?\\n)(?<directive>replace\\s+[^\\s]+\\s+=>\\s+\\.\\.\\/.*)/g,\n );\n\n // $<newline> will be matched with the (\\r?\\n) group\n // $<directive> will be matched with the inline replace match, example\n // \"// renovate-replace replace golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5\"\n const inlineCommentOut = '$<newline>// renovate-replace $<directive>';\n\n // Regex match replace directive block, example:\n // replace (\n // golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5\n // )\n const blockReplaceRegEx = regEx(/(?:\\r?\\n)replace\\s*\\([^)]+\\s*\\)/g);\n\n /**\n * replacerFunction for commenting out replace blocks\n * @param match A string representing a golang replace directive block\n * @returns A commented out block with // renovate-replace\n */\n function blockCommentOut(match: string): string {\n return match.replace(\n regEx(/(?<newline>\\r?\\n)/g),\n '$<newline>// renovate-replace ',\n );\n }\n\n // Comment out golang replace directives\n massagedGoMod = massagedGoMod\n .replace(inlineReplaceRegEx, inlineCommentOut)\n .replace(blockReplaceRegEx, blockCommentOut);\n\n if (massagedGoMod !== newGoModContent) {\n logger.debug(\n 'Removed some relative replace statements and comments from go.mod',\n );\n }\n }\n const goConstraints = await deriveGoToolchainConstraints(\n config,\n newGoModContent,\n );\n\n try {\n await writeLocalFile(goModFileName, massagedGoMod);\n\n const cmd = 'go';\n const env = getEnv();\n const execOptions: ExecOptions = {\n cwdFile: goModFileName,\n extraEnv: {\n GOPATH: await ensureCacheDir('go'),\n GOPROXY: env.GOPROXY,\n GOPRIVATE: env.GOPRIVATE,\n GONOPROXY: env.GONOPROXY,\n GONOSUMDB: env.GONOSUMDB,\n GOSUMDB: env.GOSUMDB,\n GOINSECURE: env.GOINSECURE,\n /* v8 ignore next -- TODO: add test */\n GOFLAGS: useModcacherw(goConstraints) ? '-modcacherw' : null,\n CGO_ENABLED: GlobalConfig.get('binarySource') === 'docker' ? '0' : null,\n },\n docker: {},\n toolConstraints: [\n {\n toolName: 'golang',\n constraint: goConstraints,\n },\n ],\n };\n\n const execCommands: string[] = [];\n\n let goGetDirs: string | undefined;\n if (config.goGetDirs) {\n goGetDirs = config.goGetDirs\n .filter((dir) => {\n const isValid = isValidLocalPath(dir);\n if (!isValid) {\n logger.warn({ dir }, 'Invalid path in goGetDirs');\n }\n return isValid;\n })\n .map(quote)\n .join(' ');\n\n if (goGetDirs === '') {\n throw new Error('Invalid goGetDirs');\n }\n }\n\n let args = `get${modFileFlag} `;\n\n if (goConstraints && !semver.intersects(goConstraints, `>=1.18`)) {\n // For Go versions < 1.18, we need to use the -d flag to avoid builds or installs\n // https://go.dev/doc/go1.18#go-get\n args += `-d `;\n }\n\n args += `-t ${goGetDirs ?? './...'}`;\n logger.trace({ cmd, args }, 'go get command included');\n execCommands.push(`${cmd} ${args}`);\n\n // Update import paths on major updates\n const isImportPathUpdateRequired =\n config.postUpdateOptions?.includes('gomodUpdateImportPaths') &&\n config.updateType === 'major';\n\n if (isImportPathUpdateRequired) {\n const updateImportCmds = await getUpdateImportPathCmds(\n updatedDeps,\n config,\n );\n if (updateImportCmds.length > 0) {\n logger.debug(updateImportCmds, 'update import path commands included');\n // The updates\n execCommands.push(...updateImportCmds);\n }\n }\n\n const mustSkipGoModTidy =\n !config.postUpdateOptions?.includes('gomodUpdateImportPaths') &&\n config.updateType === 'major';\n if (mustSkipGoModTidy) {\n logger.debug('go mod tidy command skipped');\n }\n\n let tidyOpts = '';\n if (config.postUpdateOptions?.includes('gomodTidy1.17')) {\n tidyOpts += ' -compat=1.17';\n }\n if (config.postUpdateOptions?.includes('gomodTidyE')) {\n tidyOpts += ' -e';\n }\n\n // dependent modules can only be tidied once the updated module is settled\n const isGoModTidyAllRequired =\n config.postUpdateOptions?.includes('gomodTidyAll') === true;\n const isGoModTidyRequired =\n !mustSkipGoModTidy &&\n (config.postUpdateOptions?.includes('gomodTidy') === true ||\n config.postUpdateOptions?.includes('gomodTidy1.17') === true ||\n config.postUpdateOptions?.includes('gomodTidyE') === true ||\n isGoModTidyAllRequired ||\n (config.updateType === 'major' && isImportPathUpdateRequired));\n if (isGoModTidyRequired) {\n args = `mod tidy${modFileFlag}${tidyOpts}`;\n logger.debug('go mod tidy command included');\n execCommands.push(`${cmd} ${args}`);\n }\n\n let goWorkSumFileName = upath.join(goModDir, 'go.work.sum');\n if (useVendor) {\n // If we find a go.work, then use go workspace vendoring.\n const goWorkFile = await findLocalSiblingOrParent(\n goModFileName,\n 'go.work',\n );\n\n if (goWorkFile) {\n goWorkSumFileName = upath.join(\n upath.dirname(goWorkFile),\n 'go.work.sum',\n );\n\n args = 'work vendor';\n logger.debug('using go work vendor');\n execCommands.push(`${cmd} ${args}`);\n\n args = 'work sync';\n logger.debug('using go work sync');\n execCommands.push(`${cmd} ${args}`);\n } else {\n args = `mod vendor${modFileFlag}`;\n logger.debug('using go mod vendor');\n execCommands.push(`${cmd} ${args}`);\n }\n\n if (isGoModTidyRequired) {\n args = `mod tidy${modFileFlag}${tidyOpts}`;\n logger.debug('go mod tidy command included');\n execCommands.push(`${cmd} ${args}`);\n }\n }\n\n // We tidy one more time as a solution for #6795\n if (isGoModTidyRequired) {\n args = `mod tidy${modFileFlag}${tidyOpts}`;\n logger.debug('go mod tidy command included');\n execCommands.push(`${cmd} ${args}`);\n }\n\n let dependentModules: string[] = [];\n if (isGoModTidyAllRequired) {\n try {\n dependentModules = await getGoModulesInTidyOrder(goModFileName);\n for (const dependent of dependentModules) {\n const dir = upath.relative(goModDir, upath.dirname(dependent));\n execCommands.push(`${cmd} -C ${quote(dir)} mod tidy${tidyOpts}`);\n }\n logger.debug({ dependentModules }, 'go mod tidy commands included');\n } catch (err) {\n logger.warn({ err }, 'Failed to find dependent Go modules');\n }\n }\n\n if (useGoGenerate) {\n if (goGenerateAllowed) {\n logger.debug('go generate command included');\n execCommands.push(`${cmd} generate ./...`);\n } else {\n logger.once.warn(\n `go generate command requested as a post update action, but goGenerate is not permitted in the allowedUnsafeExecutions`,\n );\n }\n }\n\n await gitExec(execCommands, execOptions);\n\n const status = await getRepoStatus();\n const dependentFiles = dependentModules.flatMap((f) => [\n f,\n f.replace(regEx(/\\.mod$/), '.sum'),\n ]);\n\n if (\n !status.modified.includes(sumFileName) &&\n !status.modified.includes(goModFileName) &&\n !status.modified.includes(goWorkSumFileName) &&\n !dependentFiles.some((f) => status.modified.includes(f))\n ) {\n return null;\n }\n\n const res: UpdateArtifactsResult[] = [];\n if (status.modified.includes(sumFileName)) {\n logger.debug('Returning updated go.sum');\n res.push({\n file: {\n type: 'addition',\n path: sumFileName,\n contents: await readLocalFile(sumFileName),\n },\n });\n }\n\n if (status.modified.includes(goWorkSumFileName)) {\n logger.debug('Returning updated go.work.sum');\n res.push({\n file: {\n type: 'addition',\n path: goWorkSumFileName,\n contents: await readLocalFile(goWorkSumFileName),\n },\n });\n }\n\n for (const f of dependentFiles) {\n if (status.modified.includes(f)) {\n logger.trace(`Returning updated ${f}`);\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n\n // Include all the .go file import changes\n if (isImportPathUpdateRequired) {\n logger.debug('Returning updated go source files for import path changes');\n for (const f of status.modified) {\n if (f.endsWith('.go')) {\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n }\n\n const alreadyAdded = new Set<string>();\n const alreadyDeleted = new Set<string>();\n if (useVendor) {\n for (const f of status.modified.concat(status.not_added)) {\n if (vendorDir && f.startsWith(vendorDir)) {\n alreadyAdded.add(f);\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n for (const f of coerceArray(status.deleted)) {\n if (vendorDir && f.startsWith(vendorDir)) {\n alreadyDeleted.add(f);\n res.push({\n file: {\n type: 'deletion',\n path: f,\n },\n });\n }\n }\n }\n\n // TODO: throws in tests (#22198)\n const finalGoModContent = (await readLocalFile(goModFileName, 'utf8'))!\n .replace(regEx(/\\/\\/ renovate-replace /g), '')\n .replace(regEx(/renovate-replace-bracket/g), ')');\n if (finalGoModContent !== newGoModContent) {\n const artifactResult: UpdateArtifactsResult = {\n file: {\n type: 'addition',\n path: goModFileName,\n contents: finalGoModContent,\n },\n };\n\n const updatedDepNames = filterMap(updatedDeps, (dep) => dep?.depName);\n const extraDepsNotice = getExtraDepsNotice(\n newGoModContent,\n finalGoModContent,\n updatedDepNames,\n config,\n );\n\n if (extraDepsNotice) {\n artifactResult.notice = {\n file: goModFileName,\n message: extraDepsNotice,\n };\n }\n\n logger.debug('Found updated go.mod after go.sum update');\n res.push(artifactResult);\n alreadyAdded.add(goModFileName);\n }\n\n // add all files added when in `go generate` mode.\n // unfortunately there is not a good way as there is with vendoring or go import path updates to detect this.\n // Do this at the very very end to ensure we only capture files which would have been explicitly\n // modified, added, or deleted from a `go generate` invocation\n if (useGoGenerate && goGenerateAllowed) {\n logger.debug(\n 'Updating all modified files since generated files were added',\n );\n for (const f of status.modified.concat(status.created)) {\n if (!alreadyAdded.has(f)) {\n res.push({\n file: {\n type: 'addition',\n path: f,\n contents: await readLocalFile(f),\n },\n });\n }\n }\n for (const f of coerceArray(status.deleted)) {\n if (!alreadyDeleted.has(f)) {\n res.push({\n file: {\n type: 'deletion',\n path: f,\n },\n });\n }\n }\n }\n return res;\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update go.sum');\n return [\n {\n artifactError: {\n fileName: sumFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n\nfunction getGoConstraints(content: string): string | undefined {\n // prefer toolchain directive when go.mod has one\n const toolchainMatch = regEx(/^toolchain\\s*go(?<gover>\\d+\\.\\d+\\.\\d+)$/m).exec(\n content,\n );\n const toolchainVer = toolchainMatch?.groups?.gover;\n if (toolchainVer) {\n logger.debug(\n `Using go version ${toolchainVer} found in toolchain directive`,\n );\n return toolchainVer;\n }\n\n // If go.mod doesn't have toolchain directive and has a full go version spec,\n // for example `go 1.23.6`, pick this version, this doesn't match major.minor version spec.\n //\n // This is because when go.mod have same version defined in go directive and toolchain directive,\n // go will remove toolchain directive from go.mod.\n //\n // For example, go will rewrite `go 1.23.5\\ntoolchain go1.23.5` to `go 1.23.5` by default,\n // in this case, the go directive is the toolchain directive.\n const goFullVersion = regEx(/^go\\s*(?<gover>\\d+\\.\\d+\\.\\d+)$/m).exec(content)\n ?.groups?.gover;\n if (goFullVersion) {\n return goFullVersion;\n }\n\n const re = regEx(/^go\\s*(?<gover>\\d+\\.\\d+)$/m);\n const match = re.exec(content);\n if (!match?.groups?.gover) {\n return undefined;\n }\n return `^${match.groups.gover}`;\n}\n\n/**\n * Derive the version of the Go toolchain needed to run this project.\n *\n * This matches with the `golang` Containerbase tool.\n *\n * In precedence order:\n *\n * 1. config: \\`constraints.go\\`\n * 1. \\`go.mod\\`: \\`toolchain\\` directive\n * 1. \\`go.mod\\`: \\`go\\` directive\n * 1. the \\`go\\` constraint collected during extraction\n *\n * NOTE that the \\`constraints.golang\\` is not used (TODO #42601)\n */\nexport async function deriveGoToolchainConstraints(\n config: UpdateArtifactsConfig,\n newGoModContent: string,\n): Promise<string | undefined> {\n return await resolveToolConstraint(config, 'go', () =>\n getGoConstraints(newGoModContent),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,MAAM,EAAE,OAAA,SAAO,OAAA,YAAU;AACzB,MAAM,UAAU,mBAAmB,CAAC,IAAI,CAAC;AAEzC,eAAe,wBACb,aACA,QACmB;CAEnB,MAAM,mBAAmB,YAAY,QAClC,EAAE,iBAAiB,CAACA,QAAM,UAAU,CACvC;CACA,IAAI,iBAAiB,SAAS,GAC5B,iBAAiB,SAAS,EAAE,cAC1B,OAAO,KACL,EAAE,QAAQ,GACV,kDACF,CACF;CAGF,MAAM,uBAAuB,YAC1B,QACE,EAAE,iBACDA,QAAM,UAAU,KAAK,CAAC,WAAY,SAAS,eAAe,CAC9D,CAAC,CACA,KAAK,EAAE,SAAS,kBAAkB;EACxB;EACT,UAAUC,QAAM,UAAW;CAC7B,EAAE,CAAC,CAEF,QACE,EAAE,SAAS,eACV,QAAQ,WAAW,WAAW,KAAK,WAAW,CAClD,CAAC,CAEA,KACE,EAAE,SAAS,eACV,0BAA0B,MAAM,OAAO,EAAE,MAAM,UACnD;CAEF,IAAI,qBAAqB,SAAS,GAAG;EACnC,IAAI,uBACF;EACF,MAAM,wBAAwB,MAAM,sBAClC,QACA,UACF;EACA,IAAI,uBAAuB;GACzB,IACE,sBAAsB,WAAW,GAAG,KACpCC,UAAQ,sBAAsB,QAAQ,MAAM,IAAI,GAAG,EAAE,CAAC,GAEtD,uBAAuB,qBAAqB,QAC1C,MAAM,UAAU,GAChB,IAAI,uBACN;QAEA,OAAO,MACL,EAAE,sBAAsB,GACxB,gEACF;EAEJ,OACE,OAAO,MACL,wFACF;EAEF,qBAAqB,QAAQ,MAAM,sBAAsB;CAC3D;CAEA,OAAO;AACT;AAEA,SAAS,cAAc,WAAwC;CAC7D,IAAI,CAAC,SAAS,SAAS,GACrB,OAAO;CAGT,OAAO,OAAO,WAAW,WAAW,QAAQ;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AC,OAAO,QAAQ,OAClB;CAEF,OAAO,IAAI,MAAM,OAAO;AAC1B;;;;;;;;;;;;;;;AAgBA,eAAsB,6BACpB,QACA,iBAC6B;CAC7B,OAAO,MAAM,sBAAsB,QAAQ,YACzC,iBAAiB,eAAe,CAClC;AACF"}
|
|
@@ -5,6 +5,7 @@ import { logger } from "../../../logger/index.js";
|
|
|
5
5
|
import { findUpLocal, readLocalFile, writeLocalFile } from "../../../util/fs/index.js";
|
|
6
6
|
import { exec, getToolSettingsOptions, gradleJvmArg } from "../../../util/exec/index.js";
|
|
7
7
|
import { getFiles, getRepoStatus } from "../../../util/git/index.js";
|
|
8
|
+
import { resolveToolConstraint } from "../util.js";
|
|
8
9
|
import { scm } from "../../platform/scm.js";
|
|
9
10
|
import { isGradleBuildFile } from "./utils.js";
|
|
10
11
|
import { extraEnv, extractGradleVersion, getJavaConstraint, gradleWrapperFileName, prepareGradleCommand } from "../gradle-wrapper/utils.js";
|
|
@@ -102,7 +103,7 @@ async function updateArtifacts({ packageFileName, updatedDeps, newPackageFileCon
|
|
|
102
103
|
extraEnv,
|
|
103
104
|
toolConstraints: [{
|
|
104
105
|
toolName: "java",
|
|
105
|
-
constraint: config
|
|
106
|
+
constraint: await resolveToolConstraint(config, "java", async () => getJavaConstraint(await getGradleVersion(gradlewFile), gradlewFile))
|
|
106
107
|
}]
|
|
107
108
|
};
|
|
108
109
|
const cmds = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":[],"sources":["../../../../lib/modules/manager/gradle/artifacts.ts"],"sourcesContent":["import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport upath from 'upath';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport {\n exec,\n getToolSettingsOptions,\n gradleJvmArg,\n} from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n findUpLocal,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { getFiles, getRepoStatus } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { scm } from '../../platform/scm.ts';\nimport {\n extraEnv,\n extractGradleVersion,\n getJavaConstraint,\n gradleWrapperFileName,\n prepareGradleCommand,\n} from '../gradle-wrapper/utils.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport {\n isGcvLockFile,\n isGcvPropsFile,\n} from './extract/consistent-versions-plugin.ts';\nimport { isGradleBuildFile } from './utils.ts';\n\nexport function isGradleExecutionAllowed(command: string): boolean {\n const allowlist = GlobalConfig.get('allowedUnsafeExecutions');\n\n if (!allowlist.includes('gradleWrapper')) {\n logger.once.warn(\n { command },\n 'Gradle wrapper command was requested to run, but `gradleWrapper` is not permitted in the allowedUnsafeExecutions',\n );\n return false;\n }\n\n return true;\n}\n\n// .lockfile is gradle default lockfile, /versions.lock is gradle-consistent-versions plugin lockfile\nfunction isLockFile(fileName: string): boolean {\n return fileName.endsWith('.lockfile') || isGcvLockFile(fileName);\n}\n\nasync function getUpdatedLockfiles(\n oldLockFileContentMap: Record<string, string | null>,\n): Promise<UpdateArtifactsResult[]> {\n const res: UpdateArtifactsResult[] = [];\n\n const status = await getRepoStatus();\n\n for (const modifiedFile of status.modified) {\n if (\n isLockFile(modifiedFile) ||\n modifiedFile.endsWith('gradle/verification-metadata.xml')\n ) {\n const newContent = await readLocalFile(modifiedFile, 'utf8');\n if (oldLockFileContentMap[modifiedFile] !== newContent) {\n res.push({\n file: {\n type: 'addition',\n path: modifiedFile,\n contents: newContent,\n },\n });\n }\n }\n }\n\n return res;\n}\n\nasync function getSubProjectList(\n cmd: string,\n execOptions: ExecOptions,\n): Promise<string[]> {\n const subprojects = ['']; // = root project\n const subprojectsRegex = regEx(/^[ \\t]*subprojects: \\[(?<subprojects>.+)\\]/m);\n\n const gradleProperties = await exec(`${cmd} properties`, execOptions);\n const subprojectsMatch = gradleProperties.stdout.match(subprojectsRegex);\n if (subprojectsMatch?.groups?.subprojects) {\n const projectRegex = regEx(/project '(?<name>.+?)'/g);\n const matches = subprojectsMatch.groups.subprojects.matchAll(projectRegex);\n for (const match of matches) {\n if (match?.groups?.name) {\n subprojects.push(match.groups.name);\n }\n }\n }\n\n return subprojects;\n}\n\nasync function getGradleVersion(gradlewFile: string): Promise<string | null> {\n const propertiesFile = upath.join(\n upath.dirname(gradlewFile),\n 'gradle/wrapper/gradle-wrapper.properties',\n );\n const properties = await readLocalFile(propertiesFile, 'utf8');\n const extractResult = extractGradleVersion(properties ?? '');\n\n return extractResult ? extractResult.version : null;\n}\n\nasync function buildUpdateVerificationMetadataCmd(\n verificationMetadataFile: string | undefined,\n baseCmd: string,\n): Promise<string | null> {\n if (!verificationMetadataFile) {\n return null;\n }\n\n const verificationMetadata = await readLocalFile(verificationMetadataFile);\n const verifiesChecksums = verificationMetadata?.includes(\n '<verify-metadata>true</verify-metadata>',\n );\n const verifiesSignatures = verificationMetadata?.includes(\n '<verify-signatures>true</verify-signatures>',\n );\n\n const hashTypes = ['sha256', 'sha512'].filter((type) =>\n verificationMetadata?.includes(`<${type} `),\n );\n\n if (verifiesChecksums || hashTypes.length) {\n logger.debug(\n 'Dependency metadata verification enabled or checksums present - generating checksums',\n );\n }\n\n if ((verifiesChecksums || verifiesSignatures) && !hashTypes.length) {\n // fallback algorithm for pgp and in case a weak algorithm (md5, sha1) is used for checksums\n hashTypes.push('sha256');\n }\n\n if (verifiesSignatures) {\n logger.debug(\n 'Dependency signature verification enabled - generating PGP signatures',\n );\n hashTypes.push('pgp');\n }\n\n if (!hashTypes.length) {\n return null;\n }\n\n return `${baseCmd} --write-verification-metadata ${hashTypes.join(',')} dependencies`;\n}\n\nexport async function updateArtifacts({\n packageFileName,\n updatedDeps,\n newPackageFileContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.debug(`gradle.updateArtifacts(${packageFileName})`);\n\n const fileList = await scm.getFileList();\n const lockFiles = fileList.filter((file) => isLockFile(file));\n const verificationMetadataFile = fileList.find((fileName) =>\n fileName.endsWith('gradle/verification-metadata.xml'),\n );\n if (!lockFiles.length && !verificationMetadataFile) {\n logger.debug(\n 'No Gradle dependency lockfiles or verification metadata found - skipping update',\n );\n return null;\n }\n\n const gradlewName = gradleWrapperFileName();\n const gradlewFile = await findUpLocal(\n gradlewName,\n upath.dirname(packageFileName),\n );\n if (!gradlewFile) {\n logger.debug(\n 'Found Gradle dependency lockfiles but no gradlew - aborting update',\n );\n return null;\n }\n\n if (\n config.isLockFileMaintenance &&\n (!isGradleBuildFile(packageFileName) ||\n upath.dirname(packageFileName) !== upath.dirname(gradlewFile))\n ) {\n logger.trace(\n 'No build.gradle(.kts) file or not in root project - skipping lock file maintenance',\n );\n return null;\n }\n\n if (!isGradleExecutionAllowed(gradlewFile)) {\n logger.trace(\n 'Not allowed to execute gradle due to allowedUnsafeExecutions - aborting update',\n );\n return null;\n }\n\n logger.debug('Updating found Gradle dependency lockfiles');\n\n try {\n const oldLockFileContentMap = await getFiles(lockFiles);\n await prepareGradleCommand(gradlewFile);\n\n const baseCmd = `${gradlewName}${gradleJvmArg(getToolSettingsOptions(config.toolSettings))} --console=plain --dependency-verification lenient -q`;\n const execOptions: ExecOptions = {\n cwdFile: gradlewFile,\n docker: {},\n extraEnv,\n toolConstraints: [\n {\n toolName: 'java',\n constraint:\n config.constraints?.java ??\n (await getJavaConstraint(\n await getGradleVersion(gradlewFile),\n gradlewFile,\n )),\n },\n ],\n };\n\n const cmds = [];\n if (lockFiles.length) {\n const subprojects = await getSubProjectList(baseCmd, execOptions);\n let lockfileCmd = `${baseCmd} ${subprojects\n .map((project) => `${project}:dependencies`)\n .map(quote)\n .join(' ')}`;\n\n if (\n config.isLockFileMaintenance === true ||\n !updatedDeps.length ||\n isGcvPropsFile(packageFileName)\n ) {\n lockfileCmd += ' --write-locks';\n } else {\n const updatedDepNames = updatedDeps\n .map(({ depName, packageName }) => packageName ?? depName)\n .filter(isNonEmptyStringAndNotWhitespace);\n\n lockfileCmd += ` --update-locks ${updatedDepNames\n .map(quote)\n .join(',')}`;\n }\n cmds.push(lockfileCmd);\n }\n\n const updateVerificationMetadataCmd =\n await buildUpdateVerificationMetadataCmd(\n verificationMetadataFile,\n baseCmd,\n );\n if (updateVerificationMetadataCmd) {\n cmds.push(updateVerificationMetadataCmd);\n }\n\n if (!cmds.length) {\n logger.debug('No lockfile or verification metadata update necessary');\n return null;\n }\n\n await writeLocalFile(packageFileName, newPackageFileContent);\n await exec(cmds, { ...execOptions, ignoreStdout: true });\n\n const res = await getUpdatedLockfiles(oldLockFileContentMap);\n logger.debug('Returning updated Gradle dependency lockfiles');\n\n return res.length > 0 ? res : null;\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n\n logger.debug({ err }, 'Error while updating Gradle dependency lockfiles');\n return [\n {\n artifactError: {\n fileName: packageFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,SAAgB,yBAAyB,SAA0B;CAGjE,IAAI,CAFc,aAAa,IAAI,yBAEtB,CAAC,CAAC,SAAS,eAAe,GAAG;EACxC,OAAO,KAAK,KACV,EAAE,QAAQ,GACV,kHACF;EACA,OAAO;CACT;CAEA,OAAO;AACT;AAGA,SAAS,WAAW,UAA2B;CAC7C,OAAO,SAAS,SAAS,WAAW,KAAK,cAAc,QAAQ;AACjE;AAEA,eAAe,oBACb,uBACkC;CAClC,MAAM,MAA+B,CAAC;CAEtC,MAAM,SAAS,MAAM,cAAc;CAEnC,KAAK,MAAM,gBAAgB,OAAO,UAChC,IACE,WAAW,YAAY,KACvB,aAAa,SAAS,kCAAkC,GACxD;EACA,MAAM,aAAa,MAAM,cAAc,cAAc,MAAM;EAC3D,IAAI,sBAAsB,kBAAkB,YAC1C,IAAI,KAAK,EACP,MAAM;GACJ,MAAM;GACN,M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,CAAC,CAC3C,IAAI,KAAK,CAAC,CACV,KAAK,GAAG;GAEX,IACE,OAAO,0BAA0B,QACjC,CAAC,YAAY,UACb,eAAe,eAAe,GAE9B,eAAe;QACV;IACL,MAAM,kBAAkB,YACrB,KAAK,EAAE,SAAS,kBAAkB,eAAe,OAAO,CAAC,CACzD,OAAO,gCAAgC;IAE1C,eAAe,mBAAmB,gBAC/B,IAAI,KAAK,CAAC,CACV,KAAK,GAAG;GACb;GACA,KAAK,KAAK,WAAW;EACvB;EAEA,MAAM,gCACJ,MAAM,mCACJ,0BACA,OACF;EACF,IAAI,+BACF,KAAK,KAAK,6BAA6B;EAGzC,IAAI,CAAC,KAAK,QAAQ;GAChB,OAAO,MAAM,uDAAuD;GACpE,OAAO;EACT;EAEA,MAAM,eAAe,iBAAiB,qBAAqB;EAC3D,MAAM,KAAK,MAAM;GAAE,GAAG;GAAa,cAAc;EAAK,CAAC;EAEvD,MAAM,MAAM,MAAM,oBAAoB,qBAAqB;EAC3D,OAAO,MAAM,+CAA+C;EAE5D,OAAO,IAAI,SAAS,IAAI,MAAM;CAChC,SAAS,KAAK;EACZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAGR,OAAO,MAAM,EAAE,IAAI,GAAG,kDAAkD;EACxE,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":[],"sources":["../../../../lib/modules/manager/gradle/artifacts.ts"],"sourcesContent":["import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport upath from 'upath';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport {\n exec,\n getToolSettingsOptions,\n gradleJvmArg,\n} from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n findUpLocal,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { getFiles, getRepoStatus } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { scm } from '../../platform/scm.ts';\nimport {\n extraEnv,\n extractGradleVersion,\n getJavaConstraint,\n gradleWrapperFileName,\n prepareGradleCommand,\n} from '../gradle-wrapper/utils.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { resolveToolConstraint } from '../util.ts';\nimport {\n isGcvLockFile,\n isGcvPropsFile,\n} from './extract/consistent-versions-plugin.ts';\nimport { isGradleBuildFile } from './utils.ts';\n\nexport function isGradleExecutionAllowed(command: string): boolean {\n const allowlist = GlobalConfig.get('allowedUnsafeExecutions');\n\n if (!allowlist.includes('gradleWrapper')) {\n logger.once.warn(\n { command },\n 'Gradle wrapper command was requested to run, but `gradleWrapper` is not permitted in the allowedUnsafeExecutions',\n );\n return false;\n }\n\n return true;\n}\n\n// .lockfile is gradle default lockfile, /versions.lock is gradle-consistent-versions plugin lockfile\nfunction isLockFile(fileName: string): boolean {\n return fileName.endsWith('.lockfile') || isGcvLockFile(fileName);\n}\n\nasync function getUpdatedLockfiles(\n oldLockFileContentMap: Record<string, string | null>,\n): Promise<UpdateArtifactsResult[]> {\n const res: UpdateArtifactsResult[] = [];\n\n const status = await getRepoStatus();\n\n for (const modifiedFile of status.modified) {\n if (\n isLockFile(modifiedFile) ||\n modifiedFile.endsWith('gradle/verification-metadata.xml')\n ) {\n const newContent = await readLocalFile(modifiedFile, 'utf8');\n if (oldLockFileContentMap[modifiedFile] !== newContent) {\n res.push({\n file: {\n type: 'addition',\n path: modifiedFile,\n contents: newContent,\n },\n });\n }\n }\n }\n\n return res;\n}\n\nasync function getSubProjectList(\n cmd: string,\n execOptions: ExecOptions,\n): Promise<string[]> {\n const subprojects = ['']; // = root project\n const subprojectsRegex = regEx(/^[ \\t]*subprojects: \\[(?<subprojects>.+)\\]/m);\n\n const gradleProperties = await exec(`${cmd} properties`, execOptions);\n const subprojectsMatch = gradleProperties.stdout.match(subprojectsRegex);\n if (subprojectsMatch?.groups?.subprojects) {\n const projectRegex = regEx(/project '(?<name>.+?)'/g);\n const matches = subprojectsMatch.groups.subprojects.matchAll(projectRegex);\n for (const match of matches) {\n if (match?.groups?.name) {\n subprojects.push(match.groups.name);\n }\n }\n }\n\n return subprojects;\n}\n\nasync function getGradleVersion(gradlewFile: string): Promise<string | null> {\n const propertiesFile = upath.join(\n upath.dirname(gradlewFile),\n 'gradle/wrapper/gradle-wrapper.properties',\n );\n const properties = await readLocalFile(propertiesFile, 'utf8');\n const extractResult = extractGradleVersion(properties ?? '');\n\n return extractResult ? extractResult.version : null;\n}\n\nasync function buildUpdateVerificationMetadataCmd(\n verificationMetadataFile: string | undefined,\n baseCmd: string,\n): Promise<string | null> {\n if (!verificationMetadataFile) {\n return null;\n }\n\n const verificationMetadata = await readLocalFile(verificationMetadataFile);\n const verifiesChecksums = verificationMetadata?.includes(\n '<verify-metadata>true</verify-metadata>',\n );\n const verifiesSignatures = verificationMetadata?.includes(\n '<verify-signatures>true</verify-signatures>',\n );\n\n const hashTypes = ['sha256', 'sha512'].filter((type) =>\n verificationMetadata?.includes(`<${type} `),\n );\n\n if (verifiesChecksums || hashTypes.length) {\n logger.debug(\n 'Dependency metadata verification enabled or checksums present - generating checksums',\n );\n }\n\n if ((verifiesChecksums || verifiesSignatures) && !hashTypes.length) {\n // fallback algorithm for pgp and in case a weak algorithm (md5, sha1) is used for checksums\n hashTypes.push('sha256');\n }\n\n if (verifiesSignatures) {\n logger.debug(\n 'Dependency signature verification enabled - generating PGP signatures',\n );\n hashTypes.push('pgp');\n }\n\n if (!hashTypes.length) {\n return null;\n }\n\n return `${baseCmd} --write-verification-metadata ${hashTypes.join(',')} dependencies`;\n}\n\nexport async function updateArtifacts({\n packageFileName,\n updatedDeps,\n newPackageFileContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.debug(`gradle.updateArtifacts(${packageFileName})`);\n\n const fileList = await scm.getFileList();\n const lockFiles = fileList.filter((file) => isLockFile(file));\n const verificationMetadataFile = fileList.find((fileName) =>\n fileName.endsWith('gradle/verification-metadata.xml'),\n );\n if (!lockFiles.length && !verificationMetadataFile) {\n logger.debug(\n 'No Gradle dependency lockfiles or verification metadata found - skipping update',\n );\n return null;\n }\n\n const gradlewName = gradleWrapperFileName();\n const gradlewFile = await findUpLocal(\n gradlewName,\n upath.dirname(packageFileName),\n );\n if (!gradlewFile) {\n logger.debug(\n 'Found Gradle dependency lockfiles but no gradlew - aborting update',\n );\n return null;\n }\n\n if (\n config.isLockFileMaintenance &&\n (!isGradleBuildFile(packageFileName) ||\n upath.dirname(packageFileName) !== upath.dirname(gradlewFile))\n ) {\n logger.trace(\n 'No build.gradle(.kts) file or not in root project - skipping lock file maintenance',\n );\n return null;\n }\n\n if (!isGradleExecutionAllowed(gradlewFile)) {\n logger.trace(\n 'Not allowed to execute gradle due to allowedUnsafeExecutions - aborting update',\n );\n return null;\n }\n\n logger.debug('Updating found Gradle dependency lockfiles');\n\n try {\n const oldLockFileContentMap = await getFiles(lockFiles);\n await prepareGradleCommand(gradlewFile);\n\n const baseCmd = `${gradlewName}${gradleJvmArg(getToolSettingsOptions(config.toolSettings))} --console=plain --dependency-verification lenient -q`;\n const execOptions: ExecOptions = {\n cwdFile: gradlewFile,\n docker: {},\n extraEnv,\n toolConstraints: [\n {\n toolName: 'java',\n constraint: await resolveToolConstraint(config, 'java', async () =>\n getJavaConstraint(await getGradleVersion(gradlewFile), gradlewFile),\n ),\n },\n ],\n };\n\n const cmds = [];\n if (lockFiles.length) {\n const subprojects = await getSubProjectList(baseCmd, execOptions);\n let lockfileCmd = `${baseCmd} ${subprojects\n .map((project) => `${project}:dependencies`)\n .map(quote)\n .join(' ')}`;\n\n if (\n config.isLockFileMaintenance === true ||\n !updatedDeps.length ||\n isGcvPropsFile(packageFileName)\n ) {\n lockfileCmd += ' --write-locks';\n } else {\n const updatedDepNames = updatedDeps\n .map(({ depName, packageName }) => packageName ?? depName)\n .filter(isNonEmptyStringAndNotWhitespace);\n\n lockfileCmd += ` --update-locks ${updatedDepNames\n .map(quote)\n .join(',')}`;\n }\n cmds.push(lockfileCmd);\n }\n\n const updateVerificationMetadataCmd =\n await buildUpdateVerificationMetadataCmd(\n verificationMetadataFile,\n baseCmd,\n );\n if (updateVerificationMetadataCmd) {\n cmds.push(updateVerificationMetadataCmd);\n }\n\n if (!cmds.length) {\n logger.debug('No lockfile or verification metadata update necessary');\n return null;\n }\n\n await writeLocalFile(packageFileName, newPackageFileContent);\n await exec(cmds, { ...execOptions, ignoreStdout: true });\n\n const res = await getUpdatedLockfiles(oldLockFileContentMap);\n logger.debug('Returning updated Gradle dependency lockfiles');\n\n return res.length > 0 ? res : null;\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n\n logger.debug({ err }, 'Error while updating Gradle dependency lockfiles');\n return [\n {\n artifactError: {\n fileName: packageFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmCA,SAAgB,yBAAyB,SAA0B;CAGjE,IAAI,CAFc,aAAa,IAAI,yBAEtB,CAAC,CAAC,SAAS,eAAe,GAAG;EACxC,OAAO,KAAK,KACV,EAAE,QAAQ,GACV,kHACF;EACA,OAAO;CACT;CAEA,OAAO;AACT;AAGA,SAAS,WAAW,UAA2B;CAC7C,OAAO,SAAS,SAAS,WAAW,KAAK,cAAc,QAAQ;AACjE;AAEA,eAAe,oBACb,uBACkC;CAClC,MAAM,MAA+B,CAAC;CAEtC,MAAM,SAAS,MAAM,cAAc;CAEnC,KAAK,MAAM,gBAAgB,OAAO,UAChC,IACE,WAAW,YAAY,KACvB,aAAa,SAAS,kCAAkC,GACxD;EACA,MAAM,aAAa,MAAM,cAAc,cAAc,MAAM;EAC3D,IAAI,sBAAsB,kBAAkB,YAC1C,IAAI,KAAK,EACP,MAAM;GACJ,MAAM;GACN,MAAM;G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G,QAAQ,cAAc,CAAC,CAC3C,IAAI,KAAK,CAAC,CACV,KAAK,GAAG;GAEX,IACE,OAAO,0BAA0B,QACjC,CAAC,YAAY,UACb,eAAe,eAAe,GAE9B,eAAe;QACV;IACL,MAAM,kBAAkB,YACrB,KAAK,EAAE,SAAS,kBAAkB,eAAe,OAAO,CAAC,CACzD,OAAO,gCAAgC;IAE1C,eAAe,mBAAmB,gBAC/B,IAAI,KAAK,CAAC,CACV,KAAK,GAAG;GACb;GACA,KAAK,KAAK,WAAW;EACvB;EAEA,MAAM,gCACJ,MAAM,mCACJ,0BACA,OACF;EACF,IAAI,+BACF,KAAK,KAAK,6BAA6B;EAGzC,IAAI,CAAC,KAAK,QAAQ;GAChB,OAAO,MAAM,uDAAuD;GACpE,OAAO;EACT;EAEA,MAAM,eAAe,iBAAiB,qBAAqB;EAC3D,MAAM,KAAK,MAAM;GAAE,GAAG;GAAa,cAAc;EAAK,CAAC;EAEvD,MAAM,MAAM,MAAM,oBAAoB,qBAAqB;EAC3D,OAAO,MAAM,+CAA+C;EAE5D,OAAO,IAAI,SAAS,IAAI,MAAM;CAChC,SAAS,KAAK;EACZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAGR,OAAO,MAAM,EAAE,IAAI,GAAG,kDAAkD;EACxE,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF"}
|
|
@@ -6,6 +6,7 @@ import { localPathExists, readLocalFile, writeLocalFile } from "../../../util/fs
|
|
|
6
6
|
import { Http } from "../../../util/http/index.js";
|
|
7
7
|
import { exec, getToolSettingsOptions, gradleJvmArg } from "../../../util/exec/index.js";
|
|
8
8
|
import { getRepoStatus } from "../../../util/git/index.js";
|
|
9
|
+
import { resolveToolConstraint } from "../util.js";
|
|
9
10
|
import { extraEnv, getJavaConstraint, gradleWrapperFileName, prepareGradleCommand } from "./utils.js";
|
|
10
11
|
import { isGradleExecutionAllowed, updateArtifacts as updateArtifacts$1 } from "../gradle/artifacts.js";
|
|
11
12
|
import "../gradle/index.js";
|
|
@@ -103,7 +104,7 @@ async function updateArtifacts({ packageFileName, newPackageFileContent, updated
|
|
|
103
104
|
extraEnv,
|
|
104
105
|
toolConstraints: [{
|
|
105
106
|
toolName: "java",
|
|
106
|
-
constraint: config
|
|
107
|
+
constraint: await resolveToolConstraint(config, "java", () => getJavaConstraint(config.currentValue, gradlewFile))
|
|
107
108
|
}]
|
|
108
109
|
};
|
|
109
110
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":["query","q","gradleUpdateArtifacts"],"sources":["../../../../lib/modules/manager/gradle-wrapper/artifacts.ts"],"sourcesContent":["import { lang, query as q } from '@renovatebot/good-enough-parser';\nimport { isTruthy } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport upath from 'upath';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport {\n exec,\n getToolSettingsOptions,\n gradleJvmArg,\n} from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n localPathExists,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport type { StatusResult } from '../../../util/git/types.ts';\nimport { Http } from '../../../util/http/index.ts';\nimport { newlineRegex, regEx } from '../../../util/regex.ts';\nimport { replaceAt } from '../../../util/string.ts';\nimport { isGradleExecutionAllowed } from '../gradle/artifacts.ts';\nimport { updateArtifacts as gradleUpdateArtifacts } from '../gradle/index.ts';\nimport type {\n UpdateArtifact,\n UpdateArtifactsConfig,\n UpdateArtifactsResult,\n} from '../types.ts';\nimport {\n extraEnv,\n getJavaConstraint,\n gradleWrapperFileName,\n prepareGradleCommand,\n} from './utils.ts';\n\nconst http = new Http('gradle-wrapper');\nconst groovy = lang.createLang('groovy');\n\ntype Ctx = string[];\n\nasync function addIfUpdated(\n status: StatusResult,\n fileProjectPath: string,\n): Promise<UpdateArtifactsResult | null> {\n if (status.modified.includes(fileProjectPath)) {\n return {\n file: {\n type: 'addition',\n path: fileProjectPath,\n contents: await readLocalFile(fileProjectPath),\n },\n };\n }\n return null;\n}\n\nfunction getDistributionUrl(newPackageFileContent: string): string | null {\n const distributionUrlLine = newPackageFileContent\n .split(newlineRegex)\n .find((line) => line.startsWith('distributionUrl='));\n if (distributionUrlLine) {\n return distributionUrlLine\n .replace('distributionUrl=', '')\n .replace('https\\\\:', 'https:');\n }\n return null;\n}\n\nasync function getDistributionChecksum(url: string): Promise<string> {\n const { body } = await http.getText(`${url}.sha256`);\n return body;\n}\n\nexport async function updateBuildFile(\n localGradleDir: string,\n wrapperProperties: Record<string, string | undefined | null>,\n): Promise<string> {\n let buildFileName = upath.join(localGradleDir, 'build.gradle');\n if (!(await localPathExists(buildFileName))) {\n buildFileName = upath.join(localGradleDir, 'build.gradle.kts');\n }\n\n const buildFileContent = await readLocalFile(buildFileName, 'utf8');\n if (!buildFileContent) {\n logger.debug('build.gradle or build.gradle.kts not found');\n return buildFileName;\n }\n\n let buildFileUpdated = buildFileContent;\n for (const [propertyName, newValue] of Object.entries(wrapperProperties)) {\n if (!newValue) {\n continue;\n }\n\n const query = q.tree({\n type: 'wrapped-tree',\n maxDepth: 1,\n search: q\n .sym<Ctx>(propertyName)\n .op('=')\n .str((ctx, { value, offset }) => {\n buildFileUpdated = replaceAt(\n buildFileUpdated,\n offset,\n value,\n newValue,\n );\n return ctx;\n }),\n });\n groovy.query(buildFileUpdated, query, []);\n }\n\n await writeLocalFile(buildFileName, buildFileUpdated);\n\n return buildFileName;\n}\n\nexport async function updateLockFiles(\n buildFileName: string,\n config: UpdateArtifactsConfig,\n): Promise<UpdateArtifactsResult[] | null> {\n const buildFileContent = await readLocalFile(buildFileName, 'utf8');\n if (!buildFileContent) {\n logger.debug('build.gradle or build.gradle.kts not found');\n return null;\n }\n\n return await gradleUpdateArtifacts({\n packageFileName: buildFileName,\n updatedDeps: [],\n newPackageFileContent: buildFileContent,\n config,\n });\n}\n\nexport async function updateArtifacts({\n packageFileName,\n newPackageFileContent,\n updatedDeps,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n try {\n logger.debug({ updatedDeps }, 'gradle-wrapper.updateArtifacts()');\n const localGradleDir = upath.join(upath.dirname(packageFileName), '../../');\n const gradlewFile = upath.join(localGradleDir, gradleWrapperFileName());\n\n let cmd = await prepareGradleCommand(gradlewFile);\n if (!cmd) {\n logger.info('No gradlew found - skipping Artifacts update');\n return null;\n }\n\n if (!isGradleExecutionAllowed(gradlewFile)) {\n logger.trace(\n 'Not allowed to execute gradle due to allowedUnsafeExecutions - aborting update',\n );\n\n return null;\n }\n\n // Limit the Gradle daemon Java heap memory size to prevent OOM errors\n // leading to Renovate kernel-OOMs and timeouts. See #39558\n cmd += gradleJvmArg(getToolSettingsOptions(config.toolSettings));\n cmd += ' :wrapper';\n\n let checksum: string | null = null;\n const distributionUrl = getDistributionUrl(newPackageFileContent);\n if (distributionUrl) {\n cmd += ` --gradle-distribution-url ${quote(distributionUrl)}`;\n if (newPackageFileContent.includes('distributionSha256Sum=')) {\n //update checksum in case of distributionSha256Sum in properties then run wrapper\n checksum = await getDistributionChecksum(distributionUrl);\n await writeLocalFile(\n packageFileName,\n newPackageFileContent.replace(\n regEx(/distributionSha256Sum=.*/),\n `distributionSha256Sum=${checksum}`,\n ),\n );\n cmd += ` --gradle-distribution-sha256-sum ${quote(checksum)}`;\n }\n } else {\n cmd += ` --gradle-version ${quote(config.newValue!)}`;\n }\n logger.debug(`Updating gradle wrapper: \"${cmd}\"`);\n const execOptions: ExecOptions = {\n cwdFile: gradlewFile,\n docker: {},\n extraEnv,\n toolConstraints: [\n {\n toolName: 'java',\n constraint:\n config.constraints?.java ??\n (await getJavaConstraint(config.currentValue, gradlewFile)),\n },\n ],\n };\n try {\n await exec(cmd, execOptions);\n } catch (err) {\n // istanbul ignore if\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.warn(\n { err },\n 'Error executing gradle wrapper update command. This may not necessarily be a blocker to the update, so please verify with the gradle wrapper output logs.',\n );\n }\n\n const buildFileName = await updateBuildFile(localGradleDir, {\n gradleVersion: config.newValue,\n distributionSha256Sum: checksum,\n distributionUrl,\n });\n const lockFiles = await updateLockFiles(buildFileName, config);\n\n const status = await getRepoStatus();\n const artifactFileNames = [\n packageFileName,\n buildFileName,\n ...['gradle/wrapper/gradle-wrapper.jar', 'gradlew', 'gradlew.bat'].map(\n (filename) => upath.join(localGradleDir, filename),\n ),\n ];\n const updateArtifactsResult = (\n await Promise.all(\n artifactFileNames.map((fileProjectPath) =>\n addIfUpdated(status, fileProjectPath),\n ),\n )\n ).filter(isTruthy);\n if (lockFiles) {\n updateArtifactsResult.push(...lockFiles);\n }\n\n logger.debug(\n { files: updateArtifactsResult.map((r) => r.file?.path) },\n `Returning updated gradle-wrapper files`,\n );\n return updateArtifactsResult;\n } catch (err) {\n logger.debug({ err }, 'Error setting new Gradle Wrapper release value');\n return [\n {\n artifactError: {\n fileName: packageFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoCA,MAAM,OAAO,IAAI,KAAK,gBAAgB;AACtC,MAAM,SAAS,KAAK,WAAW,QAAQ;AAIvC,eAAe,aACb,QACA,iBACuC;CACvC,IAAI,OAAO,SAAS,SAAS,eAAe,GAC1C,OAAO,EACL,MAAM;EACJ,MAAM;EACN,MAAM;EACN,UAAU,MAAM,cAAc,eAAe;CAC/C,EACF;CAEF,OAAO;AACT;AAEA,SAAS,mBAAmB,uBAA8C;CACxE,MAAM,sBAAsB,sBACzB,MAAM,YAAY,CAAC,CACnB,MAAM,SAAS,KAAK,WAAW,kBAAkB,CAAC;CACrD,IAAI,qBACF,OAAO,oBACJ,QAAQ,oBAAoB,EAAE,CAAC,CAC/B,QAAQ,YAAY,QAAQ;CAEjC,OAAO;AACT;AAEA,eAAe,wBAAwB,KAA8B;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gBAAgB,QAAQ,CACnD;EACF;EACA,MAAM,yBACJ,MAAM,QAAQ,IACZ,kBAAkB,KAAK,oBACrB,aAAa,QAAQ,eAAe,CACtC,CACF,EAAA,CACA,OAAO,QAAQ;EACjB,IAAI,WACF,sBAAsB,KAAK,GAAG,SAAS;EAGzC,OAAO,MACL,EAAE,OAAO,sBAAsB,KAAK,MAAM,EAAE,MAAM,IAAI,EAAE,GACxD,wCACF;EACA,OAAO;CACT,SAAS,KAAK;EACZ,OAAO,MAAM,EAAE,IAAI,GAAG,gDAAgD;EACtE,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":["query","q","gradleUpdateArtifacts"],"sources":["../../../../lib/modules/manager/gradle-wrapper/artifacts.ts"],"sourcesContent":["import { lang, query as q } from '@renovatebot/good-enough-parser';\nimport { isTruthy } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport upath from 'upath';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport {\n exec,\n getToolSettingsOptions,\n gradleJvmArg,\n} from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n localPathExists,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport type { StatusResult } from '../../../util/git/types.ts';\nimport { Http } from '../../../util/http/index.ts';\nimport { newlineRegex, regEx } from '../../../util/regex.ts';\nimport { replaceAt } from '../../../util/string.ts';\nimport { isGradleExecutionAllowed } from '../gradle/artifacts.ts';\nimport { updateArtifacts as gradleUpdateArtifacts } from '../gradle/index.ts';\nimport type {\n UpdateArtifact,\n UpdateArtifactsConfig,\n UpdateArtifactsResult,\n} from '../types.ts';\nimport { resolveToolConstraint } from '../util.ts';\nimport {\n extraEnv,\n getJavaConstraint,\n gradleWrapperFileName,\n prepareGradleCommand,\n} from './utils.ts';\n\nconst http = new Http('gradle-wrapper');\nconst groovy = lang.createLang('groovy');\n\ntype Ctx = string[];\n\nasync function addIfUpdated(\n status: StatusResult,\n fileProjectPath: string,\n): Promise<UpdateArtifactsResult | null> {\n if (status.modified.includes(fileProjectPath)) {\n return {\n file: {\n type: 'addition',\n path: fileProjectPath,\n contents: await readLocalFile(fileProjectPath),\n },\n };\n }\n return null;\n}\n\nfunction getDistributionUrl(newPackageFileContent: string): string | null {\n const distributionUrlLine = newPackageFileContent\n .split(newlineRegex)\n .find((line) => line.startsWith('distributionUrl='));\n if (distributionUrlLine) {\n return distributionUrlLine\n .replace('distributionUrl=', '')\n .replace('https\\\\:', 'https:');\n }\n return null;\n}\n\nasync function getDistributionChecksum(url: string): Promise<string> {\n const { body } = await http.getText(`${url}.sha256`);\n return body;\n}\n\nexport async function updateBuildFile(\n localGradleDir: string,\n wrapperProperties: Record<string, string | undefined | null>,\n): Promise<string> {\n let buildFileName = upath.join(localGradleDir, 'build.gradle');\n if (!(await localPathExists(buildFileName))) {\n buildFileName = upath.join(localGradleDir, 'build.gradle.kts');\n }\n\n const buildFileContent = await readLocalFile(buildFileName, 'utf8');\n if (!buildFileContent) {\n logger.debug('build.gradle or build.gradle.kts not found');\n return buildFileName;\n }\n\n let buildFileUpdated = buildFileContent;\n for (const [propertyName, newValue] of Object.entries(wrapperProperties)) {\n if (!newValue) {\n continue;\n }\n\n const query = q.tree({\n type: 'wrapped-tree',\n maxDepth: 1,\n search: q\n .sym<Ctx>(propertyName)\n .op('=')\n .str((ctx, { value, offset }) => {\n buildFileUpdated = replaceAt(\n buildFileUpdated,\n offset,\n value,\n newValue,\n );\n return ctx;\n }),\n });\n groovy.query(buildFileUpdated, query, []);\n }\n\n await writeLocalFile(buildFileName, buildFileUpdated);\n\n return buildFileName;\n}\n\nexport async function updateLockFiles(\n buildFileName: string,\n config: UpdateArtifactsConfig,\n): Promise<UpdateArtifactsResult[] | null> {\n const buildFileContent = await readLocalFile(buildFileName, 'utf8');\n if (!buildFileContent) {\n logger.debug('build.gradle or build.gradle.kts not found');\n return null;\n }\n\n return await gradleUpdateArtifacts({\n packageFileName: buildFileName,\n updatedDeps: [],\n newPackageFileContent: buildFileContent,\n config,\n });\n}\n\nexport async function updateArtifacts({\n packageFileName,\n newPackageFileContent,\n updatedDeps,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n try {\n logger.debug({ updatedDeps }, 'gradle-wrapper.updateArtifacts()');\n const localGradleDir = upath.join(upath.dirname(packageFileName), '../../');\n const gradlewFile = upath.join(localGradleDir, gradleWrapperFileName());\n\n let cmd = await prepareGradleCommand(gradlewFile);\n if (!cmd) {\n logger.info('No gradlew found - skipping Artifacts update');\n return null;\n }\n\n if (!isGradleExecutionAllowed(gradlewFile)) {\n logger.trace(\n 'Not allowed to execute gradle due to allowedUnsafeExecutions - aborting update',\n );\n\n return null;\n }\n\n // Limit the Gradle daemon Java heap memory size to prevent OOM errors\n // leading to Renovate kernel-OOMs and timeouts. See #39558\n cmd += gradleJvmArg(getToolSettingsOptions(config.toolSettings));\n cmd += ' :wrapper';\n\n let checksum: string | null = null;\n const distributionUrl = getDistributionUrl(newPackageFileContent);\n if (distributionUrl) {\n cmd += ` --gradle-distribution-url ${quote(distributionUrl)}`;\n if (newPackageFileContent.includes('distributionSha256Sum=')) {\n //update checksum in case of distributionSha256Sum in properties then run wrapper\n checksum = await getDistributionChecksum(distributionUrl);\n await writeLocalFile(\n packageFileName,\n newPackageFileContent.replace(\n regEx(/distributionSha256Sum=.*/),\n `distributionSha256Sum=${checksum}`,\n ),\n );\n cmd += ` --gradle-distribution-sha256-sum ${quote(checksum)}`;\n }\n } else {\n cmd += ` --gradle-version ${quote(config.newValue!)}`;\n }\n logger.debug(`Updating gradle wrapper: \"${cmd}\"`);\n const execOptions: ExecOptions = {\n cwdFile: gradlewFile,\n docker: {},\n extraEnv,\n toolConstraints: [\n {\n toolName: 'java',\n constraint: await resolveToolConstraint(config, 'java', () =>\n getJavaConstraint(config.currentValue, gradlewFile),\n ),\n },\n ],\n };\n try {\n await exec(cmd, execOptions);\n } catch (err) {\n // istanbul ignore if\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.warn(\n { err },\n 'Error executing gradle wrapper update command. This may not necessarily be a blocker to the update, so please verify with the gradle wrapper output logs.',\n );\n }\n\n const buildFileName = await updateBuildFile(localGradleDir, {\n gradleVersion: config.newValue,\n distributionSha256Sum: checksum,\n distributionUrl,\n });\n const lockFiles = await updateLockFiles(buildFileName, config);\n\n const status = await getRepoStatus();\n const artifactFileNames = [\n packageFileName,\n buildFileName,\n ...['gradle/wrapper/gradle-wrapper.jar', 'gradlew', 'gradlew.bat'].map(\n (filename) => upath.join(localGradleDir, filename),\n ),\n ];\n const updateArtifactsResult = (\n await Promise.all(\n artifactFileNames.map((fileProjectPath) =>\n addIfUpdated(status, fileProjectPath),\n ),\n )\n ).filter(isTruthy);\n if (lockFiles) {\n updateArtifactsResult.push(...lockFiles);\n }\n\n logger.debug(\n { files: updateArtifactsResult.map((r) => r.file?.path) },\n `Returning updated gradle-wrapper files`,\n );\n return updateArtifactsResult;\n } catch (err) {\n logger.debug({ err }, 'Error setting new Gradle Wrapper release value');\n return [\n {\n artifactError: {\n fileName: packageFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,MAAM,OAAO,IAAI,KAAK,gBAAgB;AACtC,MAAM,SAAS,KAAK,WAAW,QAAQ;AAIvC,eAAe,aACb,QACA,iBACuC;CACvC,IAAI,OAAO,SAAS,SAAS,eAAe,GAC1C,OAAO,EACL,MAAM;EACJ,MAAM;EACN,MAAM;EACN,UAAU,MAAM,cAAc,eAAe;CAC/C,EACF;CAEF,OAAO;AACT;AAEA,SAAS,mBAAmB,uBAA8C;CACxE,MAAM,sBAAsB,sBACzB,MAAM,YAAY,CAAC,CACnB,MAAM,SAAS,KAAK,WAAW,kBAAkB,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,eAAe,MAAM;EAE7D,MAAM,SAAS,MAAM,cAAc;EACnC,MAAM,oBAAoB;GACxB;GACA;GACA,GAAG;IAAC;IAAqC;IAAW;GAAa,CAAC,CAAC,KAChE,aAAa,MAAM,KAAK,gBAAgB,QAAQ,CACnD;EACF;EACA,MAAM,yBACJ,MAAM,QAAQ,IACZ,kBAAkB,KAAK,oBACrB,aAAa,QAAQ,eAAe,CACtC,CACF,EAAA,CACA,OAAO,QAAQ;EACjB,IAAI,WACF,sBAAsB,KAAK,GAAG,SAAS;EAGzC,OAAO,MACL,EAAE,OAAO,sBAAsB,KAAK,MAAM,EAAE,MAAM,IAAI,EAAE,GACxD,wCACF;EACA,OAAO;CACT,SAAS,KAAK;EACZ,OAAO,MAAM,EAAE,IAAI,GAAG,gDAAgD;EACtE,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF"}
|
|
@@ -7,6 +7,7 @@ import { getSiblingFileName, readLocalFile, writeLocalFile } from "../../../util
|
|
|
7
7
|
import { Result } from "../../../util/result.js";
|
|
8
8
|
import { exec } from "../../../util/exec/index.js";
|
|
9
9
|
import { getFile } from "../../../util/git/index.js";
|
|
10
|
+
import { resolveToolConstraint } from "../util.js";
|
|
10
11
|
import { generateHelmEnvs } from "../helmv3/common.js";
|
|
11
12
|
import { Doc, LockVersion } from "./schema.js";
|
|
12
13
|
import { generateRegistryLoginCmd, isOCIRegistry } from "./utils.js";
|
|
@@ -30,14 +31,14 @@ async function updateArtifacts({ packageFileName, updatedDeps, newPackageFileCon
|
|
|
30
31
|
await writeLocalFile(packageFileName, newPackageFileContent);
|
|
31
32
|
const toolConstraints = [{
|
|
32
33
|
toolName: "helm",
|
|
33
|
-
constraint: config
|
|
34
|
+
constraint: await resolveToolConstraint(config, "helm")
|
|
34
35
|
}, {
|
|
35
36
|
toolName: "helmfile",
|
|
36
|
-
constraint: config
|
|
37
|
+
constraint: await resolveToolConstraint(config, "helmfile", () => Result.parse(existingLockFileContent, LockVersion).unwrapOrNull())
|
|
37
38
|
}];
|
|
38
39
|
if (updatedDeps.some((dep) => dep.managerData?.needKustomize)) toolConstraints.push({
|
|
39
40
|
toolName: "kustomize",
|
|
40
|
-
constraint: config
|
|
41
|
+
constraint: await resolveToolConstraint(config, "kustomize")
|
|
41
42
|
});
|
|
42
43
|
const cmd = [];
|
|
43
44
|
const docs = parseYaml(newPackageFileContent, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":[],"sources":["../../../../lib/modules/manager/helmfile/artifacts.ts"],"sourcesContent":["import { isFalsy } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ToolConstraint } from '../../../util/exec/types.ts';\nimport {\n getSiblingFileName,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { getFile } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { Result } from '../../../util/result.ts';\nimport { parseYaml } from '../../../util/yaml.ts';\nimport { generateHelmEnvs } from '../helmv3/common.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { Doc, LockVersion } from './schema.ts';\nimport { generateRegistryLoginCmd, isOCIRegistry } from './utils.ts';\n\nexport async function updateArtifacts({\n packageFileName,\n updatedDeps,\n newPackageFileContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.trace(`helmfile.updateArtifacts(${packageFileName})`);\n\n const { isLockFileMaintenance } = config;\n if (\n !isLockFileMaintenance &&\n (updatedDeps === undefined || updatedDeps.length < 1)\n ) {\n logger.debug('No updated helmfile deps - returning null');\n return null;\n }\n\n const lockFileName = getSiblingFileName(packageFileName, 'helmfile.lock');\n const existingLockFileContent = await getFile(lockFileName);\n\n if (isFalsy(existingLockFileContent)) {\n logger.debug('No helmfile.lock found');\n return null;\n }\n\n try {\n await writeLocalFile(packageFileName, newPackageFileContent);\n\n const toolConstraints: ToolConstraint[] = [\n {\n toolName: 'helm',\n constraint: config
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":[],"sources":["../../../../lib/modules/manager/helmfile/artifacts.ts"],"sourcesContent":["import { isFalsy } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ToolConstraint } from '../../../util/exec/types.ts';\nimport {\n getSiblingFileName,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { getFile } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { Result } from '../../../util/result.ts';\nimport { parseYaml } from '../../../util/yaml.ts';\nimport { generateHelmEnvs } from '../helmv3/common.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { resolveToolConstraint } from '../util.ts';\nimport { Doc, LockVersion } from './schema.ts';\nimport { generateRegistryLoginCmd, isOCIRegistry } from './utils.ts';\n\nexport async function updateArtifacts({\n packageFileName,\n updatedDeps,\n newPackageFileContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.trace(`helmfile.updateArtifacts(${packageFileName})`);\n\n const { isLockFileMaintenance } = config;\n if (\n !isLockFileMaintenance &&\n (updatedDeps === undefined || updatedDeps.length < 1)\n ) {\n logger.debug('No updated helmfile deps - returning null');\n return null;\n }\n\n const lockFileName = getSiblingFileName(packageFileName, 'helmfile.lock');\n const existingLockFileContent = await getFile(lockFileName);\n\n if (isFalsy(existingLockFileContent)) {\n logger.debug('No helmfile.lock found');\n return null;\n }\n\n try {\n await writeLocalFile(packageFileName, newPackageFileContent);\n\n const toolConstraints: ToolConstraint[] = [\n {\n toolName: 'helm',\n constraint: await resolveToolConstraint(config, 'helm'),\n },\n {\n toolName: 'helmfile',\n constraint: await resolveToolConstraint(config, 'helmfile', () =>\n Result.parse(existingLockFileContent, LockVersion).unwrapOrNull(),\n ),\n },\n ];\n const needKustomize = updatedDeps.some(\n (dep) => dep.managerData?.needKustomize,\n );\n if (needKustomize) {\n toolConstraints.push({\n toolName: 'kustomize',\n constraint: await resolveToolConstraint(config, 'kustomize'),\n });\n }\n\n const cmd: string[] = [];\n const docs = parseYaml(newPackageFileContent, {\n removeTemplates: true,\n customSchema: Doc,\n failureBehaviour: 'filter',\n });\n\n for (const doc of docs) {\n for (const value of coerceArray(doc.repositories).filter(isOCIRegistry)) {\n const loginCmd = await generateRegistryLoginCmd(\n value.name,\n `https://${value.url}`,\n // this extracts the hostname from url like format ghcr.ip/helm-charts\n value.url.replace(regEx(/\\/.*/), ''),\n );\n\n if (loginCmd) {\n cmd.push(loginCmd);\n }\n }\n }\n\n cmd.push(`helmfile deps -f ${quote(packageFileName)}`);\n await exec(cmd, {\n docker: {},\n extraEnv: generateHelmEnvs(),\n toolConstraints,\n });\n\n const newHelmLockContent = await readLocalFile(lockFileName, 'utf8');\n if (existingLockFileContent === newHelmLockContent) {\n logger.debug('helmfile.lock is unchanged');\n return null;\n }\n\n return [\n {\n file: {\n type: 'addition',\n path: lockFileName,\n contents: newHelmLockContent,\n },\n },\n ];\n } catch (err) {\n // istanbul ignore if\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update Helmfile lock file');\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,eAAsB,gBAAgB,EACpC,iBACA,aACA,uBACA,UAC0D;CAC1D,OAAO,MAAM,4BAA4B,gBAAgB,EAAE;CAE3D,MAAM,EAAE,0BAA0B;CAClC,IACE,CAAC,0BACA,gBAAgB,KAAA,KAAa,YAAY,SAAS,IACnD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GACN,UAAU;EACZ,EACF,CACF;CACF,SAAS,KAAK;;EAEZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAER,OAAO,MAAM,EAAE,IAAI,GAAG,qCAAqC;EAC3D,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF"}
|
|
@@ -9,6 +9,7 @@ import { exec } from "../../../util/exec/index.js";
|
|
|
9
9
|
import { getRepoStatus } from "../../../util/git/index.js";
|
|
10
10
|
import { DockerDatasource } from "../../datasource/docker/index.js";
|
|
11
11
|
import { HelmDatasource } from "../../datasource/helm/index.js";
|
|
12
|
+
import { resolveToolConstraint } from "../util.js";
|
|
12
13
|
import { isOCIRegistry, removeOCIPrefix } from "./oci.js";
|
|
13
14
|
import { generateHelmEnvs, generateLoginCmd } from "./common.js";
|
|
14
15
|
import { aliasRecordToRepositories, getRepositories, isFileInDir } from "./utils.js";
|
|
@@ -77,7 +78,7 @@ async function updateArtifacts({ packageFileName, updatedDeps, newPackageFileCon
|
|
|
77
78
|
logger.debug("Updating Helm artifacts");
|
|
78
79
|
const helmToolConstraint = {
|
|
79
80
|
toolName: "helm",
|
|
80
|
-
constraint: config
|
|
81
|
+
constraint: await resolveToolConstraint(config, "helm")
|
|
81
82
|
};
|
|
82
83
|
await helmCommands({
|
|
83
84
|
docker: {},
|