diff --git a/generators/README.md b/generators/README.md index bfc0f91ae..e441dfec1 100644 --- a/generators/README.md +++ b/generators/README.md @@ -4,6 +4,11 @@ This project contains experimental code to create a tool for generating Tekton s See [tektoncd/pipeline/#2590](https://github.com/tektoncd/pipeline/issues/2590) information and background. +## GitHub token +You will need to create a [GitHub Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token#creating-a-token) and set it in the Kubernetes scecret `github` in the key `token` like this: +``` +kubectl create secret generic github --from-literal token="YOUR_GITHUB_PERSONAL_ACCESS_TOKEN" +``` ## Webhook secret You would expect to create a [Webhook secret token](https://developer.github.com/webhooks/securing/#setting-your-secret-token) and configure the GitHub webhook to use this value. You can contain this value in the Kubernetes secret like this : @@ -12,7 +17,7 @@ apiVersion: v1 kind: Secret metadata: name: webhook-secret - type: Opaque +type: Opaque stringData: secretToken: "YOUR-WEBHOOK-SECRET-TOKEN" ``` @@ -21,8 +26,22 @@ Then you can create it on the command line with `kubectl` like this : kubectl apply -f secret.yaml ``` Now it can be passed as a reference to the GitHub interceptor. +## Service Account +The [`serviceAccountName`](https://github.com/tektoncd/triggers/blob/master/docs/eventlisteners.md#serviceAccountName) is a required field for Tekton Triggers. You need to provide it in the input GitHub config settings. You can create the service account with the [webhook secret](#webhook-secret) that is used in the Kubernetes cluster like this : +```yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: tekton-generators-github-sa +secrets: + - name: webhook-secret +``` +With the service account, you also need to create a role to follow certain roles and the role binding. See the [example](https://github.com/tektoncd/triggers/tree/master/examples/role-resources/triggerbinding-roles) to create your own. +Use `kubectl apply` to create these resources on the cluster as well. +**Please Note: If you use Kaniko in the task, you need to make the service account have enough credentials to push images. On GKE, it has been configured already. You can ignore this.** + ## Dependent Tasks -The generated config would expect to use the tasks already on the cluster adding to the pipeline. The tasks include [`git-clone`](https://github.com/tektoncd/catalog/blob/master/git/git-clone.yaml) and [`github-set-status`](https://github.com/tektoncd/catalog/blob/master/github/set_status.yaml). The `git-clone` task is used to help clone a repo into the workspace. The `status-task` is used to help allow external services to mark GitHub commits with a state. +The generated config would expect to use the tasks already on the cluster adding to the pipeline. The tasks include [`git-clone`](https://github.com/tektoncd/catalog/blob/v1beta1/git/git-clone.yaml) and [`github-set-status`](https://github.com/tektoncd/catalog/blob/v1beta1/github/set_status.yaml). The `git-clone` task is used to help clone a repo into the workspace. The `status-task` is used to help allow external services to mark GitHub commits with a state. **Please Note: this git-clone Task is only able to fetch code from the public repo for the time being.** ### Install the Task You can install the tasks with the specified revision(commit SHA) on the command line like this: @@ -31,6 +50,43 @@ kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog//g kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog//git/git-clone.yaml ``` +## Input configurations +Here is the example of the GitHub input config: +```yaml +kind: GitHub +metadata: + name: github-build +spec: + url: "https://github.com/YolandaDu1997/hello-world" + branch: "master" + storage: 1Gi + secretName: webhook-secret + secretKey: secretToken + serviceAccountName: tekton-generators-demo + steps: + - name: build + image: gcr.io/kaniko-project/executor:latest + command: + - /kaniko/executor + args: + - --context=dir://$(workspaces.input.path)/src + - --destination=gcr.io//kaniko-test + - --verbosity=debug +``` +### Fields + + - **kind**: the kind of generators (*required*) + - **metadata**: the metadata that uniquely identifies the `GitHub` resource object. For example, a `name` (*required*) + - **spec**: the GitHub sepc + - **url**: GitHub url to clone (*required*) + - **revision**: git reversion to clone (*default:* master) + - **branch**: the remote branch where to trigger the pipelinerun (*default:* master) + - **storage**: the disk storage needed in the workspace (*default:* 1Gi) + - **secretName**: the [webhook secret](#webhook-secret) name (*required* when generating Triggers) + - **secretKey**: the [secret key](#webhook-secret) of token in the webhook secret (*required* when generating Triggers) + - **serviceAccountName**: the name of the service account used in triggers (*required* when generating Triggers) + - **steps**: the [Tekton steps](https://github.com/tektoncd/pipeline/blob/master/docs/tasks.md#defining-steps) to run in the pipeline (*required*) + ## Features This experimental project has been broken down into the features as follows: diff --git a/generators/go.mod b/generators/go.mod index c1c9cc78e..efba80523 100644 --- a/generators/go.mod +++ b/generators/go.mod @@ -10,7 +10,6 @@ require ( k8s.io/api v0.18.2 k8s.io/apimachinery v0.18.2 k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible - knative.dev/caching v0.0.0-20200521155757-e78d17bc250e // indirect sigs.k8s.io/controller-runtime v0.6.0 sigs.k8s.io/yaml v1.2.0 ) diff --git a/generators/go.sum b/generators/go.sum index d48960cc9..06c84bada 100644 --- a/generators/go.sum +++ b/generators/go.sum @@ -178,7 +178,6 @@ github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8n github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50= github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= github.com/bwmarrin/snowflake v0.0.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= -github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -194,7 +193,9 @@ github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/ github.com/clarketm/json v1.13.4/go.mod h1:ynr2LRfb0fQU34l07csRNBTcivjySLLiY1YzQqKVfdo= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudevents/sdk-go v0.0.0-20190509003705-56931988abe3/go.mod h1:j1nZWMLGg3om8SswStBoY6/SHvcLM19MuZqwDtMtmzs= +github.com/cloudevents/sdk-go v1.0.0 h1:gS5I0s2qPmdc4GBPlUmzZU7RH30BaiOdcRJ1RkXnPrc= github.com/cloudevents/sdk-go v1.0.0/go.mod h1:3TkmM0cFqkhCHOq5JzzRU/RxRkwzoS8TZ+G448qVTog= +github.com/cloudevents/sdk-go/v2 v2.0.0 h1:AUdGJwaSUnA+VvepKqgjy6XDkPcf0hf/3L7icEs1ibs= github.com/cloudevents/sdk-go/v2 v2.0.0/go.mod h1:3CTrpB4+u7Iaj6fd7E2Xvm5IxMdRoaAhqaRVnOr2rCU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= @@ -245,7 +246,6 @@ github.com/devigned/tab v0.1.1/go.mod h1:XG9mPq0dFghrYvoBF3xdRrJzSTX1b7IQrvaL9mz github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654/go.mod h1:qm+vckxRlDt0aOla0RYJJVeqHZlWfOm2UIxHaqPB46E= -github.com/dgryski/go-lttb v0.0.0-20180810165845-318fcdf10a77/go.mod h1:Va5MyIzkU0rAM92tn3hb3Anb7oz7KcnixF49+2wOMe4= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/djherbis/atime v1.0.0/go.mod h1:5W+KBIuTwVGcqjIfaTwt+KSYX1o6uep8dtevevQP/f8= @@ -323,6 +323,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= +github.com/go-logr/zapr v0.1.1 h1:qXBXPDdNncunGs7XeEpsJt8wCjYBygluzfdLO0G5baE= github.com/go-logr/zapr v0.1.1/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= @@ -534,13 +535,16 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/grpc-ecosystem/grpc-gateway v1.12.2 h1:D0EVSTwQoQOyfY35QNSuPJA4jpZRtkoGYWQMB7XNg5o= github.com/grpc-ecosystem/grpc-gateway v1.12.2/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= +github.com/grpc-ecosystem/grpc-gateway v1.13.0 h1:sBDQoHXrOlfPobnKw69FIKa1wg9qsLLvvQ/Y19WtFgI= github.com/grpc-ecosystem/grpc-gateway v1.13.0/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/h2non/gock v1.0.9/go.mod h1:CZMcB0Lg5IWnr9bF79pPMg9WeV6WumxQiUJ1UvdO1iE= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI= github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -558,10 +562,10 @@ github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb v0.0.0-20161215172503-049f9b42e9a5/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= -github.com/influxdata/tdigest v0.0.1/go.mod h1:Z0kXnxzbTC2qrx4NaIzYkE1k66+6oEDQTvL95hQFh5Y= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= @@ -627,6 +631,7 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= +github.com/lightstep/tracecontext.go v0.0.0-20181129014701-1757c391b1ac h1:+2b6iGRJe3hvV/yVXrd41yVEjxuFHxasJqDhkIjS4gk= github.com/lightstep/tracecontext.go v0.0.0-20181129014701-1757c391b1ac/go.mod h1:Frd2bnT3w5FB5q49ENTfVlztJES+1k/7lyWX2+9gq/M= github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= @@ -660,7 +665,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY= github.com/mholt/archiver/v3 v3.3.0/go.mod h1:YnQtqsp+94Rwd0D/rk5cnLrxusUBUXg+08Ebtr1Mqao= -github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= @@ -876,8 +880,6 @@ github.com/tektoncd/pipeline v0.10.1/go.mod h1:D2X0exT46zYx95BU7ByM8+erpjoN7thmU github.com/tektoncd/pipeline v0.11.3/go.mod h1:hlkH32S92+/UODROH0dmxzyuMxfRFp/Nc3e29MewLn8= github.com/tektoncd/pipeline v0.13.1-0.20200629123701-851a266d38d3 h1:aMsulcr6WwoyvsCMzp7nS3um1n1rJdBkPjNMYhXbUvY= github.com/tektoncd/pipeline v0.13.1-0.20200629123701-851a266d38d3/go.mod h1:R5AlT46x/F8n/pFJFjZ1U1q71GWtVXgG7RZkkoRL554= -github.com/tektoncd/pipeline v0.13.2 h1:QbjYzVplDJZB/us5OPaAS3rMpYQLJ6DKXXYFKvYhA+U= -github.com/tektoncd/pipeline v0.13.2/go.mod h1:jISolc5UsC2R9qKKiS96TvebwAW2Ihue3SXSGS1nECM= github.com/tektoncd/plumbing v0.0.0-20191216083742-847dcf196de9/go.mod h1:QZHgU07PRBTRF6N57w4+ApRu8OgfYLFNqCDlfEZaD9Y= github.com/tektoncd/plumbing v0.0.0-20200217163359-cd0db6e567d2/go.mod h1:QZHgU07PRBTRF6N57w4+ApRu8OgfYLFNqCDlfEZaD9Y= github.com/tektoncd/plumbing v0.0.0-20200430135134-e53521e1d887/go.mod h1:cZPJIeTIoP7UPTxQyTQLs7VE1TiXJSNj0te+If4Q+jI= @@ -890,7 +892,6 @@ github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV github.com/tidwall/sjson v1.0.4/go.mod h1:bURseu1nuBkFpIES5cz6zBtjmYeOQmEESshn7VpF15Y= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tsenart/go-tsz v0.0.0-20180814235614-0bd30b3df1c3/go.mod h1:SWZznP1z5Ki7hDT2ioqiFKEse8K9tU2OUvaRI0NeGQo= github.com/tsenart/vegeta v12.7.1-0.20190725001342-b5f4fca92137+incompatible/go.mod h1:Smz/ZWfhKRcyDDChZkG3CyTHdj87lHzio/HOCkbndXM= github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= @@ -899,6 +900,7 @@ github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4A github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.18.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/vdemeester/k8s-pkg-credentialprovider v0.0.0-20200107171650-7c61ffa44238/go.mod h1:JwQJCMWpUDqjZrB5jpw0f5VbN7U95zxFy1ZDpoEarGo= github.com/vdemeester/k8s-pkg-credentialprovider v1.13.12-1/go.mod h1:Fko0rTxEtDW2kju5Ky7yFJNS3IcNvW8IPsp4/e9oev0= @@ -1118,7 +1120,6 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1190,7 +1191,6 @@ golang.org/x/tools v0.0.0-20191118222007-07fc4c7f2b98/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200115165105-de0b1760071a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= @@ -1276,6 +1276,7 @@ google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200317114155-1f3552e48f24/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200326112834-f447254575fd h1:DVCc2PgW9UrvHGZGEv4Mt3uSeQtUrrs7r8pUw+bVwWI= google.golang.org/genproto v0.0.0-20200326112834-f447254575fd/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/grpc v0.0.0-20160317175043-d3ddb4469d5a/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.13.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= @@ -1377,6 +1378,7 @@ k8s.io/apiextensions-apiserver v0.0.0-20190918201827-3de75813f604/go.mod h1:7H8s k8s.io/apiextensions-apiserver v0.16.4/go.mod h1:HYQwjujEkXmQNhap2C9YDdIVOSskGZ3et0Mvjcyjbto= k8s.io/apiextensions-apiserver v0.17.2/go.mod h1:4KdMpjkEjjDI2pPfBA15OscyNldHWdBCfsWMDWAmSTs= k8s.io/apiextensions-apiserver v0.17.6/go.mod h1:Z3CHLP3Tha+Rbav7JR3S+ye427UaJkHBomK2c4XtZ3A= +k8s.io/apiextensions-apiserver v0.18.2 h1:I4v3/jAuQC+89L3Z7dDgAiN4EOjN6sbm6iBqQwHTah8= k8s.io/apiextensions-apiserver v0.18.2/go.mod h1:q3faSnRGmYimiocj6cHQ1I3WpLqmDgJFlKL37fC4ZvY= k8s.io/apimachinery v0.0.0-20200214081019-7490b3ed6e92 h1:LyozpD1xHYBURrbAdrLCfOzsuidg06BXeptuvqkHEp0= k8s.io/apimachinery v0.0.0-20200214081019-7490b3ed6e92/go.mod h1:5X8oEhnd931nEg6/Nkumo00nT6ZsCLp2h7Xwd7Ym6P4= @@ -1446,7 +1448,6 @@ k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl knative.dev/caching v0.0.0-20190719140829-2032732871ff/go.mod h1:dHXFU6CGlLlbzaWc32g80cR92iuBSpsslDNBWI8C7eg= knative.dev/caching v0.0.0-20200116200605-67bca2c83dfa/go.mod h1:dHXFU6CGlLlbzaWc32g80cR92iuBSpsslDNBWI8C7eg= knative.dev/caching v0.0.0-20200228235451-13d271455c74/go.mod h1:dHXFU6CGlLlbzaWc32g80cR92iuBSpsslDNBWI8C7eg= -knative.dev/caching v0.0.0-20200521155757-e78d17bc250e/go.mod h1:bsKPIG2XZFYL8uw5BAxg7EMBLp0vNpu9jZIGus8HUPU= knative.dev/eventing-contrib v0.6.1-0.20190723221543-5ce18048c08b/go.mod h1:SnXZgSGgMSMLNFTwTnpaOH7hXDzTFtw0J8OmHflNx3g= knative.dev/eventing-contrib v0.11.2/go.mod h1:SnXZgSGgMSMLNFTwTnpaOH7hXDzTFtw0J8OmHflNx3g= knative.dev/pkg v0.0.0-20191101194912-56c2594e4f11/go.mod h1:pgODObA1dTyhNoFxPZTTjNWfx6F0aKsKzn+vaT9XO/Q= @@ -1455,14 +1456,12 @@ knative.dev/pkg v0.0.0-20200207155214-fef852970f43/go.mod h1:pgODObA1dTyhNoFxPZT knative.dev/pkg v0.0.0-20200428194351-90fc61bae7f7/go.mod h1:o+e8OVEJKIuvXPsGVPIautjXgs05xbos7G+QMRjuUps= knative.dev/pkg v0.0.0-20200505191044-3da93ebb24c2/go.mod h1:Q6sL35DdGs8hIQZKdaCXJGgY8f90BmNBKSb8z6d/BTM= knative.dev/pkg v0.0.0-20200515002500-16d7b963416f/go.mod h1:tMOHGbxtRz8zYFGEGpV/bpoTEM1o89MwYFC4YJXl3GY= -knative.dev/pkg v0.0.0-20200519155757-14eb3ae3a5a7/go.mod h1:QgNZTxnwpB/oSpNcfnLVlw+WpEwwyKAvJlvR3hgeltA= knative.dev/pkg v0.0.0-20200528142800-1c6815d7e4c9 h1:bN9gghp5Osuw1bgKrvMaA+oiAvPuYmzSbRo54/EFSxI= knative.dev/pkg v0.0.0-20200528142800-1c6815d7e4c9/go.mod h1:QgNZTxnwpB/oSpNcfnLVlw+WpEwwyKAvJlvR3hgeltA= knative.dev/test-infra v0.0.0-20200407185800-1b88cb3b45a5/go.mod h1:xcdUkMJrLlBswIZqL5zCuBFOC22WIPMQoVX1L35i0vQ= knative.dev/test-infra v0.0.0-20200505052144-5ea2f705bb55/go.mod h1:WqF1Azka+FxPZ20keR2zCNtiQA1MP9ZB4BH4HuI+SIU= knative.dev/test-infra v0.0.0-20200513011557-d03429a76034/go.mod h1:aMif0KXL4g19YCYwsy4Ocjjz5xgPlseYV+B95Oo4JGE= knative.dev/test-infra v0.0.0-20200519015156-82551620b0a9/go.mod h1:A5b2OAXTOeHT3hHhVQm3dmtbuWvIDP7qzgtqxA3/2pE= -knative.dev/test-infra v0.0.0-20200519161858-554a95a37986/go.mod h1:LeNa1Wvn47efeQUkpkn3XG7Fx9Ga+rhAP13SZyjaEGg= mvdan.cc/xurls/v2 v2.0.0/go.mod h1:2/webFPYOXN9jp/lzuj0zuAVlF+9g4KPFJANH1oJhRU= pack.ag/amqp v0.11.0/go.mod h1:4/cbmt4EJXSKlG6LCfWHoqmN0uFdy5i/+YFz+fTfhV4= pack.ag/amqp v0.11.2/go.mod h1:4/cbmt4EJXSKlG6LCfWHoqmN0uFdy5i/+YFz+fTfhV4= diff --git a/generators/pkg/generator/generate.go b/generators/pkg/generator/generate.go index f10c14df9..bbd382190 100644 --- a/generators/pkg/generator/generate.go +++ b/generators/pkg/generator/generate.go @@ -23,12 +23,18 @@ type GitHub struct { // GithubSpec defines Github spec type GitHubSpec struct { - URL string `json:"url,omitempty"` - Steps []v1beta1.Step `json:"steps,omitempty"` + URL string `json:"url,omitempty"` + Revision string `json:"revision,omitempty"` + Branch string `json:"branch,omitempty"` + Storage string `json:"storage,omitempty"` + SecretName string `json:"secretName,omitempty"` + SecretKey string `json:"secretKey,omitempty"` + ServiceAccountName string `json:"serviceAccountName,omitempty"` + Steps []v1beta1.Step `json:"steps,omitempty"` } type trigger struct { - TriggerBinding *v1alpha1.TriggerBinding + TriggerBinding []*v1alpha1.TriggerBinding TriggerTemplate *v1alpha1.TriggerTemplate EventListener *v1alpha1.EventListener } @@ -41,6 +47,7 @@ func GenerateTask(github *GitHub) *v1beta1.Task { labels = make(map[string]string) } labels["generator.tekton.dev"] = github.Name + return &v1beta1.Task{ TypeMeta: metav1.TypeMeta{ APIVersion: v1beta1.SchemeGroupVersion.String(), @@ -148,7 +155,7 @@ func GeneratePipeline(github *GitHub) (*v1beta1.Pipeline, error) { { Name: tasksName[2], TaskRef: &v1beta1.TaskRef{ - Name: "set-status", + Name: "github-set-status", }, Params: []v1beta1.Param{ { @@ -165,6 +172,13 @@ func GeneratePipeline(github *GitHub) (*v1beta1.Pipeline, error) { StringVal: "$(params.gitrevision)", }, }, + { + Name: "STATE", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "success", + }, + }, }, }, }, @@ -181,11 +195,26 @@ func GeneratePipeline(github *GitHub) (*v1beta1.Pipeline, error) { } // Generate the trigger with the given generated pipeline -func GenerateTrigger(p *v1beta1.Pipeline) *trigger { +func GenerateTrigger(p *v1beta1.Pipeline, g *GitHub) *trigger { if p.Namespace == "" { p.Namespace = "default" } + var value int64 + var format resource.Format + if g.Spec.Storage != "" { + diskSize := resource.MustParse(g.Spec.Storage) + value = diskSize.Value() + format = diskSize.Format + } else { + value = 1024 * 1024 * 1024 + format = resource.BinarySI + } + + if g.Spec.Branch == "" { + g.Spec.Branch = "master" + } + // create pipelinerun in the triggertemplate pr := &v1beta1.PipelineRun{ TypeMeta: metav1.TypeMeta{ @@ -227,7 +256,7 @@ func GenerateTrigger(p *v1beta1.Pipeline) *trigger { }, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ - "storage": *resource.NewQuantity(1*1024*1024*1024, resource.BinarySI), + "storage": *resource.NewQuantity(value, format), }, }, }, @@ -267,11 +296,11 @@ func GenerateTrigger(p *v1beta1.Pipeline) *trigger { }, } - // create the triggerbinding - tb := &v1alpha1.TriggerBinding{ + // create the triggerbinding for pull request events + tbPr := &v1alpha1.TriggerBinding{ ObjectMeta: metav1.ObjectMeta{ Namespace: p.Namespace, - Name: p.Name + "-triggerbinding", + Name: p.Name + "-pr-triggerbinding", Labels: p.Labels, }, TypeMeta: metav1.TypeMeta{ @@ -282,7 +311,32 @@ func GenerateTrigger(p *v1beta1.Pipeline) *trigger { Params: []v1alpha1.Param{ { Name: "gitrevision", - Value: "$(body.head_commit.id)", + Value: "$(body.head.sha)", + }, + { + Name: "gitrepositoryurl", + Value: "$(body.repository.url)", + }, + }, + }, + } + + // create the triggerbinding for pushes events + tbPush := &v1alpha1.TriggerBinding{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: p.Namespace, + Name: p.Name + "-push-triggerbinding", + Labels: p.Labels, + }, + TypeMeta: metav1.TypeMeta{ + APIVersion: v1alpha1.SchemeGroupVersion.String(), + Kind: "TriggerBinding", + }, + Spec: v1alpha1.TriggerBindingSpec{ + Params: []v1alpha1.Param{ + { + Name: "gitrevision", + Value: "$(body.after)", }, { Name: "gitrepositoryurl", @@ -304,6 +358,7 @@ func GenerateTrigger(p *v1beta1.Pipeline) *trigger { Kind: "EventListener", }, Spec: v1alpha1.EventListenerSpec{ + ServiceAccountName: g.Spec.ServiceAccountName, Triggers: []v1alpha1.EventListenerTrigger{ { Name: "github-push", @@ -312,15 +367,20 @@ func GenerateTrigger(p *v1beta1.Pipeline) *trigger { GitHub: &v1alpha1.GitHubInterceptor{ EventTypes: []string{"push"}, SecretRef: &v1alpha1.SecretRef{ - SecretKey: "secretToken", - SecretName: "github-secret", + SecretKey: g.Spec.SecretKey, + SecretName: g.Spec.SecretName, }, }, }, + { + CEL: &v1alpha1.CELInterceptor{ + Filter: "body.ref.split('/')[2] == " + g.Spec.Branch, + }, + }, }, Bindings: []*v1alpha1.EventListenerBinding{ { - Ref: tb.Name, + Ref: tbPush.Name, }, }, Template: v1alpha1.EventListenerTemplate{ @@ -334,15 +394,20 @@ func GenerateTrigger(p *v1beta1.Pipeline) *trigger { GitHub: &v1alpha1.GitHubInterceptor{ EventTypes: []string{"pull_request"}, SecretRef: &v1alpha1.SecretRef{ - SecretKey: "secretToken", - SecretName: "github-secret", + SecretKey: g.Spec.SecretKey, + SecretName: g.Spec.SecretName, }, }, }, + { + CEL: &v1alpha1.CELInterceptor{ + Filter: "body.base.ref == " + g.Spec.Branch, + }, + }, }, Bindings: []*v1alpha1.EventListenerBinding{ { - Ref: tb.Name, + Ref: tbPr.Name, }, }, Template: v1alpha1.EventListenerTemplate{ @@ -354,7 +419,7 @@ func GenerateTrigger(p *v1beta1.Pipeline) *trigger { } trigger := &trigger{ - TriggerBinding: tb, + TriggerBinding: []*v1alpha1.TriggerBinding{tbPush, tbPr}, TriggerTemplate: tt, EventListener: el, } diff --git a/generators/pkg/generator/generate_test.go b/generators/pkg/generator/generate_test.go index 3754a2707..3ca11e653 100644 --- a/generators/pkg/generator/generate_test.go +++ b/generators/pkg/generator/generate_test.go @@ -13,6 +13,33 @@ import ( "sigs.k8s.io/yaml" ) +var github = &GitHub{ + ObjectMeta: metav1.ObjectMeta{ + Name: "github-build", + }, + Spec: GitHubSpec{ + URL: "https://github.com/wlynch/test", + Revision: "df5b1b84c23c6c4f41a4e51ba02da0095acf59e7", + Branch: "master", + ServiceAccountName: "tekton-generators-demo", + Storage: "1Gi", + SecretName: "github-secret", + SecretKey: "secretToken", + Steps: []v1beta1.Step{ + { + Container: corev1.Container{ + Name: "build", + Image: "gcr.io/kaniko-project/executor:latest", + Command: []string{"/kaniko/executor"}, + Args: []string{"--context=dir://$(workspaces.input.path)/src", + "--destination=gcr.io/tekton-yolandadu/kaniko-test", + "--verbosity=debug"}, + }, + }, + }, + }, +} + func TestGenerateTask(t *testing.T) { want := &v1beta1.Task{ TypeMeta: metav1.TypeMeta{ @@ -37,28 +64,13 @@ func TestGenerateTask(t *testing.T) { Image: "gcr.io/kaniko-project/executor:latest", Command: []string{"/kaniko/executor"}, Args: []string{"--context=dir://$(workspaces.input.path)/src", - "--destination=gcr.io/wlynch-test/kaniko-test", + "--destination=gcr.io/tekton-yolandadu/kaniko-test", "--verbosity=debug"}, }, }, }, }, } - github := &GitHub{ - ObjectMeta: metav1.ObjectMeta{ - Name: "github-build", - }, - Spec: GitHubSpec{ - URL: "https://github.com/wlynch/test", - Steps: []v1beta1.Step{{Container: corev1.Container{ - Name: "build", - Image: "gcr.io/kaniko-project/executor:latest", - Command: []string{"/kaniko/executor"}, - Args: []string{"--context=dir://$(workspaces.input.path)/src", - "--destination=gcr.io/wlynch-test/kaniko-test", - "--verbosity=debug"}, - }, - }}}} got := GenerateTask(github) if diff := cmp.Diff(want, got); diff != "" { t.Errorf("Tasks mismatch (-want +got):\n %s", diff) @@ -69,26 +81,6 @@ func TestGeneratePipeline(t *testing.T) { want := &v1beta1.Pipeline{} unmarshal(t, "./testdata/pipeline.yaml", want) - github := &GitHub{ - ObjectMeta: metav1.ObjectMeta{ - Name: "github-build", - }, - Spec: GitHubSpec{ - URL: "https://github.com/wlynch/test", - Steps: []v1beta1.Step{ - { - Container: corev1.Container{ - Name: "build", - Image: "gcr.io/kaniko-project/executor:latest", - Command: []string{"/kaniko/executor"}, - Args: []string{"--context=dir://$(workspaces.input.path)/src", - "--destination=gcr.io//kaniko-test", - "--verbosity=debug"}, - }, - }, - }, - }, - } got, err := GeneratePipeline(github) if err != nil { t.Fatalf("error from 'GeneratePipeline': %v", err) @@ -99,9 +91,13 @@ func TestGeneratePipeline(t *testing.T) { } func TestGenerateTrigger(t *testing.T) { - // read the want TriggerBinding - tb := &v1alpha1.TriggerBinding{} - unmarshal(t, "./testdata/triggerbinding.yaml", tb) + // read the want TriggerBinding for push events + tbPush := &v1alpha1.TriggerBinding{} + unmarshal(t, "./testdata/triggerbinding.yaml", tbPush) + + // read the want TriggerBinding for pull request events + tbPr := &v1alpha1.TriggerBinding{} + unmarshal(t, "./testdata/triggerbinding-pr.yaml", tbPr) // read the Trigger's resourcetemplate pr := &v1beta1.PipelineRun{} @@ -120,7 +116,7 @@ func TestGenerateTrigger(t *testing.T) { unmarshal(t, "./testdata/eventlistener.yaml", el) want := &trigger{ - TriggerBinding: tb, + TriggerBinding: []*v1alpha1.TriggerBinding{tbPush, tbPr}, TriggerTemplate: tt, EventListener: el, } @@ -142,7 +138,7 @@ func TestGenerateTrigger(t *testing.T) { }, }, } - got := GenerateTrigger(pipeline) + got := GenerateTrigger(pipeline, github) if diff := cmp.Diff(want, got); diff != "" { t.Errorf("Trigger mismatch (-want +got):\n %s", diff) } diff --git a/generators/pkg/generator/testdata/eventlistener.yaml b/generators/pkg/generator/testdata/eventlistener.yaml index 19114271e..870ef65fb 100644 --- a/generators/pkg/generator/testdata/eventlistener.yaml +++ b/generators/pkg/generator/testdata/eventlistener.yaml @@ -6,6 +6,7 @@ metadata: labels: generator.tekton.dev: github-pipeline spec: + serviceAccountName: "tekton-generators-demo" triggers: - name: github-push interceptors: @@ -15,8 +16,10 @@ spec: secretKey: secretToken eventTypes: - push + - cel: + filter: "body.ref.split('/')[2] == master" bindings: - - ref: github-pipeline-triggerbinding + - ref: github-pipeline-push-triggerbinding template: name: github-pipeline-triggertemplate - name: github-pull-request @@ -27,7 +30,9 @@ spec: secretKey: secretToken eventTypes: - pull_request + - cel: + filter: "body.base.ref == master" bindings: - - ref: github-pipeline-triggerbinding + - ref: github-pipeline-pr-triggerbinding template: name: github-pipeline-triggertemplate \ No newline at end of file diff --git a/generators/pkg/generator/testdata/pipeline.yaml b/generators/pkg/generator/testdata/pipeline.yaml index db3c31f61..155b149a4 100644 --- a/generators/pkg/generator/testdata/pipeline.yaml +++ b/generators/pkg/generator/testdata/pipeline.yaml @@ -13,8 +13,10 @@ spec: value: /wlynch/test - name: SHA value: $(params.gitrevision) + - name: STATE + value: success taskRef: - name: set-status + name: github-set-status tasks: - name: fetch-git-repo params: diff --git a/generators/pkg/generator/testdata/triggerbinding-pr.yaml b/generators/pkg/generator/testdata/triggerbinding-pr.yaml new file mode 100644 index 000000000..89346c83d --- /dev/null +++ b/generators/pkg/generator/testdata/triggerbinding-pr.yaml @@ -0,0 +1,13 @@ +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + name: github-pipeline-pr-triggerbinding + namespace: default + labels: + generator.tekton.dev: github-pipeline +spec: + params: + - name: gitrevision + value: $(body.head.sha) + - name: gitrepositoryurl + value: $(body.repository.url) \ No newline at end of file diff --git a/generators/pkg/generator/testdata/triggerbinding.yaml b/generators/pkg/generator/testdata/triggerbinding.yaml index 2e46ee811..267838f05 100644 --- a/generators/pkg/generator/testdata/triggerbinding.yaml +++ b/generators/pkg/generator/testdata/triggerbinding.yaml @@ -1,13 +1,13 @@ apiVersion: triggers.tekton.dev/v1alpha1 kind: TriggerBinding metadata: - name: github-pipeline-triggerbinding + name: github-pipeline-push-triggerbinding namespace: default labels: generator.tekton.dev: github-pipeline spec: params: - name: gitrevision - value: $(body.head_commit.id) + value: $(body.after) - name: gitrepositoryurl value: $(body.repository.url) \ No newline at end of file diff --git a/generators/pkg/parser/parser_test.go b/generators/pkg/parser/parser_test.go index b11f822e7..9bd7b11f3 100644 --- a/generators/pkg/parser/parser_test.go +++ b/generators/pkg/parser/parser_test.go @@ -30,7 +30,13 @@ func TestParse(t *testing.T) { Name: "github-build", }, Spec: generator.GitHubSpec{ - URL: "https://github.com/wlynch/test", + URL: "https://github.com/wlynch/test", + Revision: "df5b1b84c23c6c4f41a4e51ba02da0095acf59e7", + Branch: "master", + Storage: "1Gi", + SecretName: "github-secret", + SecretKey: "secretToken", + ServiceAccountName: "tekton-generators-demo", Steps: []v1beta1.Step{ { Container: corev1.Container{ diff --git a/generators/pkg/parser/testdata/spec-full.yaml b/generators/pkg/parser/testdata/spec-full.yaml index d63bfaa73..57e165eb2 100644 --- a/generators/pkg/parser/testdata/spec-full.yaml +++ b/generators/pkg/parser/testdata/spec-full.yaml @@ -3,6 +3,12 @@ metadata: name: github-build spec: url: "https://github.com/wlynch/test" + revision: df5b1b84c23c6c4f41a4e51ba02da0095acf59e7 + branch: "master" + storage: 1Gi + secretName: github-secret + secretKey: secretToken + serviceAccountName: tekton-generators-demo steps: - name: build image: gcr.io/kaniko-project/executor:latest @@ -11,4 +17,4 @@ spec: args: - --context=dir://$(workspaces.input.path)/src - --destination=gcr.io//kaniko-test - - --verbosity=debug + - --verbosity=debug \ No newline at end of file diff --git a/generators/pkg/writer/testdata/config.yaml b/generators/pkg/writer/testdata/config.yaml index 716b08b61..8d4b0b5ca 100644 --- a/generators/pkg/writer/testdata/config.yaml +++ b/generators/pkg/writer/testdata/config.yaml @@ -10,7 +10,7 @@ spec: steps: - args: - --context=dir://$(workspaces.input.path)/src - - --destination=gcr.io//kaniko-test + - --destination=gcr.io/tekton-yolandadu/kaniko-test - --verbosity=debug command: - /kaniko/executor @@ -37,8 +37,10 @@ spec: value: /wlynch/test - name: SHA value: $(params.gitrevision) + - name: STATE + value: success taskRef: - name: set-status + name: github-set-status params: - name: gitrepositoryurl type: string @@ -73,12 +75,28 @@ metadata: creationTimestamp: null labels: generator.tekton.dev: github-build-pipeline - name: github-build-pipeline-triggerbinding + name: github-build-pipeline-push-triggerbinding namespace: default spec: params: - name: gitrevision - value: $(body.head_commit.id) + value: $(body.after) + - name: gitrepositoryurl + value: $(body.repository.url) +status: {} +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + creationTimestamp: null + labels: + generator.tekton.dev: github-build-pipeline + name: github-build-pipeline-pr-triggerbinding + namespace: default +spec: + params: + - name: gitrevision + value: $(body.head.sha) - name: gitrepositoryurl value: $(body.repository.url) status: {} @@ -139,10 +157,10 @@ metadata: namespace: default spec: podTemplate: {} - serviceAccountName: "" + serviceAccountName: tekton-generators-demo triggers: - bindings: - - ref: github-build-pipeline-triggerbinding + - ref: github-build-pipeline-push-triggerbinding interceptors: - github: eventTypes: @@ -150,11 +168,13 @@ spec: secretRef: secretKey: secretToken secretName: github-secret + - cel: + filter: body.ref.split('/')[2] == master name: github-push template: name: github-build-pipeline-triggertemplate - bindings: - - ref: github-build-pipeline-triggerbinding + - ref: github-build-pipeline-pr-triggerbinding interceptors: - github: eventTypes: @@ -162,6 +182,8 @@ spec: secretRef: secretKey: secretToken secretName: github-secret + - cel: + filter: body.base.ref == master name: github-pull-request template: name: github-build-pipeline-triggertemplate diff --git a/generators/pkg/writer/testdata/spec-full.yaml b/generators/pkg/writer/testdata/spec-full.yaml index d63bfaa73..7c1bf00df 100644 --- a/generators/pkg/writer/testdata/spec-full.yaml +++ b/generators/pkg/writer/testdata/spec-full.yaml @@ -3,6 +3,11 @@ metadata: name: github-build spec: url: "https://github.com/wlynch/test" + branch: "master" + storage: 1Gi + secretName: github-secret + secretKey: secretToken + serviceAccountName: tekton-generators-demo steps: - name: build image: gcr.io/kaniko-project/executor:latest @@ -10,5 +15,6 @@ spec: - /kaniko/executor args: - --context=dir://$(workspaces.input.path)/src - - --destination=gcr.io//kaniko-test + - --destination=gcr.io/tekton-yolandadu/kaniko-test - --verbosity=debug + diff --git a/generators/pkg/writer/testdata/spec.yaml b/generators/pkg/writer/testdata/spec.yaml index 90f44dc10..b18d5f396 100644 --- a/generators/pkg/writer/testdata/spec.yaml +++ b/generators/pkg/writer/testdata/spec.yaml @@ -1,10 +1,18 @@ -url: "https://github.com/wlynch/test" -steps: - - name: build - image: gcr.io/kaniko-project/executor:latest - command: - - /kaniko/executor - args: - - --context=dir://$(workspaces.input.path)/src - - --destination=gcr.io//kaniko-test - - --verbosity=debug \ No newline at end of file +kind: GitHub +metadata: + name: github-build +spec: + url: "https://github.com/wlynch/test" + storage: 1Gi + secretName: webhook-secret + secretKey: secretToken + steps: + - name: build + image: gcr.io/kaniko-project/executor:latest + command: + - /kaniko/executor + args: + - --context=dir://$(workspaces.input.path)/src + - --destination=gcr.io/tekton-yolandadu/kaniko-test + - --verbosity=debug + diff --git a/generators/pkg/writer/write.go b/generators/pkg/writer/write.go index 69057b551..a6b12e9ca 100644 --- a/generators/pkg/writer/write.go +++ b/generators/pkg/writer/write.go @@ -33,10 +33,10 @@ func WriteToDisk(filename string, writer io.Writer) error { if err != nil { return fmt.Errorf("unable to get the pipeline: %w", err) } - trigger := generator.GenerateTrigger(pipeline) + trigger := generator.GenerateTrigger(pipeline, github) // write into the disk - return writeYaml(writer, task, pipeline, trigger.TriggerBinding, trigger.TriggerTemplate, trigger.EventListener) + return writeYaml(writer, task, pipeline, trigger.TriggerBinding[0], trigger.TriggerBinding[1], trigger.TriggerTemplate, trigger.EventListener) } func writeYaml(writer io.Writer, objs ...runtime.Object) error {