From 2796aeaa9b7f6add54002b8f2ba4106f991b7968 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Wed, 16 Oct 2024 09:43:01 +0200 Subject: [PATCH] feat(charts): refactor github-notifier in argo-ci (#227) Signed-off-by: Yoan Blanc --- charts/argo-ci/Chart.yaml | 2 +- .../templates/build-web-ui-sensor.yaml | 65 +++++++---------- .../templates/build-workbench-operator.yaml | 71 +++++++------------ .../workflow-template-github-notify.yaml | 63 ++++++++++++++++ 4 files changed, 115 insertions(+), 86 deletions(-) create mode 100644 charts/argo-ci/templates/workflow-template-github-notify.yaml diff --git a/charts/argo-ci/Chart.yaml b/charts/argo-ci/Chart.yaml index ee634f25..dba35fc7 100644 --- a/charts/argo-ci/Chart.yaml +++ b/charts/argo-ci/Chart.yaml @@ -20,4 +20,4 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.0.61 +version: 0.0.62 diff --git a/charts/argo-ci/templates/build-web-ui-sensor.yaml b/charts/argo-ci/templates/build-web-ui-sensor.yaml index 1f623e2f..7af14010 100644 --- a/charts/argo-ci/templates/build-web-ui-sensor.yaml +++ b/charts/argo-ci/templates/build-web-ui-sensor.yaml @@ -58,7 +58,7 @@ spec: generateName: "-" spec: serviceAccountName: {{ $serviceAccountName }} - entrypoint: ci + entrypoint: pnpm-test arguments: parameters: @@ -70,17 +70,32 @@ spec: hooks: running: expression: workflow.status == "Running" - template: notify + templateRef: + name: {{ $fullName }}-github-notify-template + template: github-notify + arguments: + parameters: + - name: repoFullName + value: "{{`{{workflow.parameters.repoFullName}}`}}" + - name: sha + value: "{{`{{workflow.parameters.sha}}`}}" + - name: githubSecret + value: {{ $githubSecretName }} exit: - template: notify - - volumes: - - name: github-secret - secret: - secretName: {{ $githubSecretName }} + templateRef: + name: {{ $fullName }}-github-notify-template + template: github-notify + arguments: + parameters: + - name: repoFullName + value: "{{`{{workflow.parameters.repoFullName}}`}}" + - name: sha + value: "{{`{{workflow.parameters.sha}}`}}" + - name: githubSecret + value: {{ $githubSecretName }} templates: - - name: ci + - name: pnpm-test steps: - - name: run-tests template: test @@ -112,38 +127,6 @@ spec: workingDir: "/src" - - name: notify - container: - image: "ghcr.io/supportpal/github-gh-cli" - command: [sh, -e, -c] - volumeMounts: - - name: github-secret - mountPath: /secret/github - args: - - >- - case "{{`{{workflow.status}}`}}" in - "Running") - state=pending - ;; - "Succeeded") - state=success - ;; - "Failed") - state=failure - ;; - *) - state=error - ;; - esac; - echo $state; - gh auth login --with-token < /secret/github/password; - gh api --method POST - /repos/{{`{{workflow.parameters.repoFullName}}`}}/statuses/{{`{{workflow.parameters.sha}}`}} - -f "state=$state" - -f "description=pnpm test:run {{`{{workflow.status}}`}}" - -f "target_url=https://argo-workflows.build.chorus-tre.ch/workflows/{{`{{workflow.namespace}}`}}/{{`{{workflow.name}}`}}" - -f "context=argo-ci" - parameters: - src: dependencyName: ci-chorus-web-ui diff --git a/charts/argo-ci/templates/build-workbench-operator.yaml b/charts/argo-ci/templates/build-workbench-operator.yaml index e4802385..d68994d1 100644 --- a/charts/argo-ci/templates/build-workbench-operator.yaml +++ b/charts/argo-ci/templates/build-workbench-operator.yaml @@ -59,7 +59,7 @@ spec: generateName: "-" spec: serviceAccountName: {{ $serviceAccountName }} - entrypoint: ci + entrypoint: make-test arguments: parameters: @@ -71,22 +71,37 @@ spec: hooks: running: expression: workflow.status == "Running" - template: notify + templateRef: + name: {{ $fullName }}-github-notify-template + template: github-notify + arguments: + parameters: + - name: repoFullName + value: "{{`{{workflow.parameters.repoFullName}}`}}" + - name: sha + value: "{{`{{workflow.parameters.sha}}`}}" + - name: githubSecret + value: {{ $githubSecretName }} exit: - template: notify - - volumes: - - name: github-secret - secret: - secretName: {{ $githubSecretName }} + templateRef: + name: {{ $fullName }}-github-notify-template + template: github-notify + arguments: + parameters: + - name: repoFullName + value: "{{`{{workflow.parameters.repoFullName}}`}}" + - name: sha + value: "{{`{{workflow.parameters.sha}}`}}" + - name: githubSecret + value: {{ $githubSecretName }} templates: - - name: ci + - name: make-test steps: - - - name: run-tests - template: test + - - name: ci + template: ci - - name: test + - name: ci inputs: artifacts: - name: git @@ -108,38 +123,6 @@ spec: - make test workingDir: "/src" - - name: notify - container: - image: "ghcr.io/supportpal/github-gh-cli" - command: [sh, -e, -c] - volumeMounts: - - name: github-secret - mountPath: /secret/github - args: - - >- - case "{{`{{workflow.status}}`}}" in - "Running") - state=pending - ;; - "Succeeded") - state=success - ;; - "Failed") - state=failure - ;; - *) - state=error - ;; - esac; - echo $state; - gh auth login --with-token < /secret/github/password; - gh api --method POST - /repos/{{`{{workflow.parameters.repoFullName}}`}}/statuses/{{`{{workflow.parameters.sha}}`}} - -f "state=$state" - -f "description=make test: {{`{{workflow.status}}`}}" - -f "target_url=https://argo-workflows.build.chorus-tre.ch/workflows/{{`{{workflow.namespace}}`}}/{{`{{workflow.name}}`}}" - -f "context=argo-ci" - parameters: - src: dependencyName: ci-workbench-operator diff --git a/charts/argo-ci/templates/workflow-template-github-notify.yaml b/charts/argo-ci/templates/workflow-template-github-notify.yaml new file mode 100644 index 00000000..fc9cee9b --- /dev/null +++ b/charts/argo-ci/templates/workflow-template-github-notify.yaml @@ -0,0 +1,63 @@ +{{- $name := include "argo-ci.name" . -}} +{{- $fullName := include "argo-ci.fullname" . -}} +--- +apiVersion: argoproj.io/v1alpha1 +kind: WorkflowTemplate +metadata: + name: {{ $fullName }}-github-notify-template + labels: + {{- include "argo-ci.labels" . | nindent 4 }} +spec: + arguments: + parameters: + - name: repoFullName + - name: sha + - name: githubSecret + + templates: + - name: github-notify + inputs: + parameters: + - name: repoFullName + - name: sha + - name: githubSecret + + volumes: + - name: github-secret + secret: + secretName: "{{`{{inputs.parameters.githubSecret}}`}}" + + container: + image: "ghcr.io/supportpal/github-gh-cli" + command: [sh, -xe, -c] + volumeMounts: + - name: github-secret + mountPath: /secret/github + args: + - >- + case "{{`{{workflow.status}}`}}" in + "Running") + state=pending + verb=is + ;; + "Succeeded") + state=success + verb=has + ;; + "Failed") + state=failure + verb=has + ;; + *) + state=error + verb="got unexpected" + ;; + esac; + echo $state; + gh auth login --with-token < /secret/github/password; + gh api --method POST + /repos/{{`{{inputs.parameters.repoFullName}}`}}/statuses/{{`{{inputs.parameters.sha}}`}} + -f "state=$state" + -f "description={{`{{workflow.mainEntrypoint}}`}} $verb {{`{{workflow.status}}`}}" + -f "target_url=https://argo-workflows.build.chorus-tre.ch/workflows/{{`{{workflow.namespace}}`}}/{{`{{workflow.name}}`}}" + -f "context={{ $name }}"