Skip to content

Commit

Permalink
feat(bazel): Support for rules_oci / oci_pull (#21216)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
malt3 and viceice committed Mar 30, 2023
1 parent 9257f3c commit 480cff5
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/usage/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Renovate supports upgrading dependencies in Bazel `WORKSPACE` files.

1. Bazel support is enabled automatically
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

## git_repository
Expand Down
23 changes: 23 additions & 0 deletions lib/modules/manager/bazel/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
const successStory = extractPackageFile(
codeBlock`
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/bazel/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function extractPackageFile(
const replaceString = fragment.value;
if (
replaceString.startsWith('container_pull') ||
replaceString.startsWith('oci_pull') ||
replaceString.startsWith('git_repository') ||
replaceString.startsWith('go_repository')
) {
Expand Down
28 changes: 28 additions & 0 deletions lib/modules/manager/bazel/rules/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
it('extracts maven dependencies', () => {
expect(
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/manager/bazel/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { GitTarget, gitRules } from './git';
import { GoTarget, goRules } from './go';
import { HttpTarget, httpRules } from './http';
import { MavenTarget, mavenRules } from './maven';
import { OciTarget, ociRules } from './oci';

const Target = z.union([
DockerTarget,
OciTarget,
GitTarget,
GoTarget,
HttpTarget,
Expand All @@ -22,6 +24,7 @@ const Target = z.union([
*/
const supportedRules = [
...dockerRules,
...ociRules,
...gitRules,
...goRules,
...httpRules,
Expand Down
26 changes: 26 additions & 0 deletions lib/modules/manager/bazel/rules/oci.ts
Original file line number Diff line number Diff line change
@@ -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,
},
]);

0 comments on commit 480cff5

Please sign in to comment.