Skip to content

Commit

Permalink
feat(charts): refactor github-notifier in argo-ci (#227)
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <yoan.blanc@chuv.ch>
  • Loading branch information
greut authored Oct 16, 2024
1 parent 04e7d1e commit 2796aea
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 86 deletions.
2 changes: 1 addition & 1 deletion charts/argo-ci/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
65 changes: 24 additions & 41 deletions charts/argo-ci/templates/build-web-ui-sensor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spec:
generateName: "-"
spec:
serviceAccountName: {{ $serviceAccountName }}
entrypoint: ci
entrypoint: pnpm-test

arguments:
parameters:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
71 changes: 27 additions & 44 deletions charts/argo-ci/templates/build-workbench-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
generateName: "-"
spec:
serviceAccountName: {{ $serviceAccountName }}
entrypoint: ci
entrypoint: make-test

arguments:
parameters:
Expand All @@ -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
Expand All @@ -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
Expand Down
63 changes: 63 additions & 0 deletions charts/argo-ci/templates/workflow-template-github-notify.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"

0 comments on commit 2796aea

Please sign in to comment.