renovate 44.17.4 → 44.18.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/config/options/index.js +1 -1
- package/dist/config/options/index.js.map +1 -1
- package/dist/global-config-option-defaults.generated.js +1 -1
- package/dist/global-config-option-defaults.generated.js.map +1 -1
- package/dist/modules/datasource/git-refs/base.js +1 -3
- package/dist/modules/datasource/git-refs/base.js.map +1 -1
- package/dist/modules/manager/cargo/artifacts.js +6 -10
- package/dist/modules/manager/cargo/artifacts.js.map +1 -1
- package/dist/modules/manager/conan/artifacts.js +4 -6
- package/dist/modules/manager/conan/artifacts.js.map +1 -1
- package/dist/modules/manager/copier/artifacts.js +3 -4
- package/dist/modules/manager/copier/artifacts.js.map +1 -1
- package/dist/modules/manager/fingerprint.generated.js +3 -3
- package/dist/modules/manager/fingerprint.generated.js.map +1 -1
- package/dist/modules/manager/git-submodules/update.js +3 -4
- package/dist/modules/manager/git-submodules/update.js.map +1 -1
- package/dist/modules/manager/gomod/artifacts.js +4 -5
- package/dist/modules/manager/gomod/artifacts.js.map +1 -1
- package/dist/modules/manager/hermit/artifacts.js +8 -6
- package/dist/modules/manager/hermit/artifacts.js.map +1 -1
- package/dist/modules/manager/pep621/processors/pdm.js +10 -13
- package/dist/modules/manager/pep621/processors/pdm.js.map +1 -1
- package/dist/modules/manager/pep621/processors/uv.js +3 -4
- package/dist/modules/manager/pep621/processors/uv.js.map +1 -1
- package/dist/modules/manager/poetry/artifacts.js +3 -4
- package/dist/modules/manager/poetry/artifacts.js.map +1 -1
- package/dist/modules/manager/vendir/artifacts.js +3 -4
- package/dist/modules/manager/vendir/artifacts.js.map +1 -1
- package/dist/util/exec/index.js +10 -5
- package/dist/util/exec/index.js.map +1 -1
- package/dist/util/exec/utils.js.map +1 -1
- package/dist/util/git/auth.js +16 -18
- package/dist/util/git/auth.js.map +1 -1
- package/dist/util/git/exec.js +34 -0
- package/dist/util/git/exec.js.map +1 -0
- package/dist/util/git/index.d.ts +6 -2
- package/dist/util/git/index.js +9 -7
- package/dist/util/git/index.js.map +1 -1
- package/dist/workers/repository/update/branch/execute-post-upgrade-commands.js +4 -5
- package/dist/workers/repository/update/branch/execute-post-upgrade-commands.js.map +1 -1
- package/package.json +1 -1
- package/renovate-schema.json +2 -2
|
@@ -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 { exec } from '../../../util/exec/index.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 { getGitEnvironmentVariables } from '../../../util/git/auth.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';\n\nconst { major, valid } = semver;\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 /(\\r?\\n)(replace\\s+[^\\s]+\\s+=>\\s+\\.\\.\\/.*)/g,\n );\n\n // $1 will be matched with the (\\r?n) group\n // $2 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 = '$1// renovate-replace $2';\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(/(\\r?\\n)/g, '$1// renovate-replace ');\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 ...getGitEnvironmentVariables(['go']),\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 const isGoModTidyRequired =\n !mustSkipGoModTidy &&\n (config.postUpdateOptions?.includes('gomodTidy') === true ||\n config.postUpdateOptions?.includes('gomodTidy1.17') === true ||\n config.postUpdateOptions?.includes('gomodTidyE') === true ||\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 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 exec(execCommands, execOptions);\n\n const status = await getRepoStatus();\n if (\n !status.modified.includes(sumFileName) &&\n !status.modified.includes(goModFileName) &&\n !status.modified.includes(goWorkSumFileName)\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 // 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 );\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;AAEzB,SAAS,wBACP,aACA,EAAE,eACQ;CAEV,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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AO,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 { getExtraDepsNotice } from './artifacts-extra.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 /(\\r?\\n)(replace\\s+[^\\s]+\\s+=>\\s+\\.\\.\\/.*)/g,\n );\n\n // $1 will be matched with the (\\r?n) group\n // $2 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 = '$1// renovate-replace $2';\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(/(\\r?\\n)/g, '$1// renovate-replace ');\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 const isGoModTidyRequired =\n !mustSkipGoModTidy &&\n (config.postUpdateOptions?.includes('gomodTidy') === true ||\n config.postUpdateOptions?.includes('gomodTidy1.17') === true ||\n config.postUpdateOptions?.includes('gomodTidyE') === true ||\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 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 if (\n !status.modified.includes(sumFileName) &&\n !status.modified.includes(goModFileName) &&\n !status.modified.includes(goWorkSumFileName)\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 // 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 );\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":";;;;;;;;;;;;;;;;;AA8BA,MAAM,EAAE,OAAA,SAAO,OAAA,YAAU;AACzB,MAAM,UAAU,mBAAmB,CAAC,IAAI,CAAC;AAEzC,SAAS,wBACP,aACA,EAAE,eACQ;CAEV,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,OAA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AAmB;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,12 +1,13 @@
|
|
|
1
|
+
import { ExecError } from "../../../util/exec/exec-error.js";
|
|
1
2
|
import { logger } from "../../../logger/index.js";
|
|
2
3
|
import { localPathIsSymbolicLink, readLocalSymlink } from "../../../util/fs/index.js";
|
|
3
4
|
import { map } from "../../../util/promises.js";
|
|
4
|
-
import { getGitEnvironmentVariables } from "../../../util/git/auth.js";
|
|
5
|
-
import { exec } from "../../../util/exec/index.js";
|
|
6
5
|
import { getRepoStatus } from "../../../util/git/index.js";
|
|
6
|
+
import { withGitEnvironment } from "../../../util/git/exec.js";
|
|
7
7
|
import { quote } from "shlex";
|
|
8
8
|
import upath from "upath";
|
|
9
9
|
//#region lib/modules/manager/hermit/artifacts.ts
|
|
10
|
+
const gitExec = withGitEnvironment(["hermit"]);
|
|
10
11
|
/**
|
|
11
12
|
* updateArtifacts runs hermit install for each updated dependencies
|
|
12
13
|
*/
|
|
@@ -133,18 +134,18 @@ async function updateHermitPackage(update) {
|
|
|
133
134
|
}
|
|
134
135
|
const execOptions = {
|
|
135
136
|
docker: {},
|
|
136
|
-
cwdFile: update.packageFileName
|
|
137
|
-
extraEnv: getGitEnvironmentVariables(["hermit"])
|
|
137
|
+
cwdFile: update.packageFileName
|
|
138
138
|
};
|
|
139
139
|
const fromPackages = from.map(quote).join(" ");
|
|
140
140
|
if (toUninstall.length > 0) {
|
|
141
141
|
const packagesToUninstall = toUninstall.map(quote).join(" ");
|
|
142
142
|
const uninstallCommands = `./hermit uninstall ${packagesToUninstall}`;
|
|
143
143
|
try {
|
|
144
|
-
const result = await
|
|
144
|
+
const result = await gitExec(uninstallCommands, execOptions);
|
|
145
145
|
logger.trace({ stdout: result.stdout }, `hermit uninstall command stdout`);
|
|
146
146
|
} catch (e) {
|
|
147
147
|
logger.warn({ err: e }, `error uninstall hermit package for replacement`);
|
|
148
|
+
if (!(e instanceof ExecError)) throw e;
|
|
148
149
|
throw new UpdateHermitError(fromPackages, packagesToUninstall, e.stderr, e.stdout);
|
|
149
150
|
}
|
|
150
151
|
}
|
|
@@ -155,10 +156,11 @@ async function updateHermitPackage(update) {
|
|
|
155
156
|
packagesToInstall
|
|
156
157
|
}, `performing updates`);
|
|
157
158
|
try {
|
|
158
|
-
const result = await
|
|
159
|
+
const result = await gitExec(execCommands, execOptions);
|
|
159
160
|
logger.trace({ stdout: result.stdout }, `hermit command stdout`);
|
|
160
161
|
} catch (e) {
|
|
161
162
|
logger.warn({ err: e }, `error updating hermit package`);
|
|
163
|
+
if (!(e instanceof ExecError)) throw e;
|
|
162
164
|
throw new UpdateHermitError(fromPackages, packagesToInstall, e.stderr, e.stdout);
|
|
163
165
|
}
|
|
164
166
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":["p.map"],"sources":["../../../../lib/modules/manager/hermit/artifacts.ts"],"sourcesContent":["import { quote } from 'shlex';\nimport upath from 'upath';\nimport { logger } from '../../../logger/index.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n localPathIsSymbolicLink,\n readLocalSymlink,\n} from '../../../util/fs/index.ts';\nimport { getGitEnvironmentVariables } from '../../../util/git/auth.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport * as p from '../../../util/promises.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport type { ReadContentResult } from './types.ts';\n\n/**\n * updateArtifacts runs hermit install for each updated dependencies\n */\nexport async function updateArtifacts(\n update: UpdateArtifact,\n): Promise<UpdateArtifactsResult[] | null> {\n const { packageFileName } = update;\n try {\n await updateHermitPackage(update);\n } catch (err) {\n logger.debug({ err }, `error updating hermit packages.`);\n if (err instanceof UpdateHermitError) {\n return [\n {\n artifactError: {\n fileName: `from: ${err.from}, to: ${err.to}`,\n stderr: err.stderr,\n },\n },\n ];\n }\n return [\n {\n artifactError: {\n stderr: err instanceof Error ? err.message : String(err),\n },\n },\n ];\n }\n\n logger.debug(`scanning the changes after update`);\n\n let updateResult: UpdateArtifactsResult[] | null = null;\n\n try {\n updateResult = await getUpdateResult(packageFileName);\n logger.debug({ updateResult }, `update result for hermit`);\n } catch (err) {\n logger.debug({ err }, 'Error getting hermet update results');\n return [\n {\n artifactError: {\n stderr: err.message,\n },\n },\n ];\n }\n\n return updateResult;\n}\n\n/**\n * getContent returns the content of either link or a normal file\n */\nasync function getContent(file: string): Promise<ReadContentResult> {\n let contents: string | null = '';\n const isSymlink = await localPathIsSymbolicLink(file);\n\n if (isSymlink) {\n contents = await readLocalSymlink(file);\n }\n\n if (contents === null) {\n throw new Error(`error getting content for ${file}`);\n }\n\n return {\n isSymlink,\n contents,\n };\n}\n\n/**\n * getAddResult returns the UpdateArtifactsResult for the added files\n */\nfunction getAddResult(\n path: string,\n contentRes: ReadContentResult,\n): UpdateArtifactsResult {\n return {\n file: {\n type: 'addition',\n path,\n contents: contentRes.contents,\n isSymlink: contentRes.isSymlink,\n isExecutable: contentRes.isExecutable,\n },\n };\n}\n\n/**\n * getDeleteResult returns the UpdateArtifactsResult for deleted files\n */\nfunction getDeleteResult(path: string): UpdateArtifactsResult {\n return {\n file: {\n type: 'deletion',\n path,\n },\n };\n}\n\n/**\n * getUpdateResult will return the update result after `hermit install`\n * has been performed for all packages\n */\nasync function getUpdateResult(\n packageFileName: string,\n): Promise<UpdateArtifactsResult[]> {\n const hermitFolder = `${upath.dirname(packageFileName)}/`;\n const hermitChanges = await getRepoStatus(hermitFolder);\n logger.debug(\n { hermitChanges, hermitFolder },\n `hermit changes after package update`,\n );\n\n // handle added files\n const added = await p.map(\n [...hermitChanges.created, ...hermitChanges.not_added],\n async (path: string): Promise<UpdateArtifactsResult> => {\n const contents = await getContent(path);\n\n return getAddResult(path, contents);\n },\n );\n\n const deleted = hermitChanges.deleted.map(getDeleteResult);\n\n const modified = await p.map(\n hermitChanges.modified,\n async (path: string): Promise<UpdateArtifactsResult[]> => {\n const contents = await getContent(path);\n return [\n getDeleteResult(path), // delete existing link\n getAddResult(path, contents), // add a new link\n ];\n },\n );\n\n const renamed = await p.map(\n hermitChanges.renamed,\n async (renamed): Promise<UpdateArtifactsResult[]> => {\n const from = renamed.from;\n const to = renamed.to;\n const toContents = await getContent(to);\n\n return [getDeleteResult(from), getAddResult(to, toContents)];\n },\n );\n\n return [\n // rename will need to go first, because\n // it needs to create the new link for the new version\n // for the modified links to use\n ...renamed.flat(),\n ...modified.flat(),\n ...added,\n ...deleted,\n ];\n}\n\n/**\n * getHermitPackage returns the hermit package for running the hermit install\n */\nfunction getHermitPackage(name: string, version: string): string {\n return `${name}-${version}`;\n}\n\n/**\n * updateHermitPackage runs hermit install for the given package\n */\nasync function updateHermitPackage(update: UpdateArtifact): Promise<void> {\n logger.trace({ update }, `hermit.updateHermitPackage()`);\n\n const toInstall = [];\n const from = [];\n // storing the old package for replacement\n const toUninstall = [];\n\n for (const pkg of update.updatedDeps) {\n if (!pkg.depName || !pkg.currentVersion || !pkg.newValue) {\n logger.debug(\n {\n depName: pkg.depName,\n currentVersion: pkg.currentVersion,\n newValue: pkg.newValue,\n },\n 'missing package update information',\n );\n\n throw new UpdateHermitError(\n getHermitPackage(pkg.depName ?? '', pkg.currentVersion ?? ''),\n getHermitPackage(pkg.depName ?? '', pkg.newValue ?? ''),\n 'invalid package to update',\n );\n }\n\n const depName = pkg.depName;\n const newName = pkg.newName;\n const currentVersion = pkg.currentVersion;\n const newValue = pkg.newValue;\n const fromPackage = getHermitPackage(depName, currentVersion);\n // newName will be available for replacement\n const toPackage = getHermitPackage(newName ?? depName, newValue);\n toInstall.push(toPackage);\n from.push(fromPackage);\n // skips uninstall for version only replacement\n if (pkg.updateType === 'replacement' && newName !== depName) {\n toUninstall.push(depName);\n }\n }\n\n const execOptions: ExecOptions = {\n docker: {},\n cwdFile: update.packageFileName,\n extraEnv: getGitEnvironmentVariables(['hermit']),\n };\n\n const fromPackages = from.map(quote).join(' ');\n\n // when a name replacement happens, need to uninstall the old package\n if (toUninstall.length > 0) {\n const packagesToUninstall = toUninstall.map(quote).join(' ');\n const uninstallCommands = `./hermit uninstall ${packagesToUninstall}`;\n\n try {\n const result = await exec(uninstallCommands, execOptions);\n logger.trace(\n { stdout: result.stdout },\n `hermit uninstall command stdout`,\n );\n } catch (e) {\n logger.warn({ err: e }, `error uninstall hermit package for replacement`);\n throw new UpdateHermitError(\n fromPackages,\n packagesToUninstall,\n e.stderr,\n e.stdout,\n );\n }\n }\n\n const packagesToInstall = toInstall.map(quote).join(' ');\n\n const execCommands = `./hermit install ${packagesToInstall}`;\n logger.debug(\n {\n packageFile: update.packageFileName,\n packagesToInstall,\n },\n `performing updates`,\n );\n\n try {\n const result = await exec(execCommands, execOptions);\n logger.trace({ stdout: result.stdout }, `hermit command stdout`);\n } catch (e) {\n logger.warn({ err: e }, `error updating hermit package`);\n throw new UpdateHermitError(\n fromPackages,\n packagesToInstall,\n e.stderr,\n e.stdout,\n );\n }\n}\n\nexport class UpdateHermitError extends Error {\n stdout: string;\n stderr: string;\n from: string;\n to: string;\n\n constructor(from: string, to: string, stderr: string, stdout = '') {\n super();\n this.stdout = stdout;\n this.stderr = stderr;\n this.from = from;\n this.to = to;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,eAAsB,gBACpB,QACyC;CACzC,MAAM,EAAE,oBAAoB;CAC5B,IAAI;EACF,MAAM,oBAAoB,MAAM;CAClC,SAAS,KAAK;EACZ,OAAO,MAAM,EAAE,IAAI,GAAG,iCAAiC;EACvD,IAAI,eAAe,mBACjB,OAAO,CACL,EACE,eAAe;GACb,UAAU,SAAS,IAAI,KAAK,QAAQ,IAAI;GACxC,QAAQ,IAAI;EACd,EACF,CACF;EAEF,OAAO,CACL,EACE,eAAe,EACb,QAAQ,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,EACzD,EACF,CACF;CACF;CAEA,OAAO,MAAM,mCAAmC;CAEhD,IAAI,eAA+C;CAEnD,IAAI;EACF,eAAe,MAAM,gBAAgB,eAAe;EACpD,OAAO,MAAM,EAAE,aAAa,GAAG,0BAA0B;CAC3D,SAAS,KAAK;EACZ,OAAO,MAAM,EAAE,IAAI,GAAG,qCAAqC;EAC3D,OAAO,CACL,EACE,eAAe,EACb,QAAQ,IAAI,QACd,EACF,CACF;CACF;CAEA,OAAO;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AM,KAAK,mBAAmB,WAAW;GACxD,OAAO,MACL,EAAE,QAAQ,OAAO,OAAO,GACxB,iCACF;EACF,SAAS,GAAG;GACV,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,gDAAgD;GACxE,MAAM,IAAI,kBACR,cACA,qBACA,EAAE,QACF,EAAE,MACJ;EACF;CACF;CAEA,MAAM,oBAAoB,UAAU,IAAI,KAAK,CAAC,CAAC,KAAK,GAAG;CAEvD,MAAM,eAAe,oBAAoB;CACzC,OAAO,MACL;EACE,aAAa,OAAO;EACpB;CACF,GACA,oBACF;CAEA,IAAI;EACF,MAAM,SAAS,MAAM,KAAK,cAAc,WAAW;EACnD,OAAO,MAAM,EAAE,QAAQ,OAAO,OAAO,GAAG,uBAAuB;CACjE,SAAS,GAAG;EACV,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,+BAA+B;EACvD,MAAM,IAAI,kBACR,cACA,mBACA,EAAE,QACF,EAAE,MACJ;CACF;AACF;AAEA,IAAa,oBAAb,cAAuC,MAAM;CAC3C;CACA;CACA;CACA;CAEA,YAAY,MAAc,IAAY,QAAgB,SAAS,IAAI;EACjE,MAAM;EACN,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,KAAK;CACZ;AACF"}
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":["p.map"],"sources":["../../../../lib/modules/manager/hermit/artifacts.ts"],"sourcesContent":["import { quote } from 'shlex';\nimport upath from 'upath';\nimport { logger } from '../../../logger/index.ts';\nimport { ExecError } from '../../../util/exec/exec-error.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n localPathIsSymbolicLink,\n readLocalSymlink,\n} from '../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../util/git/exec.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport * as p from '../../../util/promises.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport type { ReadContentResult } from './types.ts';\n\nconst gitExec = withGitEnvironment(['hermit']);\n\n/**\n * updateArtifacts runs hermit install for each updated dependencies\n */\nexport async function updateArtifacts(\n update: UpdateArtifact,\n): Promise<UpdateArtifactsResult[] | null> {\n const { packageFileName } = update;\n try {\n await updateHermitPackage(update);\n } catch (err) {\n logger.debug({ err }, `error updating hermit packages.`);\n if (err instanceof UpdateHermitError) {\n return [\n {\n artifactError: {\n fileName: `from: ${err.from}, to: ${err.to}`,\n stderr: err.stderr,\n },\n },\n ];\n }\n return [\n {\n artifactError: {\n stderr: err instanceof Error ? err.message : String(err),\n },\n },\n ];\n }\n\n logger.debug(`scanning the changes after update`);\n\n let updateResult: UpdateArtifactsResult[] | null = null;\n\n try {\n updateResult = await getUpdateResult(packageFileName);\n logger.debug({ updateResult }, `update result for hermit`);\n } catch (err) {\n logger.debug({ err }, 'Error getting hermet update results');\n return [\n {\n artifactError: {\n stderr: err.message,\n },\n },\n ];\n }\n\n return updateResult;\n}\n\n/**\n * getContent returns the content of either link or a normal file\n */\nasync function getContent(file: string): Promise<ReadContentResult> {\n let contents: string | null = '';\n const isSymlink = await localPathIsSymbolicLink(file);\n\n if (isSymlink) {\n contents = await readLocalSymlink(file);\n }\n\n if (contents === null) {\n throw new Error(`error getting content for ${file}`);\n }\n\n return {\n isSymlink,\n contents,\n };\n}\n\n/**\n * getAddResult returns the UpdateArtifactsResult for the added files\n */\nfunction getAddResult(\n path: string,\n contentRes: ReadContentResult,\n): UpdateArtifactsResult {\n return {\n file: {\n type: 'addition',\n path,\n contents: contentRes.contents,\n isSymlink: contentRes.isSymlink,\n isExecutable: contentRes.isExecutable,\n },\n };\n}\n\n/**\n * getDeleteResult returns the UpdateArtifactsResult for deleted files\n */\nfunction getDeleteResult(path: string): UpdateArtifactsResult {\n return {\n file: {\n type: 'deletion',\n path,\n },\n };\n}\n\n/**\n * getUpdateResult will return the update result after `hermit install`\n * has been performed for all packages\n */\nasync function getUpdateResult(\n packageFileName: string,\n): Promise<UpdateArtifactsResult[]> {\n const hermitFolder = `${upath.dirname(packageFileName)}/`;\n const hermitChanges = await getRepoStatus(hermitFolder);\n logger.debug(\n { hermitChanges, hermitFolder },\n `hermit changes after package update`,\n );\n\n // handle added files\n const added = await p.map(\n [...hermitChanges.created, ...hermitChanges.not_added],\n async (path: string): Promise<UpdateArtifactsResult> => {\n const contents = await getContent(path);\n\n return getAddResult(path, contents);\n },\n );\n\n const deleted = hermitChanges.deleted.map(getDeleteResult);\n\n const modified = await p.map(\n hermitChanges.modified,\n async (path: string): Promise<UpdateArtifactsResult[]> => {\n const contents = await getContent(path);\n return [\n getDeleteResult(path), // delete existing link\n getAddResult(path, contents), // add a new link\n ];\n },\n );\n\n const renamed = await p.map(\n hermitChanges.renamed,\n async (renamed): Promise<UpdateArtifactsResult[]> => {\n const from = renamed.from;\n const to = renamed.to;\n const toContents = await getContent(to);\n\n return [getDeleteResult(from), getAddResult(to, toContents)];\n },\n );\n\n return [\n // rename will need to go first, because\n // it needs to create the new link for the new version\n // for the modified links to use\n ...renamed.flat(),\n ...modified.flat(),\n ...added,\n ...deleted,\n ];\n}\n\n/**\n * getHermitPackage returns the hermit package for running the hermit install\n */\nfunction getHermitPackage(name: string, version: string): string {\n return `${name}-${version}`;\n}\n\n/**\n * updateHermitPackage runs hermit install for the given package\n */\nasync function updateHermitPackage(update: UpdateArtifact): Promise<void> {\n logger.trace({ update }, `hermit.updateHermitPackage()`);\n\n const toInstall = [];\n const from = [];\n // storing the old package for replacement\n const toUninstall = [];\n\n for (const pkg of update.updatedDeps) {\n if (!pkg.depName || !pkg.currentVersion || !pkg.newValue) {\n logger.debug(\n {\n depName: pkg.depName,\n currentVersion: pkg.currentVersion,\n newValue: pkg.newValue,\n },\n 'missing package update information',\n );\n\n throw new UpdateHermitError(\n getHermitPackage(pkg.depName ?? '', pkg.currentVersion ?? ''),\n getHermitPackage(pkg.depName ?? '', pkg.newValue ?? ''),\n 'invalid package to update',\n );\n }\n\n const depName = pkg.depName;\n const newName = pkg.newName;\n const currentVersion = pkg.currentVersion;\n const newValue = pkg.newValue;\n const fromPackage = getHermitPackage(depName, currentVersion);\n // newName will be available for replacement\n const toPackage = getHermitPackage(newName ?? depName, newValue);\n toInstall.push(toPackage);\n from.push(fromPackage);\n // skips uninstall for version only replacement\n if (pkg.updateType === 'replacement' && newName !== depName) {\n toUninstall.push(depName);\n }\n }\n\n const execOptions: ExecOptions = {\n docker: {},\n cwdFile: update.packageFileName,\n };\n\n const fromPackages = from.map(quote).join(' ');\n\n // when a name replacement happens, need to uninstall the old package\n if (toUninstall.length > 0) {\n const packagesToUninstall = toUninstall.map(quote).join(' ');\n const uninstallCommands = `./hermit uninstall ${packagesToUninstall}`;\n\n try {\n const result = await gitExec(uninstallCommands, execOptions);\n logger.trace(\n { stdout: result.stdout },\n `hermit uninstall command stdout`,\n );\n } catch (e) {\n logger.warn({ err: e }, `error uninstall hermit package for replacement`);\n if (!(e instanceof ExecError)) {\n throw e;\n }\n throw new UpdateHermitError(\n fromPackages,\n packagesToUninstall,\n e.stderr,\n e.stdout,\n );\n }\n }\n\n const packagesToInstall = toInstall.map(quote).join(' ');\n\n const execCommands = `./hermit install ${packagesToInstall}`;\n logger.debug(\n {\n packageFile: update.packageFileName,\n packagesToInstall,\n },\n `performing updates`,\n );\n\n try {\n const result = await gitExec(execCommands, execOptions);\n logger.trace({ stdout: result.stdout }, `hermit command stdout`);\n } catch (e) {\n logger.warn({ err: e }, `error updating hermit package`);\n if (!(e instanceof ExecError)) {\n throw e;\n }\n throw new UpdateHermitError(\n fromPackages,\n packagesToInstall,\n e.stderr,\n e.stdout,\n );\n }\n}\n\nexport class UpdateHermitError extends Error {\n stdout: string;\n stderr: string;\n from: string;\n to: string;\n\n constructor(from: string, to: string, stderr: string, stdout = '') {\n super();\n this.stdout = stdout;\n this.stderr = stderr;\n this.from = from;\n this.to = to;\n }\n}\n"],"mappings":";;;;;;;;;AAeA,MAAM,UAAU,mBAAmB,CAAC,QAAQ,CAAC;;;;AAK7C,eAAsB,gBAC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,mBACA,EAAE,QACF,EAAE,MACJ;CACF;AACF;AAEA,IAAa,oBAAb,cAAuC,MAAM;CAC3C;CACA;CACA;CACA;CAEA,YAAY,MAAc,IAAY,QAAgB,SAAS,IAAI;EACjE,MAAM;EACN,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,KAAK;CACZ;AACF"}
|
|
@@ -2,15 +2,15 @@ import "../../../../constants/error-messages.js";
|
|
|
2
2
|
import { logger } from "../../../../logger/index.js";
|
|
3
3
|
import { getSiblingFileName, readLocalFile } from "../../../../util/fs/index.js";
|
|
4
4
|
import { Result } from "../../../../util/result.js";
|
|
5
|
-
import { getGitEnvironmentVariables } from "../../../../util/git/auth.js";
|
|
6
|
-
import { exec } from "../../../../util/exec/index.js";
|
|
7
5
|
import { PypiDatasource } from "../../../datasource/pypi/index.js";
|
|
6
|
+
import { withGitEnvironment } from "../../../../util/git/exec.js";
|
|
8
7
|
import { BasePyProjectProcessor } from "./abstract.js";
|
|
9
8
|
import { depTypes } from "../utils.js";
|
|
10
9
|
import { PdmLockfile } from "../schema.js";
|
|
11
10
|
import { quote } from "shlex";
|
|
12
11
|
//#region lib/modules/manager/pep621/processors/pdm.ts
|
|
13
12
|
const pdmUpdateCMD = "pdm update --no-sync --update-eager";
|
|
13
|
+
const gitExec = withGitEnvironment(["pep621"]);
|
|
14
14
|
var PdmProcessor = class extends BasePyProjectProcessor {
|
|
15
15
|
lockfileName = "pdm.lock";
|
|
16
16
|
process(project, deps) {
|
|
@@ -45,24 +45,21 @@ var PdmProcessor = class extends BasePyProjectProcessor {
|
|
|
45
45
|
logger.debug("No pdm.lock found");
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
-
const pythonConstraint = {
|
|
49
|
-
toolName: "python",
|
|
50
|
-
constraint: config.constraints?.python ?? project.project?.["requires-python"]
|
|
51
|
-
};
|
|
52
|
-
const pdmConstraint = {
|
|
53
|
-
toolName: "pdm",
|
|
54
|
-
constraint: config.constraints?.pdm
|
|
55
|
-
};
|
|
56
48
|
const execOptions = {
|
|
57
49
|
cwdFile: packageFileName,
|
|
58
|
-
extraEnv: { ...getGitEnvironmentVariables(["pep621"]) },
|
|
59
50
|
docker: {},
|
|
60
|
-
toolConstraints: [
|
|
51
|
+
toolConstraints: [{
|
|
52
|
+
toolName: "python",
|
|
53
|
+
constraint: config.constraints?.python ?? project.project?.["requires-python"]
|
|
54
|
+
}, {
|
|
55
|
+
toolName: "pdm",
|
|
56
|
+
constraint: config.constraints?.pdm
|
|
57
|
+
}]
|
|
61
58
|
};
|
|
62
59
|
const cmds = [];
|
|
63
60
|
if (isLockFileMaintenance) cmds.push(pdmUpdateCMD);
|
|
64
61
|
else cmds.push(...generateCMDs(updatedDeps));
|
|
65
|
-
await
|
|
62
|
+
await gitExec(cmds, execOptions);
|
|
66
63
|
const fileChanges = [];
|
|
67
64
|
const newLockContent = await readLocalFile(lockFileName, "utf8");
|
|
68
65
|
if (existingLockFileContent !== newLockContent) fileChanges.push({ file: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdm.js","names":[],"sources":["../../../../../lib/modules/manager/pep621/processors/pdm.ts"],"sourcesContent":["import { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../../constants/error-messages.ts';\nimport { logger } from '../../../../logger/index.ts';\nimport
|
|
1
|
+
{"version":3,"file":"pdm.js","names":[],"sources":["../../../../../lib/modules/manager/pep621/processors/pdm.ts"],"sourcesContent":["import { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../../constants/error-messages.ts';\nimport { logger } from '../../../../logger/index.ts';\nimport type {\n ExecOptions,\n ToolConstraint,\n} from '../../../../util/exec/types.ts';\nimport {\n getSiblingFileName,\n readLocalFile,\n} from '../../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../../util/git/exec.ts';\nimport { Result } from '../../../../util/result.ts';\nimport { PypiDatasource } from '../../../datasource/pypi/index.ts';\nimport type {\n PackageDependency,\n UpdateArtifact,\n UpdateArtifactsResult,\n Upgrade,\n} from '../../types.ts';\nimport { PdmLockfile, type PyProject } from '../schema.ts';\nimport type { Pep621ManagerData } from '../types.ts';\nimport { depTypes } from '../utils.ts';\nimport { BasePyProjectProcessor } from './abstract.ts';\n\nconst pdmUpdateCMD = 'pdm update --no-sync --update-eager';\nconst gitExec = withGitEnvironment(['pep621']);\n\nexport class PdmProcessor extends BasePyProjectProcessor {\n override lockfileName = 'pdm.lock';\n\n process(\n project: PyProject,\n deps: PackageDependency[],\n ): PackageDependency<Pep621ManagerData>[] {\n const devDependencies = project.tool?.pdm?.devDependencies;\n if (devDependencies) {\n deps.push(...devDependencies);\n }\n\n const registryUrls = project.tool?.pdm?.registryUrls;\n if (registryUrls) {\n for (const dep of deps) {\n if (dep.datasource === PypiDatasource.id) {\n dep.registryUrls = registryUrls;\n }\n }\n }\n\n return deps;\n }\n\n async extractLockedVersions(\n project: PyProject,\n deps: PackageDependency[],\n packageFile: string,\n ): Promise<PackageDependency[]> {\n if (\n !project.tool?.pdm &&\n project['build-system']?.['build-backend'] !== 'pdm.backend'\n ) {\n return Promise.resolve(deps);\n }\n\n const lockFileName = getSiblingFileName(packageFile, 'pdm.lock');\n const lockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (lockFileContent) {\n const lockFileMapping = Result.parse(\n lockFileContent,\n PdmLockfile.transform(({ lock }) => lock),\n ).unwrapOr({});\n\n for (const dep of deps) {\n const packageName = dep.packageName;\n if (packageName && packageName in lockFileMapping) {\n dep.lockedVersion = lockFileMapping[packageName];\n }\n }\n }\n\n return Promise.resolve(deps);\n }\n\n async updateArtifacts(\n updateArtifact: UpdateArtifact,\n project: PyProject,\n ): Promise<UpdateArtifactsResult[] | null> {\n const { config, updatedDeps, packageFileName } = updateArtifact;\n\n const { isLockFileMaintenance } = config;\n\n // abort if no lockfile is defined\n const lockFileName = getSiblingFileName(packageFileName, this.lockfileName);\n try {\n const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n logger.debug('No pdm.lock found');\n return null;\n }\n\n const pythonConstraint: ToolConstraint = {\n toolName: 'python',\n constraint:\n config.constraints?.python ?? project.project?.['requires-python'],\n };\n const pdmConstraint: ToolConstraint = {\n toolName: 'pdm',\n constraint: config.constraints?.pdm,\n };\n\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n docker: {},\n toolConstraints: [pythonConstraint, pdmConstraint],\n };\n\n // on lockFileMaintenance do not specify any packages and update the complete lock file\n // else only update specific packages\n const cmds: string[] = [];\n if (isLockFileMaintenance) {\n cmds.push(pdmUpdateCMD);\n } else {\n cmds.push(...generateCMDs(updatedDeps));\n }\n await gitExec(cmds, execOptions);\n\n // check for changes\n const fileChanges: UpdateArtifactsResult[] = [];\n const newLockContent = await readLocalFile(lockFileName, 'utf8');\n const isLockFileChanged = existingLockFileContent !== newLockContent;\n if (isLockFileChanged) {\n fileChanges.push({\n file: {\n type: 'addition',\n path: lockFileName,\n contents: newLockContent,\n },\n });\n } else {\n logger.debug('pdm.lock is unchanged');\n }\n\n return fileChanges.length ? fileChanges : null;\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update PDM lock file');\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: err.message,\n },\n },\n ];\n }\n }\n}\n\nfunction generateCMDs(updatedDeps: Upgrade<Pep621ManagerData>[]): string[] {\n const cmds: string[] = [];\n const packagesByCMD: Record<string, string[]> = {};\n for (const dep of updatedDeps) {\n switch (dep.depType) {\n case depTypes.optionalDependencies: {\n if (!dep.managerData?.depGroup) {\n logger.once.warn(\n { dep: dep.depName },\n 'Unexpected optional dependency without group',\n );\n continue;\n }\n addPackageToCMDRecord(\n packagesByCMD,\n `${pdmUpdateCMD} -G ${quote(dep.managerData.depGroup)}`,\n dep.packageName!,\n );\n break;\n }\n case depTypes.dependencyGroups:\n case depTypes.pdmDevDependencies: {\n if (!dep.managerData?.depGroup) {\n logger.once.warn(\n { dep: dep.depName },\n 'Unexpected dev dependency without group',\n );\n continue;\n }\n addPackageToCMDRecord(\n packagesByCMD,\n `${pdmUpdateCMD} -dG ${quote(dep.managerData.depGroup)}`,\n dep.packageName!,\n );\n break;\n }\n case depTypes.buildSystemRequires:\n // build requirements are not locked in the lock files, no need to update.\n // Reference: https://github.com/pdm-project/pdm/discussions/2869\n break;\n default: {\n addPackageToCMDRecord(packagesByCMD, pdmUpdateCMD, dep.packageName!);\n }\n }\n }\n\n for (const commandPrefix in packagesByCMD) {\n const packageList = packagesByCMD[commandPrefix].map(quote).join(' ');\n const cmd = `${commandPrefix} ${packageList}`;\n cmds.push(cmd);\n }\n\n return cmds;\n}\n\nfunction addPackageToCMDRecord(\n packagesByCMD: Record<string, string[]>,\n commandPrefix: string,\n packageName: string,\n): void {\n if (!packagesByCMD[commandPrefix]) {\n packagesByCMD[commandPrefix] = [];\n }\n packagesByCMD[commandPrefix].push(packageName);\n}\n"],"mappings":";;;;;;;;;;;AAyBA,MAAM,eAAe;AACrB,MAAM,UAAU,mBAAmB,CAAC,QAAQ,CAAC;AAE7C,IAAa,eAAb,cAAkC,uBAAuB;CACvD,eAAwB;CAExB,QACE,SACA,MACwC;EACxC,MAAM,kBAAkB,QAAQ,MAAM,KAAK;EAC3C,IAAI,iBACF,KAAK,KAAK,GAAG,eAAe;EAG9B,MAAM,eAAe,QAAQ,MAAM,KAAK;EACxC,IAAI,cACG;QAAA,MAAM,OAAO,MAChB,IAAI,IAAI,eAAe,eAAe,IACpC,IAAI,eAAe;EAAA;EAKzB,OAAO;CACT;CAEA,MAAM,sBACJ,SACA,MACA,aAC8B;EAC9B,IACE,CAAC,QAAQ,MAAM,OACf,QAAQ,eAAe,GAAG,qBAAqB,eAE/C,OAAO,QAAQ,QAAQ,IAAI;EAG7B,MAAM,eAAe,mBAAmB,aAAa,UAAU;EAC/D,MAAM,kBAAkB,MAAM,cAAc,cAAc,MAAM;EAChE,IAAI,iBAAiB;GACnB,MAAM,kBAA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,IAAI;GACd,EACF,CACF;EACF;CACF;AACF;AAEA,SAAS,aAAa,aAAqD;CACzE,MAAM,OAAiB,CAAC;CACxB,MAAM,gBAA0C,CAAC;CACjD,KAAK,MAAM,OAAO,aAChB,QAAQ,IAAI,SAAZ;EACE,KAAK,SAAS;GACZ,IAAI,CAAC,IAAI,aAAa,UAAU;IAC9B,OAAO,KAAK,KACV,EAAE,KAAK,IAAI,QAAQ,GACnB,8CACF;IACA;GACF;GACA,sBACE,eACA,GAAG,aAAa,MAAM,MAAM,IAAI,YAAY,QAAQ,KACpD,IAAI,WACN;GACA;EAEF,KAAK,SAAS;EACd,KAAK,SAAS;GACZ,IAAI,CAAC,IAAI,aAAa,UAAU;IAC9B,OAAO,KAAK,KACV,EAAE,KAAK,IAAI,QAAQ,GACnB,yCACF;IACA;GACF;GACA,sBACE,eACA,GAAG,aAAa,OAAO,MAAM,IAAI,YAAY,QAAQ,KACrD,IAAI,WACN;GACA;EAEF,KAAK,SAAS,qBAGZ;EACF,SACE,sBAAsB,eAAe,cAAc,IAAI,WAAY;CAEvE;CAGF,KAAK,MAAM,iBAAiB,eAAe;EAEzC,MAAM,MAAM,GAAG,cAAc,GADT,cAAc,cAAc,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,GACvB;EAC1C,KAAK,KAAK,GAAG;CACf;CAEA,OAAO;AACT;AAEA,SAAS,sBACP,eACA,eACA,aACM;CACN,IAAI,CAAC,cAAc,gBACjB,cAAc,iBAAiB,CAAC;CAElC,cAAc,cAAc,CAAC,KAAK,WAAW;AAC/C"}
|
|
@@ -5,10 +5,9 @@ import { find } from "../../../../util/host-rules.js";
|
|
|
5
5
|
import { findLocalSiblingOrParent, readLocalFile } from "../../../../util/fs/index.js";
|
|
6
6
|
import { Result } from "../../../../util/result.js";
|
|
7
7
|
import { getGoogleAuthHostRule } from "../../../datasource/util.js";
|
|
8
|
-
import { getGitEnvironmentVariables } from "../../../../util/git/auth.js";
|
|
9
|
-
import { exec } from "../../../../util/exec/index.js";
|
|
10
8
|
import { PypiDatasource } from "../../../datasource/pypi/index.js";
|
|
11
9
|
import { applyGitSource } from "../../util.js";
|
|
10
|
+
import { withGitEnvironment } from "../../../../util/git/exec.js";
|
|
12
11
|
import { BasePyProjectProcessor } from "./abstract.js";
|
|
13
12
|
import { depTypes } from "../utils.js";
|
|
14
13
|
import { UvLockfile } from "../schema.js";
|
|
@@ -16,6 +15,7 @@ import { isString } from "@sindresorhus/is";
|
|
|
16
15
|
import { quote } from "shlex";
|
|
17
16
|
//#region lib/modules/manager/pep621/processors/uv.ts
|
|
18
17
|
const uvUpdateCMD = "uv lock";
|
|
18
|
+
const gitExec = withGitEnvironment(["pep621"]);
|
|
19
19
|
var UvProcessor = class extends BasePyProjectProcessor {
|
|
20
20
|
lockfileName = "uv.lock";
|
|
21
21
|
process(project, deps) {
|
|
@@ -95,7 +95,6 @@ var UvProcessor = class extends BasePyProjectProcessor {
|
|
|
95
95
|
const execOptions = {
|
|
96
96
|
cwdFile: packageFileName,
|
|
97
97
|
extraEnv: {
|
|
98
|
-
...getGitEnvironmentVariables(["pep621"]),
|
|
99
98
|
...await getUvExtraIndexUrl(project, updateArtifact.updatedDeps),
|
|
100
99
|
...await getUvIndexCredentials(project)
|
|
101
100
|
},
|
|
@@ -105,7 +104,7 @@ var UvProcessor = class extends BasePyProjectProcessor {
|
|
|
105
104
|
let cmd;
|
|
106
105
|
if (isLockFileMaintenance) cmd = `${uvUpdateCMD} --upgrade`;
|
|
107
106
|
else cmd = generateCMD(updatedDeps);
|
|
108
|
-
await
|
|
107
|
+
await gitExec(cmd, execOptions);
|
|
109
108
|
const fileChanges = [];
|
|
110
109
|
const newLockContent = await readLocalFile(lockFileName, "utf8");
|
|
111
110
|
if (existingLockFileContent !== newLockContent) fileChanges.push({ file: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uv.js","names":[],"sources":["../../../../../lib/modules/manager/pep621/processors/uv.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../../constants/error-messages.ts';\nimport { logger } from '../../../../logger/index.ts';\nimport type { HostRule } from '../../../../types/index.ts';\nimport { exec } from '../../../../util/exec/index.ts';\nimport type {\n ExecOptions,\n ToolConstraint,\n} from '../../../../util/exec/types.ts';\nimport {\n findLocalSiblingOrParent,\n readLocalFile,\n} from '../../../../util/fs/index.ts';\nimport { getGitEnvironmentVariables } from '../../../../util/git/auth.ts';\nimport { find } from '../../../../util/host-rules.ts';\nimport { Result } from '../../../../util/result.ts';\nimport { parseUrl } from '../../../../util/url.ts';\nimport { PypiDatasource } from '../../../datasource/pypi/index.ts';\nimport { getGoogleAuthHostRule } from '../../../datasource/util.ts';\nimport type {\n PackageDependency,\n UpdateArtifact,\n UpdateArtifactsResult,\n Upgrade,\n} from '../../types.ts';\nimport { applyGitSource } from '../../util.ts';\nimport { type PyProject, UvLockfile } from '../schema.ts';\nimport { depTypes } from '../utils.ts';\n\nimport { BasePyProjectProcessor } from './abstract.ts';\n\nconst uvUpdateCMD = 'uv lock';\n\nexport class UvProcessor extends BasePyProjectProcessor {\n override lockfileName = 'uv.lock';\n\n process(project: PyProject, deps: PackageDependency[]): PackageDependency[] {\n const uv = project.tool?.uv;\n if (!uv) {\n return deps;\n }\n\n const hasExplicitDefault = uv.index?.some(\n (index) => index.default && index.explicit,\n );\n const defaultIndex = uv.index?.find(\n (index) => index.default && !index.explicit,\n );\n const implicitIndexUrls = uv.index\n ?.filter((index) => !index.explicit && index.name !== defaultIndex?.name)\n ?.map(({ url }) => url);\n\n const devDependencies = uv['dev-dependencies'];\n if (devDependencies) {\n deps.push(...devDependencies);\n }\n\n // https://docs.astral.sh/uv/concepts/dependencies/#dependency-sources\n // Skip sources that do not make sense to handle (e.g. path).\n if (uv.sources || defaultIndex || implicitIndexUrls) {\n for (const dep of deps) {\n /* v8 ignore next 3 -- needs test */\n if (!dep.packageName) {\n continue;\n }\n\n if (dep.depType === 'requires-python') {\n continue;\n }\n\n // Using `packageName` as it applies PEP 508 normalization, which is\n // also applied by uv when matching a source to a dependency.\n const depSource = uv.sources?.[dep.packageName];\n if (depSource) {\n // Dependency is pinned to a specific source.\n dep.depType = depTypes.uvSources;\n if ('index' in depSource) {\n const index = uv.index?.find(\n ({ name }) => name === depSource.index,\n );\n if (index) {\n dep.registryUrls = [index.url];\n }\n } else if ('git' in depSource) {\n applyGitSource(\n dep,\n depSource.git,\n depSource.rev,\n depSource.tag,\n depSource.branch,\n );\n } else if ('url' in depSource) {\n dep.skipReason = 'unsupported-url';\n } else if ('path' in depSource) {\n dep.skipReason = 'path-dependency';\n } else if ('workspace' in depSource) {\n dep.skipReason = 'inherited-dependency';\n } else {\n /* v8 ignore next -- unreachable through schema */\n dep.skipReason = 'unknown-registry';\n }\n } else {\n // Dependency is not pinned to a specific source, so we need to\n // determine the source based on the index configuration.\n if (hasExplicitDefault) {\n // don't fall back to pypi if there is an explicit default index\n dep.registryUrls = [];\n } else if (defaultIndex) {\n // There is a default index configured, so use it.\n dep.registryUrls = [defaultIndex.url];\n }\n\n if (implicitIndexUrls?.length) {\n // If there are implicit indexes, check them first and fall back\n // to the default.\n dep.registryUrls = implicitIndexUrls.concat(\n dep.registryUrls ?? PypiDatasource.defaultURL,\n );\n }\n }\n }\n }\n\n return deps;\n }\n\n async extractLockedVersions(\n project: PyProject,\n deps: PackageDependency[],\n packageFile: string,\n ): Promise<PackageDependency[]> {\n const lockFileName = await findLocalSiblingOrParent(\n packageFile,\n this.lockfileName,\n );\n if (lockFileName === null) {\n logger.debug({ packageFile }, `No uv lock file found`);\n } else {\n const lockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (lockFileContent) {\n const { val: lockFileMapping, err } = Result.parse(\n lockFileContent,\n UvLockfile,\n ).unwrap();\n\n if (err) {\n logger.debug({ packageFile, err }, `Error parsing uv lock file`);\n } else {\n for (const dep of deps) {\n const packageName = dep.packageName;\n if (packageName && packageName in lockFileMapping) {\n dep.lockedVersion = lockFileMapping[packageName];\n }\n }\n }\n }\n }\n\n return Promise.resolve(deps);\n }\n\n async updateArtifacts(\n updateArtifact: UpdateArtifact,\n project: PyProject,\n ): Promise<UpdateArtifactsResult[] | null> {\n const { config, updatedDeps, packageFileName } = updateArtifact;\n\n const { isLockFileMaintenance } = config;\n\n // abort if no lockfile is defined\n const lockFileName = await findLocalSiblingOrParent(\n packageFileName,\n 'uv.lock',\n );\n if (lockFileName === null) {\n logger.debug({ packageFileName }, `No uv lock file found`);\n return null;\n }\n try {\n const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n logger.debug('No uv.lock found');\n return null;\n }\n\n const pythonConstraint: ToolConstraint = {\n toolName: 'python',\n constraint:\n config.constraints?.python ?? project.project?.['requires-python'],\n };\n const uvConstraint: ToolConstraint = {\n toolName: 'uv',\n constraint:\n config.constraints?.uv ?? project.tool?.uv?.['required-version'],\n };\n\n const extraEnv = {\n ...getGitEnvironmentVariables(['pep621']),\n ...(await getUvExtraIndexUrl(project, updateArtifact.updatedDeps)),\n ...(await getUvIndexCredentials(project)),\n };\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n extraEnv,\n docker: {},\n toolConstraints: [pythonConstraint, uvConstraint],\n };\n\n // on lockFileMaintenance do not specify any packages and update the complete lock file\n // else only update specific packages\n let cmd: string;\n if (isLockFileMaintenance) {\n cmd = `${uvUpdateCMD} --upgrade`;\n } else {\n cmd = generateCMD(updatedDeps);\n }\n await exec(cmd, execOptions);\n\n // check for changes\n const fileChanges: UpdateArtifactsResult[] = [];\n const newLockContent = await readLocalFile(lockFileName, 'utf8');\n const isLockFileChanged = existingLockFileContent !== newLockContent;\n if (isLockFileChanged) {\n fileChanges.push({\n file: {\n type: 'addition',\n path: lockFileName,\n contents: newLockContent,\n },\n });\n } else {\n logger.debug('uv.lock is unchanged');\n }\n\n return fileChanges.length ? fileChanges : null;\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update uv lock file');\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: err.message,\n },\n },\n ];\n }\n }\n}\n\nfunction generateCMD(updatedDeps: Upgrade[]): string {\n const deps: string[] = [];\n\n for (const dep of updatedDeps) {\n switch (dep.depType) {\n case depTypes.optionalDependencies: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.uvDevDependencies:\n case depTypes.uvSources: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.buildSystemRequires:\n // build requirements are not locked in the lock files, no need to update.\n break;\n default: {\n deps.push(dep.packageName!);\n }\n }\n }\n\n return `${uvUpdateCMD} ${deps.map((dep) => `--upgrade-package ${quote(dep)}`).join(' ')}`;\n}\n\nfunction getMatchingHostRule(url: string | undefined): HostRule {\n return find({ hostType: PypiDatasource.id, url });\n}\n\nasync function getUsernamePassword(\n url: URL,\n): Promise<{ username?: string; password?: string }> {\n const rule = getMatchingHostRule(url.toString());\n if (rule.username || rule.password) {\n return rule;\n }\n\n if (url.hostname.endsWith('.pkg.dev')) {\n const hostRule = await getGoogleAuthHostRule();\n if (hostRule) {\n return hostRule;\n }\n logger.once.debug({ url }, 'Could not get Google access token');\n }\n\n return {};\n}\n\nasync function getUvExtraIndexUrl(\n project: PyProject,\n deps: Upgrade[],\n): Promise<NodeJS.ProcessEnv> {\n const pyPiRegistryUrls = deps\n .filter((dep) => dep.datasource === PypiDatasource.id)\n .filter((dep) => {\n // Remove dependencies that are pinned to a specific index\n const sources = project.tool?.uv?.sources;\n const packageName = dep.packageName!;\n return !sources || !(packageName in sources);\n })\n .flatMap((dep) => dep.registryUrls)\n .filter(isString)\n .filter((registryUrl) => {\n // Check if the registry URL is not the default one and not already configured\n const configuredIndexUrls =\n project.tool?.uv?.index?.map(({ url }) => url) ?? [];\n return (\n registryUrl !== PypiDatasource.defaultURL &&\n !configuredIndexUrls.includes(registryUrl)\n );\n });\n\n const registryUrls = new Set(pyPiRegistryUrls);\n const extraIndexUrls: string[] = [];\n\n for (const registryUrl of registryUrls) {\n const parsedUrl = parseUrl(registryUrl);\n if (!parsedUrl) {\n continue;\n }\n\n const { username, password } = await getUsernamePassword(parsedUrl);\n if (username || password) {\n if (username) {\n parsedUrl.username = username;\n }\n if (password) {\n parsedUrl.password = password;\n }\n }\n\n extraIndexUrls.push(parsedUrl.toString());\n }\n\n return {\n UV_EXTRA_INDEX_URL: extraIndexUrls.join(' '),\n };\n}\n\nasync function getUvIndexCredentials(\n project: PyProject,\n): Promise<NodeJS.ProcessEnv> {\n const uv_indexes = project.tool?.uv?.index;\n\n if (!uv_indexes) {\n return {};\n }\n\n const entries = [];\n\n for (const { name, url } of uv_indexes) {\n const parsedUrl = parseUrl(url);\n /* v8 ignore next 3 -- needs test */\n if (!parsedUrl) {\n continue;\n }\n\n // If no name is provided for the index, authentication information must be passed through alternative methods\n if (!name) {\n continue;\n }\n\n const { username, password } = await getUsernamePassword(parsedUrl);\n\n const NAME = name.toUpperCase().replace(/[^A-Z0-9]/g, '_');\n\n if (username) {\n entries.push([`UV_INDEX_${NAME}_USERNAME`, username]);\n }\n\n if (password) {\n entries.push([`UV_INDEX_${NAME}_PASSWORD`, password]);\n }\n }\n\n return Object.fromEntries(entries);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,MAAM,cAAc;AAEpB,IAAa,cAAb,cAAiC,uBAAuB;CACtD,eAAwB;CAExB,QAAQ,SAAoB,MAAgD;EAC1E,MAAM,KAAK,QAAQ,MAAM;EACzB,IAAI,CAAC,IACH,OAAO;EAGT,MAAM,qBAAqB,GAAG,OAAO,MAClC,UAAU,MAAM,WAAW,MAAM,QACpC;EACA,MAAM,eAAe,GAAG,OAAO,MAC5B,UAAU,MAAM,WAAW,CAAC,MAAM,QACrC;EACA,MAAM,oBAAoB,GAAG,OACzB,QAAQ,UAAU,CAAC,MAAM,YAAY,MAAM,SAAS,cAAc,IAAI,CAAC,EACvE,KAAK,EAAE,UAAU,GAAG;EAExB,MAAM,kBAAkB,G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AAgB;EAEvB,MAAM,sBACJ,QAAQ,MAAM,IAAI,OAAO,KAAK,EAAE,UAAU,GAAG,KAAK,CAAC;EACrD,OACE,gBAAgB,eAAe,cAC/B,CAAC,oBAAoB,SAAS,WAAW;CAE7C,CAAC;CAEH,MAAM,eAAe,IAAI,IAAI,gBAAgB;CAC7C,MAAM,iBAA2B,CAAC;CAElC,KAAK,MAAM,eAAe,cAAc;EACtC,MAAM,YAAY,SAAS,WAAW;EACtC,IAAI,CAAC,WACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,oBAAoB,SAAS;EAClE,IAAI,YAAY,UAAU;GACxB,IAAI,UACF,UAAU,WAAW;GAEvB,IAAI,UACF,UAAU,WAAW;EAEzB;EAEA,eAAe,KAAK,UAAU,SAAS,CAAC;CAC1C;CAEA,OAAO,EACL,oBAAoB,eAAe,KAAK,GAAG,EAC7C;AACF;AAEA,eAAe,sBACb,SAC4B;CAC5B,MAAM,aAAa,QAAQ,MAAM,IAAI;CAErC,IAAI,CAAC,YACH,OAAO,CAAC;CAGV,MAAM,UAAU,CAAC;CAEjB,KAAK,MAAM,EAAE,MAAM,SAAS,YAAY;EACtC,MAAM,YAAY,SAAS,GAAG;;EAE9B,IAAI,CAAC,WACH;EAIF,IAAI,CAAC,MACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,oBAAoB,SAAS;EAElE,MAAM,OAAO,KAAK,YAAY,CAAC,CAAC,QAAQ,cAAc,GAAG;EAEzD,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;EAGtD,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;CAExD;CAEA,OAAO,OAAO,YAAY,OAAO;AACnC"}
|
|
1
|
+
{"version":3,"file":"uv.js","names":[],"sources":["../../../../../lib/modules/manager/pep621/processors/uv.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../../constants/error-messages.ts';\nimport { logger } from '../../../../logger/index.ts';\nimport type { HostRule } from '../../../../types/index.ts';\nimport type {\n ExecOptions,\n ToolConstraint,\n} from '../../../../util/exec/types.ts';\nimport {\n findLocalSiblingOrParent,\n readLocalFile,\n} from '../../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../../util/git/exec.ts';\nimport { find } from '../../../../util/host-rules.ts';\nimport { Result } from '../../../../util/result.ts';\nimport { parseUrl } from '../../../../util/url.ts';\nimport { PypiDatasource } from '../../../datasource/pypi/index.ts';\nimport { getGoogleAuthHostRule } from '../../../datasource/util.ts';\nimport type {\n PackageDependency,\n UpdateArtifact,\n UpdateArtifactsResult,\n Upgrade,\n} from '../../types.ts';\nimport { applyGitSource } from '../../util.ts';\nimport { type PyProject, UvLockfile } from '../schema.ts';\nimport { depTypes } from '../utils.ts';\n\nimport { BasePyProjectProcessor } from './abstract.ts';\n\nconst uvUpdateCMD = 'uv lock';\nconst gitExec = withGitEnvironment(['pep621']);\n\nexport class UvProcessor extends BasePyProjectProcessor {\n override lockfileName = 'uv.lock';\n\n process(project: PyProject, deps: PackageDependency[]): PackageDependency[] {\n const uv = project.tool?.uv;\n if (!uv) {\n return deps;\n }\n\n const hasExplicitDefault = uv.index?.some(\n (index) => index.default && index.explicit,\n );\n const defaultIndex = uv.index?.find(\n (index) => index.default && !index.explicit,\n );\n const implicitIndexUrls = uv.index\n ?.filter((index) => !index.explicit && index.name !== defaultIndex?.name)\n ?.map(({ url }) => url);\n\n const devDependencies = uv['dev-dependencies'];\n if (devDependencies) {\n deps.push(...devDependencies);\n }\n\n // https://docs.astral.sh/uv/concepts/dependencies/#dependency-sources\n // Skip sources that do not make sense to handle (e.g. path).\n if (uv.sources || defaultIndex || implicitIndexUrls) {\n for (const dep of deps) {\n /* v8 ignore next 3 -- needs test */\n if (!dep.packageName) {\n continue;\n }\n\n if (dep.depType === 'requires-python') {\n continue;\n }\n\n // Using `packageName` as it applies PEP 508 normalization, which is\n // also applied by uv when matching a source to a dependency.\n const depSource = uv.sources?.[dep.packageName];\n if (depSource) {\n // Dependency is pinned to a specific source.\n dep.depType = depTypes.uvSources;\n if ('index' in depSource) {\n const index = uv.index?.find(\n ({ name }) => name === depSource.index,\n );\n if (index) {\n dep.registryUrls = [index.url];\n }\n } else if ('git' in depSource) {\n applyGitSource(\n dep,\n depSource.git,\n depSource.rev,\n depSource.tag,\n depSource.branch,\n );\n } else if ('url' in depSource) {\n dep.skipReason = 'unsupported-url';\n } else if ('path' in depSource) {\n dep.skipReason = 'path-dependency';\n } else if ('workspace' in depSource) {\n dep.skipReason = 'inherited-dependency';\n } else {\n /* v8 ignore next -- unreachable through schema */\n dep.skipReason = 'unknown-registry';\n }\n } else {\n // Dependency is not pinned to a specific source, so we need to\n // determine the source based on the index configuration.\n if (hasExplicitDefault) {\n // don't fall back to pypi if there is an explicit default index\n dep.registryUrls = [];\n } else if (defaultIndex) {\n // There is a default index configured, so use it.\n dep.registryUrls = [defaultIndex.url];\n }\n\n if (implicitIndexUrls?.length) {\n // If there are implicit indexes, check them first and fall back\n // to the default.\n dep.registryUrls = implicitIndexUrls.concat(\n dep.registryUrls ?? PypiDatasource.defaultURL,\n );\n }\n }\n }\n }\n\n return deps;\n }\n\n async extractLockedVersions(\n project: PyProject,\n deps: PackageDependency[],\n packageFile: string,\n ): Promise<PackageDependency[]> {\n const lockFileName = await findLocalSiblingOrParent(\n packageFile,\n this.lockfileName,\n );\n if (lockFileName === null) {\n logger.debug({ packageFile }, `No uv lock file found`);\n } else {\n const lockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (lockFileContent) {\n const { val: lockFileMapping, err } = Result.parse(\n lockFileContent,\n UvLockfile,\n ).unwrap();\n\n if (err) {\n logger.debug({ packageFile, err }, `Error parsing uv lock file`);\n } else {\n for (const dep of deps) {\n const packageName = dep.packageName;\n if (packageName && packageName in lockFileMapping) {\n dep.lockedVersion = lockFileMapping[packageName];\n }\n }\n }\n }\n }\n\n return Promise.resolve(deps);\n }\n\n async updateArtifacts(\n updateArtifact: UpdateArtifact,\n project: PyProject,\n ): Promise<UpdateArtifactsResult[] | null> {\n const { config, updatedDeps, packageFileName } = updateArtifact;\n\n const { isLockFileMaintenance } = config;\n\n // abort if no lockfile is defined\n const lockFileName = await findLocalSiblingOrParent(\n packageFileName,\n 'uv.lock',\n );\n if (lockFileName === null) {\n logger.debug({ packageFileName }, `No uv lock file found`);\n return null;\n }\n try {\n const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n logger.debug('No uv.lock found');\n return null;\n }\n\n const pythonConstraint: ToolConstraint = {\n toolName: 'python',\n constraint:\n config.constraints?.python ?? project.project?.['requires-python'],\n };\n const uvConstraint: ToolConstraint = {\n toolName: 'uv',\n constraint:\n config.constraints?.uv ?? project.tool?.uv?.['required-version'],\n };\n\n const extraEnv = {\n ...(await getUvExtraIndexUrl(project, updateArtifact.updatedDeps)),\n ...(await getUvIndexCredentials(project)),\n };\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n extraEnv,\n docker: {},\n toolConstraints: [pythonConstraint, uvConstraint],\n };\n\n // on lockFileMaintenance do not specify any packages and update the complete lock file\n // else only update specific packages\n let cmd: string;\n if (isLockFileMaintenance) {\n cmd = `${uvUpdateCMD} --upgrade`;\n } else {\n cmd = generateCMD(updatedDeps);\n }\n await gitExec(cmd, execOptions);\n\n // check for changes\n const fileChanges: UpdateArtifactsResult[] = [];\n const newLockContent = await readLocalFile(lockFileName, 'utf8');\n const isLockFileChanged = existingLockFileContent !== newLockContent;\n if (isLockFileChanged) {\n fileChanges.push({\n file: {\n type: 'addition',\n path: lockFileName,\n contents: newLockContent,\n },\n });\n } else {\n logger.debug('uv.lock is unchanged');\n }\n\n return fileChanges.length ? fileChanges : null;\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update uv lock file');\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: err.message,\n },\n },\n ];\n }\n }\n}\n\nfunction generateCMD(updatedDeps: Upgrade[]): string {\n const deps: string[] = [];\n\n for (const dep of updatedDeps) {\n switch (dep.depType) {\n case depTypes.optionalDependencies: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.uvDevDependencies:\n case depTypes.uvSources: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.buildSystemRequires:\n // build requirements are not locked in the lock files, no need to update.\n break;\n default: {\n deps.push(dep.packageName!);\n }\n }\n }\n\n return `${uvUpdateCMD} ${deps.map((dep) => `--upgrade-package ${quote(dep)}`).join(' ')}`;\n}\n\nfunction getMatchingHostRule(url: string | undefined): HostRule {\n return find({ hostType: PypiDatasource.id, url });\n}\n\nasync function getUsernamePassword(\n url: URL,\n): Promise<{ username?: string; password?: string }> {\n const rule = getMatchingHostRule(url.toString());\n if (rule.username || rule.password) {\n return rule;\n }\n\n if (url.hostname.endsWith('.pkg.dev')) {\n const hostRule = await getGoogleAuthHostRule();\n if (hostRule) {\n return hostRule;\n }\n logger.once.debug({ url }, 'Could not get Google access token');\n }\n\n return {};\n}\n\nasync function getUvExtraIndexUrl(\n project: PyProject,\n deps: Upgrade[],\n): Promise<NodeJS.ProcessEnv> {\n const pyPiRegistryUrls = deps\n .filter((dep) => dep.datasource === PypiDatasource.id)\n .filter((dep) => {\n // Remove dependencies that are pinned to a specific index\n const sources = project.tool?.uv?.sources;\n const packageName = dep.packageName!;\n return !sources || !(packageName in sources);\n })\n .flatMap((dep) => dep.registryUrls)\n .filter(isString)\n .filter((registryUrl) => {\n // Check if the registry URL is not the default one and not already configured\n const configuredIndexUrls =\n project.tool?.uv?.index?.map(({ url }) => url) ?? [];\n return (\n registryUrl !== PypiDatasource.defaultURL &&\n !configuredIndexUrls.includes(registryUrl)\n );\n });\n\n const registryUrls = new Set(pyPiRegistryUrls);\n const extraIndexUrls: string[] = [];\n\n for (const registryUrl of registryUrls) {\n const parsedUrl = parseUrl(registryUrl);\n if (!parsedUrl) {\n continue;\n }\n\n const { username, password } = await getUsernamePassword(parsedUrl);\n if (username || password) {\n if (username) {\n parsedUrl.username = username;\n }\n if (password) {\n parsedUrl.password = password;\n }\n }\n\n extraIndexUrls.push(parsedUrl.toString());\n }\n\n return {\n UV_EXTRA_INDEX_URL: extraIndexUrls.join(' '),\n };\n}\n\nasync function getUvIndexCredentials(\n project: PyProject,\n): Promise<NodeJS.ProcessEnv> {\n const uv_indexes = project.tool?.uv?.index;\n\n if (!uv_indexes) {\n return {};\n }\n\n const entries = [];\n\n for (const { name, url } of uv_indexes) {\n const parsedUrl = parseUrl(url);\n /* v8 ignore next 3 -- needs test */\n if (!parsedUrl) {\n continue;\n }\n\n // If no name is provided for the index, authentication information must be passed through alternative methods\n if (!name) {\n continue;\n }\n\n const { username, password } = await getUsernamePassword(parsedUrl);\n\n const NAME = name.toUpperCase().replace(/[^A-Z0-9]/g, '_');\n\n if (username) {\n entries.push([`UV_INDEX_${NAME}_USERNAME`, username]);\n }\n\n if (password) {\n entries.push([`UV_INDEX_${NAME}_PASSWORD`, password]);\n }\n }\n\n return Object.fromEntries(entries);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAM,cAAc;AACpB,MAAM,UAAU,mBAAmB,CAAC,QAAQ,CAAC;AAE7C,IAAa,cAAb,cAAiC,uBAAuB;CACtD,eAAwB;CAExB,QAAQ,SAAoB,MAAgD;EAC1E,MAAM,KAAK,QAAQ,MAAM;EACzB,IAAI,CAAC,IACH,OAAO;EAGT,MAAM,qBAAqB,GAAG,OAAO,MAClC,UAAU,MAAM,WAAW,MAAM,QACpC;EACA,MAAM,eAAe,GAAG,OAAO,MAC5B,UAAU,MAAM,WAAW,CAAC,MAAM,QACrC;EACA,MAAM,oBAAoB,GAAG,OACzB,QAAQ,UAAU,CAAC,MAAM,YAAY,MAAM,SAAS,cAAc,IAAI,CAAC,EACvE,KAAK,EAAE,UAAU,GAAG;EAExB,MAAM,kBAAkB,GAAG;EAC3B,IAAI,iBACF,KAAK,KAA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AG,KAAK,CAAC;EACrD,OACE,gBAAgB,eAAe,cAC/B,CAAC,oBAAoB,SAAS,WAAW;CAE7C,CAAC;CAEH,MAAM,eAAe,IAAI,IAAI,gBAAgB;CAC7C,MAAM,iBAA2B,CAAC;CAElC,KAAK,MAAM,eAAe,cAAc;EACtC,MAAM,YAAY,SAAS,WAAW;EACtC,IAAI,CAAC,WACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,oBAAoB,SAAS;EAClE,IAAI,YAAY,UAAU;GACxB,IAAI,UACF,UAAU,WAAW;GAEvB,IAAI,UACF,UAAU,WAAW;EAEzB;EAEA,eAAe,KAAK,UAAU,SAAS,CAAC;CAC1C;CAEA,OAAO,EACL,oBAAoB,eAAe,KAAK,GAAG,EAC7C;AACF;AAEA,eAAe,sBACb,SAC4B;CAC5B,MAAM,aAAa,QAAQ,MAAM,IAAI;CAErC,IAAI,CAAC,YACH,OAAO,CAAC;CAGV,MAAM,UAAU,CAAC;CAEjB,KAAK,MAAM,EAAE,MAAM,SAAS,YAAY;EACtC,MAAM,YAAY,SAAS,GAAG;;EAE9B,IAAI,CAAC,WACH;EAIF,IAAI,CAAC,MACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,oBAAoB,SAAS;EAElE,MAAM,OAAO,KAAK,YAAY,CAAC,CAAC,QAAQ,cAAc,GAAG;EAEzD,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;EAGtD,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;CAExD;CAEA,OAAO,OAAO,YAAY,OAAO;AACnC"}
|
|
@@ -7,13 +7,13 @@ import { massage, parse } from "../../../util/toml.js";
|
|
|
7
7
|
import { deleteLocalFile, ensureCacheDir, getSiblingFileName, readLocalFile, writeLocalFile } from "../../../util/fs/index.js";
|
|
8
8
|
import { Result } from "../../../util/result.js";
|
|
9
9
|
import { getGoogleAuthHostRule } from "../../datasource/util.js";
|
|
10
|
-
import { getGitEnvironmentVariables } from "../../../util/git/auth.js";
|
|
11
|
-
import { exec } from "../../../util/exec/index.js";
|
|
12
10
|
import { PypiDatasource } from "../../datasource/pypi/index.js";
|
|
11
|
+
import { withGitEnvironment } from "../../../util/git/exec.js";
|
|
13
12
|
import { Lockfile, PoetryPyProject } from "./schema.js";
|
|
14
13
|
import { isNonEmptyArray, isNonEmptyObject, isString } from "@sindresorhus/is";
|
|
15
14
|
import { quote } from "shlex";
|
|
16
15
|
//#region lib/modules/manager/poetry/artifacts.ts
|
|
16
|
+
const gitExec = withGitEnvironment(["poetry"]);
|
|
17
17
|
function getPythonConstraint(pyProjectContent, existingLockFileContent) {
|
|
18
18
|
const pyprojectPythonConstraint = Result.parse(massage(pyProjectContent), PoetryPyProject.transform(({ packageFileContent }) => packageFileContent.deps.find((dep) => dep.depName === "python")?.currentValue)).unwrapOrNull();
|
|
19
19
|
if (pyprojectPythonConstraint) {
|
|
@@ -128,7 +128,6 @@ async function updateArtifacts({ packageFileName, updatedDeps, newPackageFileCon
|
|
|
128
128
|
cwdFile: packageFileName,
|
|
129
129
|
extraEnv: {
|
|
130
130
|
...await getSourceCredentialVars(newPackageFileContent, packageFileName),
|
|
131
|
-
...getGitEnvironmentVariables(["poetry"]),
|
|
132
131
|
PIP_CACHE_DIR: await ensureCacheDir("pip")
|
|
133
132
|
},
|
|
134
133
|
docker: {},
|
|
@@ -140,7 +139,7 @@ async function updateArtifacts({ packageFileName, updatedDeps, newPackageFileCon
|
|
|
140
139
|
constraint: poetryConstraint
|
|
141
140
|
}]
|
|
142
141
|
};
|
|
143
|
-
await
|
|
142
|
+
await gitExec(cmd, execOptions);
|
|
144
143
|
const newPoetryLockContent = await readLocalFile(lockFileName, "utf8");
|
|
145
144
|
if (existingLockFileContent === newPoetryLockContent) {
|
|
146
145
|
logger.debug(`${lockFileName} is unchanged`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":["massageToml","parseToml"],"sources":["../../../../lib/modules/manager/poetry/artifacts.ts"],"sourcesContent":["import { isNonEmptyArray, isNonEmptyObject, isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport type { HostRule } from '../../../types/index.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n deleteLocalFile,\n ensureCacheDir,\n getSiblingFileName,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { getGitEnvironmentVariables } from '../../../util/git/auth.ts';\nimport { find } from '../../../util/host-rules.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { Result } from '../../../util/result.ts';\nimport {\n massage as massageToml,\n parse as parseToml,\n} from '../../../util/toml.ts';\nimport { parseUrl } from '../../../util/url.ts';\nimport { PypiDatasource } from '../../datasource/pypi/index.ts';\nimport { getGoogleAuthHostRule } from '../../datasource/util.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { Lockfile, PoetryPyProject } from './schema.ts';\nimport type { PoetryFile, PoetrySource } from './types.ts';\n\nexport function getPythonConstraint(\n pyProjectContent: string,\n existingLockFileContent: string,\n): string | null {\n // Read Python version from `pyproject.toml` first as it could have been updated\n const pyprojectPythonConstraint = Result.parse(\n massageToml(pyProjectContent),\n PoetryPyProject.transform(\n ({ packageFileContent }) =>\n packageFileContent.deps.find((dep) => dep.depName === 'python')\n ?.currentValue,\n ),\n ).unwrapOrNull();\n if (pyprojectPythonConstraint) {\n logger.debug('Using python version from pyproject.toml');\n return pyprojectPythonConstraint;\n }\n\n const lockfilePythonConstraint = Result.parse(\n existingLockFileContent,\n Lockfile.transform(({ pythonVersions }) => pythonVersions),\n ).unwrapOrNull();\n if (lockfilePythonConstraint) {\n logger.debug('Using python version from poetry.lock');\n return lockfilePythonConstraint;\n }\n\n return null;\n}\n\nexport function getPoetryRequirement(\n pyProjectContent: string,\n existingLockFileContent: string,\n): undefined | string | null {\n // Read Poetry version from first line of poetry.lock\n const firstLine = existingLockFileContent.split('\\n')[0];\n const poetryVersionMatch = regEx(/by Poetry ([\\d\\\\.]+)/).exec(firstLine);\n if (poetryVersionMatch?.[1]) {\n const poetryVersion = poetryVersionMatch[1];\n logger.debug(\n `Using poetry version ${poetryVersion} from poetry.lock header`,\n );\n return poetryVersion;\n }\n\n const { val: lockfilePoetryConstraint } = Result.parse(\n existingLockFileContent,\n Lockfile.transform(({ poetryConstraint }) => poetryConstraint),\n ).unwrap();\n if (lockfilePoetryConstraint) {\n logger.debug(\n `Using poetry version ${lockfilePoetryConstraint} from poetry.lock metadata`,\n );\n return lockfilePoetryConstraint;\n }\n\n const { val: pyprojectPoetryConstraint } = Result.parse(\n massageToml(pyProjectContent),\n PoetryPyProject.transform(({ poetryRequirement }) => poetryRequirement),\n ).unwrap();\n if (pyprojectPoetryConstraint) {\n logger.debug(\n `Using poetry version ${pyprojectPoetryConstraint} from pyproject.toml`,\n );\n return pyprojectPoetryConstraint;\n }\n\n return null;\n}\n\nfunction getPoetrySources(content: string, fileName: string): PoetrySource[] {\n let pyprojectFile: PoetryFile;\n try {\n pyprojectFile = parseToml(massageToml(content)) as PoetryFile;\n } catch (err) {\n logger.debug({ err }, 'Error parsing pyproject.toml file');\n return [];\n }\n if (!pyprojectFile.tool?.poetry) {\n logger.debug(`${fileName} contains no poetry section`);\n return [];\n }\n\n const sources = pyprojectFile.tool?.poetry?.source ?? [];\n const sourceArray: PoetrySource[] = [];\n for (const source of sources) {\n if (source.name && source.url) {\n sourceArray.push({ name: source.name, url: source.url });\n }\n }\n return sourceArray;\n}\n\nasync function getMatchingHostRule(url: string | undefined): Promise<HostRule> {\n const scopedMatch = find({ hostType: PypiDatasource.id, url });\n const hostRule = isNonEmptyObject(scopedMatch) ? scopedMatch : find({ url });\n if (hostRule && Object.keys(hostRule).length !== 0) {\n return hostRule;\n }\n\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n logger.once.debug(`Failed to parse URL ${url}`);\n return {};\n }\n\n if (parsedUrl.hostname.endsWith('.pkg.dev')) {\n const hostRule = await getGoogleAuthHostRule();\n if (hostRule && Object.keys(hostRule).length !== 0) {\n return hostRule;\n }\n logger.once.debug(`Could not get Google access token (url=${url})`);\n }\n\n return {};\n}\n\nasync function getSourceCredentialVars(\n pyprojectContent: string,\n packageFileName: string,\n): Promise<NodeJS.ProcessEnv> {\n const poetrySources = getPoetrySources(pyprojectContent, packageFileName);\n const envVars: NodeJS.ProcessEnv = {};\n\n for (const source of poetrySources) {\n const matchingHostRule = await getMatchingHostRule(source.url);\n const formattedSourceName = source.name\n .replace(regEx(/(\\.|-)+/g), '_')\n .toUpperCase();\n if (matchingHostRule.username) {\n envVars[`POETRY_HTTP_BASIC_${formattedSourceName}_USERNAME`] =\n matchingHostRule.username;\n }\n if (matchingHostRule.password) {\n envVars[`POETRY_HTTP_BASIC_${formattedSourceName}_PASSWORD`] =\n matchingHostRule.password;\n }\n }\n return envVars;\n}\n\nexport async function updateArtifacts({\n packageFileName,\n updatedDeps,\n newPackageFileContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.debug(`poetry.updateArtifacts(${packageFileName})`);\n const { isLockFileMaintenance } = config;\n\n if (!isNonEmptyArray(updatedDeps) && !isLockFileMaintenance) {\n logger.debug('No updated poetry deps - returning null');\n return null;\n }\n // Try poetry.lock first\n let lockFileName = getSiblingFileName(packageFileName, 'poetry.lock');\n let existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n // Try pyproject.lock next\n lockFileName = getSiblingFileName(packageFileName, 'pyproject.lock');\n existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n logger.debug(`No lock file found`);\n return null;\n }\n }\n logger.debug(`Updating ${lockFileName}`);\n try {\n await writeLocalFile(packageFileName, newPackageFileContent);\n const cmd: string[] = [];\n if (isLockFileMaintenance) {\n await deleteLocalFile(lockFileName);\n cmd.push('poetry update --lock --no-interaction');\n } else {\n cmd.push(\n `poetry update --lock --no-interaction ${updatedDeps\n .map((dep) => dep.depName)\n .filter(isString)\n .map((dep) => quote(dep))\n .join(' ')}`,\n );\n }\n const pythonConstraint =\n config?.constraints?.python ??\n getPythonConstraint(newPackageFileContent, existingLockFileContent);\n const poetryConstraint =\n config.constraints?.poetry ??\n getPoetryRequirement(newPackageFileContent, existingLockFileContent);\n const extraEnv = {\n ...(await getSourceCredentialVars(\n newPackageFileContent,\n packageFileName,\n )),\n ...getGitEnvironmentVariables(['poetry']),\n PIP_CACHE_DIR: await ensureCacheDir('pip'),\n };\n\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n extraEnv,\n docker: {},\n toolConstraints: [\n { toolName: 'python', constraint: pythonConstraint },\n { toolName: 'poetry', constraint: poetryConstraint },\n ],\n };\n await exec(cmd, execOptions);\n const newPoetryLockContent = await readLocalFile(lockFileName, 'utf8');\n if (existingLockFileContent === newPoetryLockContent) {\n logger.debug(`${lockFileName} is unchanged`);\n return null;\n }\n logger.debug(`Returning updated ${lockFileName}`);\n return [\n {\n file: {\n type: 'addition',\n path: lockFileName,\n contents: newPoetryLockContent,\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 ${lockFileName} file`);\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: `${String(err.stdout)}\\n${String(err.stderr)}`,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,SAAgB,oBACd,kBACA,yBACe;CAEf,MAAM,4BAA4B,OAAO,MACvCA,QAAY,gBAAgB,GAC5B,gBAAgB,WACb,EAAE,yBACD,mBAAmB,KAAK,MAAM,QAAQ,IAAI,YAAY,QAAQ,CAAC,EAC3D,YACR,CACF,CAAC,CAAC,aAAa;CACf,IAAI,2BAA2B;EAC7B,OAAO,MAAM,0C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c;GAC3C,OAAO;EACT;EACA,OAAO,MAAM,qBAAqB,cAAc;EAChD,OAAO,CACL,EACE,MAAM;GACJ,MAAM;GACN,MAAM;GACN,UAAU;EACZ,EACF,CACF;CACF,SAAS,KAAK;;EAEZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAER,OAAO,MAAM,EAAE,IAAI,GAAG,oBAAoB,aAAa,MAAM;EAC7D,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,GAAG,OAAO,IAAI,MAAM,EAAE,IAAI,OAAO,IAAI,MAAM;EACrD,EACF,CACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":["massageToml","parseToml"],"sources":["../../../../lib/modules/manager/poetry/artifacts.ts"],"sourcesContent":["import { isNonEmptyArray, isNonEmptyObject, isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport type { HostRule } from '../../../types/index.ts';\nimport type { ExecOptions } from '../../../util/exec/types.ts';\nimport {\n deleteLocalFile,\n ensureCacheDir,\n getSiblingFileName,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../util/git/exec.ts';\nimport { find } from '../../../util/host-rules.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { Result } from '../../../util/result.ts';\nimport {\n massage as massageToml,\n parse as parseToml,\n} from '../../../util/toml.ts';\nimport { parseUrl } from '../../../util/url.ts';\nimport { PypiDatasource } from '../../datasource/pypi/index.ts';\nimport { getGoogleAuthHostRule } from '../../datasource/util.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { Lockfile, PoetryPyProject } from './schema.ts';\nimport type { PoetryFile, PoetrySource } from './types.ts';\n\nconst gitExec = withGitEnvironment(['poetry']);\n\nexport function getPythonConstraint(\n pyProjectContent: string,\n existingLockFileContent: string,\n): string | null {\n // Read Python version from `pyproject.toml` first as it could have been updated\n const pyprojectPythonConstraint = Result.parse(\n massageToml(pyProjectContent),\n PoetryPyProject.transform(\n ({ packageFileContent }) =>\n packageFileContent.deps.find((dep) => dep.depName === 'python')\n ?.currentValue,\n ),\n ).unwrapOrNull();\n if (pyprojectPythonConstraint) {\n logger.debug('Using python version from pyproject.toml');\n return pyprojectPythonConstraint;\n }\n\n const lockfilePythonConstraint = Result.parse(\n existingLockFileContent,\n Lockfile.transform(({ pythonVersions }) => pythonVersions),\n ).unwrapOrNull();\n if (lockfilePythonConstraint) {\n logger.debug('Using python version from poetry.lock');\n return lockfilePythonConstraint;\n }\n\n return null;\n}\n\nexport function getPoetryRequirement(\n pyProjectContent: string,\n existingLockFileContent: string,\n): undefined | string | null {\n // Read Poetry version from first line of poetry.lock\n const firstLine = existingLockFileContent.split('\\n')[0];\n const poetryVersionMatch = regEx(/by Poetry ([\\d\\\\.]+)/).exec(firstLine);\n if (poetryVersionMatch?.[1]) {\n const poetryVersion = poetryVersionMatch[1];\n logger.debug(\n `Using poetry version ${poetryVersion} from poetry.lock header`,\n );\n return poetryVersion;\n }\n\n const { val: lockfilePoetryConstraint } = Result.parse(\n existingLockFileContent,\n Lockfile.transform(({ poetryConstraint }) => poetryConstraint),\n ).unwrap();\n if (lockfilePoetryConstraint) {\n logger.debug(\n `Using poetry version ${lockfilePoetryConstraint} from poetry.lock metadata`,\n );\n return lockfilePoetryConstraint;\n }\n\n const { val: pyprojectPoetryConstraint } = Result.parse(\n massageToml(pyProjectContent),\n PoetryPyProject.transform(({ poetryRequirement }) => poetryRequirement),\n ).unwrap();\n if (pyprojectPoetryConstraint) {\n logger.debug(\n `Using poetry version ${pyprojectPoetryConstraint} from pyproject.toml`,\n );\n return pyprojectPoetryConstraint;\n }\n\n return null;\n}\n\nfunction getPoetrySources(content: string, fileName: string): PoetrySource[] {\n let pyprojectFile: PoetryFile;\n try {\n pyprojectFile = parseToml(massageToml(content)) as PoetryFile;\n } catch (err) {\n logger.debug({ err }, 'Error parsing pyproject.toml file');\n return [];\n }\n if (!pyprojectFile.tool?.poetry) {\n logger.debug(`${fileName} contains no poetry section`);\n return [];\n }\n\n const sources = pyprojectFile.tool?.poetry?.source ?? [];\n const sourceArray: PoetrySource[] = [];\n for (const source of sources) {\n if (source.name && source.url) {\n sourceArray.push({ name: source.name, url: source.url });\n }\n }\n return sourceArray;\n}\n\nasync function getMatchingHostRule(url: string | undefined): Promise<HostRule> {\n const scopedMatch = find({ hostType: PypiDatasource.id, url });\n const hostRule = isNonEmptyObject(scopedMatch) ? scopedMatch : find({ url });\n if (hostRule && Object.keys(hostRule).length !== 0) {\n return hostRule;\n }\n\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n logger.once.debug(`Failed to parse URL ${url}`);\n return {};\n }\n\n if (parsedUrl.hostname.endsWith('.pkg.dev')) {\n const hostRule = await getGoogleAuthHostRule();\n if (hostRule && Object.keys(hostRule).length !== 0) {\n return hostRule;\n }\n logger.once.debug(`Could not get Google access token (url=${url})`);\n }\n\n return {};\n}\n\nasync function getSourceCredentialVars(\n pyprojectContent: string,\n packageFileName: string,\n): Promise<NodeJS.ProcessEnv> {\n const poetrySources = getPoetrySources(pyprojectContent, packageFileName);\n const envVars: NodeJS.ProcessEnv = {};\n\n for (const source of poetrySources) {\n const matchingHostRule = await getMatchingHostRule(source.url);\n const formattedSourceName = source.name\n .replace(regEx(/(\\.|-)+/g), '_')\n .toUpperCase();\n if (matchingHostRule.username) {\n envVars[`POETRY_HTTP_BASIC_${formattedSourceName}_USERNAME`] =\n matchingHostRule.username;\n }\n if (matchingHostRule.password) {\n envVars[`POETRY_HTTP_BASIC_${formattedSourceName}_PASSWORD`] =\n matchingHostRule.password;\n }\n }\n return envVars;\n}\n\nexport async function updateArtifacts({\n packageFileName,\n updatedDeps,\n newPackageFileContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.debug(`poetry.updateArtifacts(${packageFileName})`);\n const { isLockFileMaintenance } = config;\n\n if (!isNonEmptyArray(updatedDeps) && !isLockFileMaintenance) {\n logger.debug('No updated poetry deps - returning null');\n return null;\n }\n // Try poetry.lock first\n let lockFileName = getSiblingFileName(packageFileName, 'poetry.lock');\n let existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n // Try pyproject.lock next\n lockFileName = getSiblingFileName(packageFileName, 'pyproject.lock');\n existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n logger.debug(`No lock file found`);\n return null;\n }\n }\n logger.debug(`Updating ${lockFileName}`);\n try {\n await writeLocalFile(packageFileName, newPackageFileContent);\n const cmd: string[] = [];\n if (isLockFileMaintenance) {\n await deleteLocalFile(lockFileName);\n cmd.push('poetry update --lock --no-interaction');\n } else {\n cmd.push(\n `poetry update --lock --no-interaction ${updatedDeps\n .map((dep) => dep.depName)\n .filter(isString)\n .map((dep) => quote(dep))\n .join(' ')}`,\n );\n }\n const pythonConstraint =\n config?.constraints?.python ??\n getPythonConstraint(newPackageFileContent, existingLockFileContent);\n const poetryConstraint =\n config.constraints?.poetry ??\n getPoetryRequirement(newPackageFileContent, existingLockFileContent);\n const extraEnv = {\n ...(await getSourceCredentialVars(\n newPackageFileContent,\n packageFileName,\n )),\n PIP_CACHE_DIR: await ensureCacheDir('pip'),\n };\n\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n extraEnv,\n docker: {},\n toolConstraints: [\n { toolName: 'python', constraint: pythonConstraint },\n { toolName: 'poetry', constraint: poetryConstraint },\n ],\n };\n await gitExec(cmd, execOptions);\n const newPoetryLockContent = await readLocalFile(lockFileName, 'utf8');\n if (existingLockFileContent === newPoetryLockContent) {\n logger.debug(`${lockFileName} is unchanged`);\n return null;\n }\n logger.debug(`Returning updated ${lockFileName}`);\n return [\n {\n file: {\n type: 'addition',\n path: lockFileName,\n contents: newPoetryLockContent,\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 ${lockFileName} file`);\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: `${String(err.stdout)}\\n${String(err.stderr)}`,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAM,UAAU,mBAAmB,CAAC,QAAQ,CAAC;AAE7C,SAAgB,oBACd,kBACA,yBACe;CAEf,MAAM,4BAA4B,OAAO,MACvCA,QAAY,gBAAgB,GAC5B,gBAAgB,WACb,EAAE,yBACD,mBAAmB,KAAK,MAAM,QAAQ,IAAI,YAAY,QAAQ,CAAC,EAC3D,YACR,CACF,CAAC,CAAC,aAAa;CACf,IAAI,2BAA2B;EAC7B,OAAO,MAAM,0CAA0C;EACvD,OAAO;CACT;CAEA,MAAM,2BAA2B,OAAO,MACtC,yBACA,SAAS,WAAW,EAAE,qBAAqB,cAAc,CAC3D,CAAC,CAAC,aAAa;CACf,IAAI,0BAA0B;EAC5B,OAAO,MAAM,uCAAuC;EACpD,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAgB,qBACd,kBACA,yBAC2B;CAE3B,MAAM,YAAY,wBAAwB,MAAM,IAAI,CAAC,CAAC;CACtD,MAAM,qBAAqB,MAAM,sBAAsB,CAAC,CAAC,KAAK,SAAS;CACvE,IAAI,qBAAqB,IAAI;EAC3B,MAAM,gBAAgB,mBAAmB;EACzC,OAAO,MACL,wBAAwB,cAAc,yBACxC;EACA,OAAO;CACT;CAEA,MAAM,EAAE,KAAK,6BAA6B,OAAO,MAC/C,yBACA,SAAS,WAAW,EAAE,uBAAuB,gBAAgB,CAC/D,CAAC,CAAC,OAAO;CACT,IAAI,0BAA0B;EAC5B,OAAO,MACL,wBAAwB,yBAAyB,2BACnD;EACA,OAAO;CACT;CAEA,MAAM,EAAE,KAAK,8BAA8B,OAAO,MAChDA,QAAY,gBAAgB,GAC5B,gBAAgB,WAAW,EAAE,wBAAwB,iBAAiB,CACxE,CAAC,CAAC,OAAO;CACT,IAAI,2BAA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AAa,UACpB,qBAAqB,uBAAuB,uBAAuB;EASrE,MAAM,cAA2B;GAC/B,SAAS;GACT,UAAA;IATA,GAAI,MAAM,wBACR,uBACA,eACF;IACA,eAAe,MAAM,eAAe,KAAK;GAKlC;GACP,QAAQ,CAAC;GACT,iBAAiB,CACf;IAAE,UAAU;IAAU,YAAY;GAAiB,GACnD;IAAE,UAAU;IAAU,YAAY;GAAiB,CACrD;EACF;EACA,MAAM,QAAQ,KAAK,WAAW;EAC9B,MAAM,uBAAuB,MAAM,cAAc,cAAc,MAAM;EACrE,IAAI,4BAA4B,sBAAsB;GACpD,OAAO,MAAM,GAAG,aAAa,cAAc;GAC3C,OAAO;EACT;EACA,OAAO,MAAM,qBAAqB,cAAc;EAChD,OAAO,CACL,EACE,MAAM;GACJ,MAAM;GACN,MAAM;GACN,UAAU;EACZ,EACF,CACF;CACF,SAAS,KAAK;;EAEZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAER,OAAO,MAAM,EAAE,IAAI,GAAG,oBAAoB,aAAa,MAAM;EAC7D,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,GAAG,OAAO,IAAI,MAAM,EAAE,IAAI,OAAO,IAAI,MAAM;EACrD,EACF,CACF;CACF;AACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "../../../constants/error-messages.js";
|
|
2
2
|
import { logger } from "../../../logger/index.js";
|
|
3
3
|
import { getParentDir, getSiblingFileName, readLocalFile, writeLocalFile } from "../../../util/fs/index.js";
|
|
4
|
-
import { getGitEnvironmentVariables } from "../../../util/git/auth.js";
|
|
5
|
-
import { exec } from "../../../util/exec/index.js";
|
|
6
4
|
import { getRepoStatus } from "../../../util/git/index.js";
|
|
5
|
+
import { withGitEnvironment } from "../../../util/git/exec.js";
|
|
7
6
|
//#region lib/modules/manager/vendir/artifacts.ts
|
|
7
|
+
const gitExec = withGitEnvironment();
|
|
8
8
|
async function updateArtifacts({ packageFileName, newPackageFileContent, config }) {
|
|
9
9
|
logger.debug(`vendir.updateArtifacts(${packageFileName})`);
|
|
10
10
|
const lockFileName = getSiblingFileName(packageFileName, "vendir.lock.yml");
|
|
@@ -21,7 +21,6 @@ async function updateArtifacts({ packageFileName, newPackageFileContent, config
|
|
|
21
21
|
await writeLocalFile(packageFileName, newPackageFileContent);
|
|
22
22
|
logger.debug("Updating Vendir artifacts");
|
|
23
23
|
const execOptions = {
|
|
24
|
-
extraEnv: { ...getGitEnvironmentVariables([]) },
|
|
25
24
|
cwdFile: packageFileName,
|
|
26
25
|
docker: {},
|
|
27
26
|
toolConstraints: [{
|
|
@@ -32,7 +31,7 @@ async function updateArtifacts({ packageFileName, newPackageFileContent, config
|
|
|
32
31
|
constraint: config.constraints?.helm
|
|
33
32
|
}]
|
|
34
33
|
};
|
|
35
|
-
await
|
|
34
|
+
await gitExec(`vendir sync`, execOptions);
|
|
36
35
|
logger.debug("Returning updated Vendir artifacts");
|
|
37
36
|
const fileChanges = [];
|
|
38
37
|
const newVendirLockContent = await readLocalFile(lockFileName, "utf8");
|