From 220e5c54806932b0f49a561a78cecaa9ec2d0495 Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Thu, 26 Jan 2023 10:09:11 +0700 Subject: [PATCH] feat(tekton): add pull request workflow --- .ci/master.yaml | 24 ++-------- .ci/pull-request.yaml | 43 ++++++++++++++++++ platform/tekton-pipelines/kustomization.yaml | 1 + .../workflows/pull-request.yaml | 44 +++++++++++++++++++ 4 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 .ci/pull-request.yaml create mode 100644 platform/tekton-pipelines/workflows/pull-request.yaml diff --git a/.ci/master.yaml b/.ci/master.yaml index 07c6b5a1..0a1db665 100644 --- a/.ci/master.yaml +++ b/.ci/master.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1beta1 kind: Pipeline metadata: - name: homelab + name: master spec: workspaces: - name: shared-data @@ -21,23 +21,7 @@ spec: workspace: shared-data params: - name: url - value: http://gitea-http.gitea:3000/ops/homelab + value: $(params.git_url) - name: revision - value: master - - name: pre-commit - workspaces: - - name: source - workspace: shared-data - taskSpec: - workspaces: - - name: source - stepTemplate: - image: nixos/nix:latest - workingDir: /workspace/source - steps: - - name: run - command: - - nix-shell - - --command - args: - - "pre-commit run --color=always" + value: $(params.git_revision) + # TODO add tests here diff --git a/.ci/pull-request.yaml b/.ci/pull-request.yaml new file mode 100644 index 00000000..4912c87a --- /dev/null +++ b/.ci/pull-request.yaml @@ -0,0 +1,43 @@ +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: pull-request +spec: + workspaces: + - name: shared-data + tasks: + - name: git-clone + taskRef: + resolver: hub + params: + - name: kind + value: task + - name: name + value: git-clone + - name: version + value: "0.7" + workspaces: + - name: output + workspace: shared-data + params: + - name: url + value: $(params.git_url) + - name: revision + value: $(params.git_revision) + - name: pre-commit + workspaces: + - name: source + workspace: shared-data + taskSpec: + workspaces: + - name: source + stepTemplate: + image: nixos/nix:latest + workingDir: /workspace/source + steps: + - name: run + command: + - nix-shell + - --command + args: + - "pre-commit run --color=always" diff --git a/platform/tekton-pipelines/kustomization.yaml b/platform/tekton-pipelines/kustomization.yaml index 7d5254d6..e7b618a9 100644 --- a/platform/tekton-pipelines/kustomization.yaml +++ b/platform/tekton-pipelines/kustomization.yaml @@ -18,3 +18,4 @@ resources: # Pre-defined workflows - workflows/webhook-secret.yaml - workflows/master.yaml + - workflows/pull-request.yaml diff --git a/platform/tekton-pipelines/workflows/pull-request.yaml b/platform/tekton-pipelines/workflows/pull-request.yaml new file mode 100644 index 00000000..3b0eb923 --- /dev/null +++ b/platform/tekton-pipelines/workflows/pull-request.yaml @@ -0,0 +1,44 @@ +apiVersion: workflows.tekton.dev/v1alpha1 +kind: Workflow +metadata: + name: pull-request + namespace: tekton-workflows +spec: + triggers: + - event: + type: pull_request + secret: + secretName: webhook-secret + secretKey: token + bindings: + - name: git_url + value: $(body.repository.clone_url) + - name: git_revision + value: $(body.head.sha) + params: + - name: git_url + # TODO don't need default, but invalid mem address if remove this + default: https://git.khuedoan.com/foo/bar + - name: git_revision + default: master + pipelineRef: + resolver: git + params: + # TODO ??? + # supposed to be param. or body., looks like it's not working in v1alpha1 yet + - name: url + value: $(tt.params.git_url) + - name: revision + value: $(tt.params.git_revision) + - name: pathInRepo + value: .ci/pull-request.yaml + workspaces: + - name: shared-data + volumeClaimTemplate: + spec: + storageClassName: longhorn + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 128Mi