From 90d9cd7dca20f274b8a1403de8a97070f2bb5a29 Mon Sep 17 00:00:00 2001 From: Fabian Heib <151526715+fabian-heib@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:52:30 +0100 Subject: [PATCH] feat(tekton): support pipelinesascode annotation (#26753) Co-authored-by: Michael Kriese --- .../__fixtures__/multi-doc-annotations.yaml | 5 ++++ lib/modules/manager/tekton/extract.spec.ts | 28 +++++++++++++++++++ lib/modules/manager/tekton/extract.ts | 12 ++++---- lib/modules/manager/tekton/readme.md | 7 +++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/lib/modules/manager/tekton/__fixtures__/multi-doc-annotations.yaml b/lib/modules/manager/tekton/__fixtures__/multi-doc-annotations.yaml index 70ad497472769c..7e4c15549bf993 100644 --- a/lib/modules/manager/tekton/__fixtures__/multi-doc-annotations.yaml +++ b/lib/modules/manager/tekton/__fixtures__/multi-doc-annotations.yaml @@ -4,18 +4,22 @@ metadata: annotations: pipelinesascode.tekton.dev/on-event: "[pull_request]" pipelinesascode.tekton.dev/task: "[git-clone,https://github.com/foo/bar/releases/download/v0.0.4/stakater-create-git-tag.yaml]" + pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/foo/baz/v0.0.12/pipeline/deploy/deploy.yaml" --- kind: PipelineRun metadata: annotations: pipelinesascode.tekton.dev/task: "[git-clone, https://raw.githubusercontent.com/foo/bar/v0.0.6/tasks/create-git-tag/create-git-tag.yaml]" + pipelinesascode.tekton.dev/pipeline: " + https://raw.githubusercontent.com/foo/baz/v0.0.12/pipeline/deploy/deploy.yaml" --- kind: PipelineRun metadata: annotations: pipelinesascode.tekton.dev/task: "git-clone" pipelinesascode.tekton.dev/task-1: "https://github.com/foo/bar/raw/v0.0.8/tasks/create-git-tag/create-git-tag.yaml" + pipelinesascode.tekton.dev/pipeline: "https://github.com/foo/baz/raw/v0.0.14/pipeline/deploy/deploy.yaml" --- kind: PipelineRun metadata: @@ -24,3 +28,4 @@ metadata: https://github.com/foo/bar/releases/download/v0.0.9/stakater-create-git-tag.yaml, https://github.com/foo/bar/raw/v0.0.7/tasks/create-git-tag/create-git-tag.yaml, https://raw.githubusercontent.com/foo/bar/v0.0.5/tasks/create-git-tag/create-git-tag.yaml]" + pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/foo/baz/v0.0.25/pipeline/deploy/deploy.yaml" diff --git a/lib/modules/manager/tekton/extract.spec.ts b/lib/modules/manager/tekton/extract.spec.ts index 449fe10217d8a4..092ce1728dfbbc 100644 --- a/lib/modules/manager/tekton/extract.spec.ts +++ b/lib/modules/manager/tekton/extract.spec.ts @@ -26,6 +26,13 @@ describe('modules/manager/tekton/extract', () => { depType: 'tekton-annotation', packageName: 'foo/bar', }, + { + currentValue: 'v0.0.12', + datasource: 'git-tags', + depName: 'github.com/foo/baz', + depType: 'tekton-annotation', + packageName: 'https://github.com/foo/baz', + }, { currentValue: 'v0.0.6', datasource: 'git-tags', @@ -33,6 +40,13 @@ describe('modules/manager/tekton/extract', () => { depType: 'tekton-annotation', packageName: 'https://github.com/foo/bar', }, + { + currentValue: 'v0.0.12', + datasource: 'git-tags', + depName: 'github.com/foo/baz', + depType: 'tekton-annotation', + packageName: 'https://github.com/foo/baz', + }, { currentValue: 'v0.0.8', datasource: 'git-tags', @@ -40,6 +54,13 @@ describe('modules/manager/tekton/extract', () => { depType: 'tekton-annotation', packageName: 'https://github.com/foo/bar', }, + { + currentValue: 'v0.0.14', + datasource: 'git-tags', + depName: 'github.com/foo/baz', + depType: 'tekton-annotation', + packageName: 'https://github.com/foo/baz', + }, { currentValue: 'v0.0.9', datasource: 'github-releases', @@ -61,6 +82,13 @@ describe('modules/manager/tekton/extract', () => { depType: 'tekton-annotation', packageName: 'https://github.com/foo/bar', }, + { + currentValue: 'v0.0.25', + datasource: 'git-tags', + depName: 'github.com/foo/baz', + depType: 'tekton-annotation', + packageName: 'https://github.com/foo/baz', + }, ], }); }); diff --git a/lib/modules/manager/tekton/extract.ts b/lib/modules/manager/tekton/extract.ts index a61c78745a0254..990ffb00e30f76 100644 --- a/lib/modules/manager/tekton/extract.ts +++ b/lib/modules/manager/tekton/extract.ts @@ -86,7 +86,9 @@ function getDeps(doc: TektonResource): PackageDependency[] { return deps; } -const taskAnnotation = regEx(/^pipelinesascode\.tekton\.dev\/task(-[0-9]+)?$/); +const annotationRegex = regEx( + /^pipelinesascode\.tekton\.dev\/(?:task(-[0-9]+)?|pipeline)$/, +); function addPipelineAsCodeAnnotations( annotations: Record | undefined | null, @@ -97,16 +99,16 @@ function addPipelineAsCodeAnnotations( } for (const [key, value] of Object.entries(annotations)) { - if (!taskAnnotation.test(key)) { + if (!annotationRegex.test(key)) { continue; } - const tasks = value + const values = value .replace(regEx(/]$/), '') .replace(regEx(/^\[/), '') .split(','); - for (const task of tasks) { - const dep = getAnnotationDep(task.trim()); + for (const value of values) { + const dep = getAnnotationDep(value.trim()); if (!dep) { continue; } diff --git a/lib/modules/manager/tekton/readme.md b/lib/modules/manager/tekton/readme.md index 9e0f08f219e051..ed59c0601936bc 100644 --- a/lib/modules/manager/tekton/readme.md +++ b/lib/modules/manager/tekton/readme.md @@ -17,15 +17,16 @@ Read the [Tekton Pipeline remote resolution docs](https://tekton.dev/docs/pipeli ### Using a PipelinesAsCode remote URL reference -By specifying the annotation with a remote task based on the recommended way using [git based versioning](https://github.com/tektoncd/community/blob/main/teps/0115-tekton-catalog-git-based-versioning.md). How this can be used can be seen in the example below. +By specifying the annotation with a remote task or a remote pipeline based on the recommended way using [git based versioning](https://github.com/tektoncd/community/blob/main/teps/0115-tekton-catalog-git-based-versioning.md). How this can be used can be seen in the example below. -```yaml title="How an annotation in could look like in an pipeline-run.yaml" +```yaml title="How an annotation could look like in an pipeline-run.yaml" apiVersion: tekton.dev/v1 kind: PipelineRun metadata: name: main annotations: - pipelinesascode.tekton.dev/task: 'https://github.com/foo/bar/raw/v0.0.1/tasks/task/task.yaml' + pipelinesascode.tekton.dev/task: 'https://github.com/foo/bar/raw/v0.0.1/task/my-task/my-task.yaml' + pipelinesascode.tekton.dev/pipeline: 'https://github.com/foo/bar/raw/v0.0.1/pipeline/my-pipeline/my-pipeline.yaml' ``` Supported URLs: