Skip to content

Commit 4fad6c8

Browse files
authored
Add support for v1beta1 API (#245)
* #183 use TS script to generate snippets, add snippets for new resources Signed-off-by: Yevhen Vydolob <[email protected]> * Migrate all snippets to 'v1beta1' version Signed-off-by: Yevhen Vydolob <[email protected]>
1 parent 878c849 commit 4fad6c8

26 files changed

+562
-410
lines changed

CONTRIBUTING.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ There are only a few guidelines that we need contributors to follow and we are o
3131

3232
4. Once the extension is installed and reloaded, you should see a Tekton Icon on the View Container, as shown in the image below.
3333

34-
![View Tekton Pipelines](https://github.com/redhat-developer/vscode-tekton/blob/master/images/view-container-icon.png)
34+
![View Tekton Pipelines](https://github.com/redhat-developer/vscode-tekton/blob/master/images/tekton.svg)
3535

36-
> If you have any questions or run into any problems, please post an [issue](issues) - we'll be very happy to help.
36+
> If you have any questions or run into any problems, please post an [issue](issues) - we'll be very happy to help.
37+
38+
## Build the extension snippets
39+
40+
All templates are placed in yaml files in [rawsnippets](./rawsnippets).
41+
If you want to add/change snippets body, you need to edit proper `yaml` file in [rawsnippets](./rawsnippets).
42+
Label and description for each snippet are placesd in [build-snippets.ts](build/build-snippets.ts) script.
43+
To generate new snippet json, run:
44+
```bash
45+
$ npm run snippets-build
46+
```
47+
npm script from extension root.

build/build-snippets.ts

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
import * as path from 'path';
6+
import * as fs from 'fs-extra';
7+
8+
interface Snippet {
9+
prefix: string;
10+
description: string;
11+
body: string[];
12+
}
13+
14+
const snippets: { [key: string]: Snippet } = {
15+
'Resource Limits and Requests': {
16+
prefix: 'Tekton: K8s Limits',
17+
description: 'Defines the Kubernetes resource limits and requests',
18+
body: load('k8s-limits.yaml'),
19+
},
20+
'Task': {
21+
prefix: 'Tekton: Task',
22+
description: 'Create a Tekton Task Resource',
23+
body: load('task.yaml'),
24+
},
25+
'TaskRun': {
26+
prefix: 'Tekton: TaskRun',
27+
description: 'Create a Tekton TaskRun Resource',
28+
body: load('taskrun.yaml'),
29+
},
30+
'Pipeline': {
31+
prefix: 'Tekton: Pipeline',
32+
description: 'Create a Tekton Pipeline Resource',
33+
body: load('pipeline.yaml'),
34+
},
35+
'PipelineRun': {
36+
prefix: 'Tekton: PipelineRun',
37+
description: 'Create a Tekton PipelineRun Resource',
38+
body: load('pipelinerun.yaml'),
39+
},
40+
'ClusterTask': {
41+
prefix: 'Tekton: ClusterTask',
42+
description: 'Create a ClusterTask Resource',
43+
body: load('clustertask.yaml'),
44+
},
45+
'Condition': {
46+
prefix: 'Tekton: Condition',
47+
description: 'Create a Condition Resource',
48+
body: load('condition.yaml')
49+
},
50+
'PipelineResource': {
51+
prefix: 'Tekton: PipelineResource',
52+
description: 'Create a PipelineResource Resource',
53+
body: load('pipelineResource.yaml'),
54+
},
55+
'TriggerTemplate': {
56+
prefix: 'Tekton: TriggerTemplate',
57+
description: 'Create a TriggerTemplate Resource',
58+
body: load('triggertemplate.yaml')
59+
},
60+
'TriggerBinding': {
61+
prefix: 'Tekton: TriggerBinding',
62+
description: 'Create a TriggerBinding Resource',
63+
body: load('triggerbinding.yaml')
64+
},
65+
'ClusterTriggerBinding': {
66+
prefix: 'Tekton: ClusterTriggerBinding',
67+
description: 'Create a ClusterTriggerBinding Resource',
68+
body: load('cluster-triggerbinding.yaml')
69+
},
70+
'EventListener': {
71+
prefix: 'Tekton: EventListener',
72+
description: 'Create an EventListener Resource',
73+
body: load('EventListener.yaml')
74+
},
75+
'PipelineResource Type': {
76+
prefix: 'Tekton: PipelineResourceType',
77+
description: 'Create a PipelineResource Type Resource',
78+
body: load('pipelineResourceType.yaml'),
79+
},
80+
'Pipeline Task Reference': {
81+
prefix: 'Tekton: PipelineTaskReference',
82+
description: 'Tekton Pipeline Task Reference',
83+
body: load('pipelineTaskReference.yaml'),
84+
},
85+
'Pipeline Task Reference Input': {
86+
prefix: 'Tekton: PipelineTaskReferenceInput',
87+
description: 'Tekton Pipeline Task Reference Inputs, Parameters and Outputs',
88+
body: load('pipelineTaskReferenceInputs.yaml'),
89+
},
90+
'Pipeline Task Conditions': {
91+
prefix: 'Tekton: PipelineTaskConditions',
92+
description: 'Tekton Pipeline Task Conditions',
93+
body: load('pipelineTaskCondition.yaml')
94+
},
95+
'TaskStep': {
96+
prefix: 'Tekton: TaskStep',
97+
description: 'Tekton Task Step',
98+
body: load('tektonTaskStep.yaml'),
99+
},
100+
'Param': {
101+
prefix: 'Tekton: Parameter',
102+
description: 'A generic parameter used across any YAML that are key/value pair',
103+
body: load('tektonParameter.yaml'),
104+
},
105+
'Task Input': {
106+
prefix: 'Tekton: TaskInput',
107+
description: 'Tekton Task Inputs, Parameters and Outputs',
108+
body: load('taskinput.yaml'),
109+
},
110+
'Task Param': {
111+
prefix: 'Tekton: TaskParameter',
112+
description: 'Tekton Pipeline Task Parameter',
113+
body: load('tektonTaskParameter.yaml'),
114+
},
115+
}
116+
117+
function load(name: string): string[] {
118+
const filePath = path.join(__dirname, '..', '..', 'rawsnippets', name);
119+
const lines = fs.readFileSync(filePath).toString().split('\n');
120+
if (lines[lines.length - 1] === '') {
121+
lines.pop();
122+
}
123+
return lines;
124+
}
125+
126+
const out = JSON.stringify(snippets, undefined, 2);
127+
128+
const filePath = path.join(__dirname, '..', '..', 'snippets', 'tekton.json');
129+
fs.writeFileSync(filePath, out);

buildsnippets/snippets.go

-130
This file was deleted.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"snippets": [
126126
{
127127
"language": "yaml",
128-
"path": "./snippets/tektoncd.json"
128+
"path": "./snippets/tekton.json"
129129
}
130130
],
131131
"keybindings": [
@@ -772,7 +772,8 @@
772772
"lint": "eslint . --ext .js,.ts",
773773
"lint:fix": "eslint . --ext .js,.ts --fix",
774774
"build-preview": "webpack-cli --mode production",
775-
"preview-watch": "webpack-cli -w --mode development"
775+
"preview-watch": "webpack-cli -w --mode development",
776+
"snippets-build": "node ./out/build/build-snippets.js"
776777
},
777778
"devDependencies": {
778779
"@types/byline": "^4.2.31",

rawsnippets/EventListener.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: EventListener
3+
metadata:
4+
name: ${1:name}
5+
spec:
6+
serviceAccountName: ${2:serviceAccount}
7+
triggers:
8+
- name: ${3:triggerName}
9+
bindings:
10+
- name: ${4:bindingName}
11+
template:
12+
name: ${5:templateName}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: ClusterTriggerBinding
3+
metadata:
4+
name: ${1:name}
5+
spec:
6+
params:
7+
- name: ${2:param_name}
8+
value: ${3:value}

rawsnippets/clustertask.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
apiVersion: tekton.dev/v1alpha1
1+
apiVersion: tekton.dev/v1beta1
22
kind: ClusterTask
33
metadata:
44
name: ${1:foo}
55
spec:
66
steps:
7-
- args:
8-
- ${2:echo clustertask}
7+
- image: ${2:alpine}
8+
script: ${3:echo hello}

rawsnippets/condition.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Condition
3+
metadata:
4+
name: ${1:foo}
5+
spec:
6+
check:
7+
image: ${2:alpine}
8+
script: ${3:echo hello}

rawsnippets/pipeline.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
apiVersion: tekton.dev/v1alpha1
1+
apiVersion: tekton.dev/v1beta1
22
kind: Pipeline
33
metadata:
44
name: ${1:app-deploy}
5-
spec:
6-
resources:
5+
spec:
6+
resources:
77
- name: ${2:pipeline-resource-type}
88
type: ${3:pipeline-type}
9-
tasks:
9+
tasks:
1010
- name: ${4:taskName}
1111
taskRef:
12-
name: ${5:build-app}
12+
name: ${5:build-app}

rawsnippets/pipelineResource.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ kind: PipelineResource
33
metadata:
44
name: ${1:git-source}
55
spec:
6-
type: ${2|git,image,pullRequest,cluster,storage|}
6+
type: ${2|git,image,pullRequest,cluster,storage,gcs,build-gcs,cloudevent|}
77
$LINE_COMMENT params:
8-
$LINE_COMMENT Check https://github.com/tektoncd/pipeline/blob/master/docs/resources.md#pipelineresources for more applicable parameters
8+
$LINE_COMMENT Check https://github.com/tektoncd/pipeline/blob/master/docs/resources.md#pipelineresources for more applicable parameters

rawsnippets/pipelineResourceType.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
- name: ${1:app-source}
2-
type: ${2|git,image,pullRequest,cluster,storage|}
2+
type: ${2|git,image,pullRequest,cluster,storage,gcs,build-gcs,cloudevent|}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
conditions:
2+
- conditionRef: ${1:conditionName}
3+
params:
4+
- name: ${2:path}
5+
value: ${3:$(params.path)}

rawsnippets/pipelineTaskReference.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
taskRef:
33
name: ${2:build-and-push}
44
runAfter:
5-
- ${3:another-task-name}
6-
$LINE_COMMENT params:
7-
$LINE_COMMENT resources:
5+
- ${3:another-task-name}
6+
$LINE_COMMENT params:
7+
$LINE_COMMENT resources:

0 commit comments

Comments
 (0)