Skip to content

Commit

Permalink
feat(poetry): perform git login (#25178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadus committed Oct 12, 2023
1 parent 91fa40a commit 63fbc76
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
92 changes: 91 additions & 1 deletion lib/modules/manager/poetry/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('modules/manager/poetry/artifacts', () => {
describe('updateArtifacts', () => {
beforeEach(() => {
env.getChildProcessEnv.mockReturnValue(envMock.basic);
hostRules.getAll.mockReturnValue([]);
GlobalConfig.set(adminConfig);
docker.resetPrefetchedImages();
});
Expand Down Expand Up @@ -197,7 +198,7 @@ describe('modules/manager/poetry/artifacts', () => {
},
},
]);
expect(hostRules.find.mock.calls).toHaveLength(4);
expect(hostRules.find.mock.calls).toHaveLength(5);
expect(execSnapshots).toMatchObject([
{ cmd: 'poetry update --lock --no-interaction dep1' },
]);
Expand Down Expand Up @@ -338,6 +339,95 @@ describe('modules/manager/poetry/artifacts', () => {
]);
});

it('supports docker mode with github credentials', async () => {
GlobalConfig.set({
...adminConfig,
binarySource: 'docker',
dockerSidecarImage: 'ghcr.io/containerbase/sidecar',
});
hostRules.find.mockReturnValueOnce({
token: 'some-token',
});
hostRules.getAll.mockReturnValueOnce([
{
token: 'some-token',
hostType: 'github',
matchHost: 'api.github.com',
},
{ token: 'some-other-token', matchHost: 'https://gitea.com' },
]);
const execSnapshots = mockExecAll();
fs.ensureCacheDir.mockResolvedValueOnce('/tmp/renovate/cache/others/pip');
// poetry.lock
fs.getSiblingFileName.mockReturnValueOnce('poetry.lock');
fs.readLocalFile.mockResolvedValueOnce('[metadata]\n');
fs.readLocalFile.mockResolvedValueOnce('New poetry.lock');
// python
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: '2.7.5' }, { version: '3.4.2' }],
});
// poetry
datasource.getPkgReleases.mockResolvedValueOnce({
releases: [{ version: '1.2.0' }],
});
const updatedDeps = [{ depName: 'dep1' }];
expect(
await updateArtifacts({
packageFileName: 'pyproject.toml',
updatedDeps,
newPackageFileContent: pyproject1toml,
config: {
...config,
constraints: {
python: '~2.7 || ^3.4',
},
},
})
).toEqual([
{
file: {
type: 'addition',
path: 'poetry.lock',
contents: 'New poetry.lock',
},
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'docker pull ghcr.io/containerbase/sidecar' },
{ cmd: 'docker ps --filter name=renovate_sidecar -aq' },
{
cmd:
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/cache":"/tmp/cache" ' +
'-e GIT_CONFIG_KEY_0 ' +
'-e GIT_CONFIG_VALUE_0 ' +
'-e GIT_CONFIG_KEY_1 ' +
'-e GIT_CONFIG_VALUE_1 ' +
'-e GIT_CONFIG_KEY_2 ' +
'-e GIT_CONFIG_VALUE_2 ' +
'-e GIT_CONFIG_COUNT ' +
'-e GIT_CONFIG_KEY_3 ' +
'-e GIT_CONFIG_VALUE_3 ' +
'-e GIT_CONFIG_KEY_4 ' +
'-e GIT_CONFIG_VALUE_4 ' +
'-e GIT_CONFIG_KEY_5 ' +
'-e GIT_CONFIG_VALUE_5 ' +
'-e PIP_CACHE_DIR ' +
'-e CONTAINERBASE_CACHE_DIR ' +
'-w "/tmp/github/some/repo" ' +
'ghcr.io/containerbase/sidecar ' +
'bash -l -c "' +
'install-tool python 3.4.2 ' +
'&& ' +
'install-tool poetry 1.2.0 ' +
'&& ' +
'poetry update --lock --no-interaction dep1' +
'"',
},
]);
});

it('returns updated poetry.lock using docker (constraints)', async () => {
GlobalConfig.set({
...adminConfig,
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/manager/poetry/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
readLocalFile,
writeLocalFile,
} from '../../../util/fs';
import { getGitEnvironmentVariables } from '../../../util/git/auth';
import { find } from '../../../util/host-rules';
import { regEx } from '../../../util/regex';
import { Result } from '../../../util/result';
Expand Down Expand Up @@ -115,9 +116,9 @@ function getMatchingHostRule(url: string | undefined): HostRule {
function getSourceCredentialVars(
pyprojectContent: string,
packageFileName: string
): Record<string, string> {
): NodeJS.ProcessEnv {
const poetrySources = getPoetrySources(pyprojectContent, packageFileName);
const envVars: Record<string, string> = {};
const envVars: NodeJS.ProcessEnv = {};

for (const source of poetrySources) {
const matchingHostRule = getMatchingHostRule(source.url);
Expand Down Expand Up @@ -185,6 +186,7 @@ export async function updateArtifacts({
getPoetryRequirement(newPackageFileContent, existingLockFileContent);
const extraEnv = {
...getSourceCredentialVars(newPackageFileContent, packageFileName),
...getGitEnvironmentVariables(['poetry']),
PIP_CACHE_DIR: await ensureCacheDir('pip'),
};

Expand Down

0 comments on commit 63fbc76

Please sign in to comment.