feat(bazel): Support for rules_oci / oci_pull (#21216)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Malte Poll 2023-03-30 22:37:52 +02:00 committed by GitHub
parent 9257f3ca2e
commit 480cff54ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 1 deletions

View file

@ -11,7 +11,7 @@ Renovate supports upgrading dependencies in Bazel `WORKSPACE` files.
1. Bazel support is enabled automatically 1. Bazel support is enabled automatically
2. Renovate will search repositories for any `WORKSPACE` files in the repository 2. Renovate will search repositories for any `WORKSPACE` files in the repository
3. Existing dependencies will be extracted from `container_pull`, `git_repository`, `go_repository`, `maven_install`, and `http_archive`/`http_file` declarations 3. Existing dependencies will be extracted from `container_pull`, `oci_pull`, `git_repository`, `go_repository`, `maven_install`, and `http_archive`/`http_file` declarations
4. Renovate will replace any old versions with the latest version available 4. Renovate will replace any old versions with the latest version available
## git_repository ## git_repository

View file

@ -87,6 +87,29 @@ describe('modules/manager/bazel/extract', () => {
]); ]);
}); });
it('extracts dependencies for oci_pull deptype', () => {
const res = extractPackageFile(
codeBlock`
oci_pull(
name="hasura",
image="index.docker.io/hasura/graphql-engine",
# v1.0.0-alpha31.cli-migrations 11/28
digest="sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548",
tag="v1.0.0-alpha31.cli-migrations"
)
`
);
expect(res?.deps).toMatchObject([
{
currentDigest:
'sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548',
currentValue: 'v1.0.0-alpha31.cli-migrations',
depType: 'oci_pull',
packageName: 'index.docker.io/hasura/graphql-engine',
},
]);
});
it('check remote option in go_repository', () => { it('check remote option in go_repository', () => {
const successStory = extractPackageFile( const successStory = extractPackageFile(
codeBlock` codeBlock`

View file

@ -24,6 +24,7 @@ export function extractPackageFile(
const replaceString = fragment.value; const replaceString = fragment.value;
if ( if (
replaceString.startsWith('container_pull') || replaceString.startsWith('container_pull') ||
replaceString.startsWith('oci_pull') ||
replaceString.startsWith('git_repository') || replaceString.startsWith('git_repository') ||
replaceString.startsWith('go_repository') replaceString.startsWith('go_repository')
) { ) {

View file

@ -349,6 +349,34 @@ describe('modules/manager/bazel/rules/index', () => {
}); });
}); });
describe('oci', () => {
it('extracts oci dependencies', () => {
expect(
extractDepsFromFragmentData({ rule: 'foo_bar', name: 'foo_bar' })
).toBeEmptyArray();
expect(
extractDepsFromFragmentData({
rule: 'oci_pull',
name: 'foo_bar',
tag: '1.2.3',
digest: 'abcdef0123abcdef0123abcdef0123abcdef0123',
image: 'example.com/foo/bar',
})
).toEqual([
{
currentDigest: 'abcdef0123abcdef0123abcdef0123abcdef0123',
currentValue: '1.2.3',
datasource: 'docker',
depName: 'foo_bar',
depType: 'oci_pull',
packageName: 'example.com/foo/bar',
versioning: 'docker',
},
]);
});
});
describe('maven', () => { describe('maven', () => {
it('extracts maven dependencies', () => { it('extracts maven dependencies', () => {
expect( expect(

View file

@ -7,9 +7,11 @@ import { GitTarget, gitRules } from './git';
import { GoTarget, goRules } from './go'; import { GoTarget, goRules } from './go';
import { HttpTarget, httpRules } from './http'; import { HttpTarget, httpRules } from './http';
import { MavenTarget, mavenRules } from './maven'; import { MavenTarget, mavenRules } from './maven';
import { OciTarget, ociRules } from './oci';
const Target = z.union([ const Target = z.union([
DockerTarget, DockerTarget,
OciTarget,
GitTarget, GitTarget,
GoTarget, GoTarget,
HttpTarget, HttpTarget,
@ -22,6 +24,7 @@ const Target = z.union([
*/ */
const supportedRules = [ const supportedRules = [
...dockerRules, ...dockerRules,
...ociRules,
...gitRules, ...gitRules,
...goRules, ...goRules,
...httpRules, ...httpRules,

View file

@ -0,0 +1,26 @@
import { z } from 'zod';
import { DockerDatasource } from '../../../datasource/docker';
import { id as dockerVersioning } from '../../../versioning/docker';
import type { PackageDependency } from '../../types';
export const ociRules = ['oci_pull'] as const;
export const OciTarget = z
.object({
rule: z.enum(ociRules),
name: z.string(),
image: z.string(),
tag: z.string().optional(),
digest: z.string().optional(),
})
.transform(({ rule, name, image, tag, digest }): PackageDependency[] => [
{
datasource: DockerDatasource.id,
versioning: dockerVersioning,
depType: rule,
depName: name,
packageName: image,
currentValue: tag,
currentDigest: digest,
},
]);