Skip to content

Commit

Permalink
feat(tekton): support pipelinesascode annotation (#26753)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
fabian-heib and viceice committed Feb 27, 2024
1 parent 5de12e7 commit 90d9cd7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
Expand Up @@ -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:
Expand All @@ -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"
28 changes: 28 additions & 0 deletions lib/modules/manager/tekton/extract.spec.ts
Expand Up @@ -26,20 +26,41 @@ 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',
depName: 'github.com/foo/bar',
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',
depName: 'github.com/foo/bar',
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',
Expand All @@ -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',
},
],
});
});
Expand Down
12 changes: 7 additions & 5 deletions lib/modules/manager/tekton/extract.ts
Expand Up @@ -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<string, string> | undefined | null,
Expand All @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions lib/modules/manager/tekton/readme.md
Expand Up @@ -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:
Expand Down

0 comments on commit 90d9cd7

Please sign in to comment.