From 7490690e13afe54b4169ec39770a4a6833f1c80c Mon Sep 17 00:00:00 2001 From: anuttinck Date: Tue, 13 Aug 2024 11:50:58 +0200 Subject: [PATCH] [ADD] helm-release-notify and helm-test-notify --- CHANGELOG.md | 5 ++ README.md | 84 ++++++++++++++++++++++++++++++---- helm-release-notify/action.yml | 75 ++++++++++++++++++++++++++++++ helm-test-notify/action.yml | 63 +++++++++++++++++++++++++ 4 files changed, 218 insertions(+), 9 deletions(-) create mode 100644 helm-release-notify/action.yml create mode 100644 helm-test-notify/action.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index b40503b..980eb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [v3.9] - 2024-08-13 +### Added +- helm-release-notify +- helm-test-notify + ## [v3.8] - 2024-08-08 ### Added - plone-theme-build-push-notify diff --git a/README.md b/README.md index 3966691..7a8ec88 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,42 @@ This repository hosts a set of github actions we use to deploy our apps. ## Actions -- [build-push-notify](#build-push-notify) -- [check-url-availibility](#check-url-availibility) -- [code-analysis-notify](#code-analysis-notify) -- [deb-build-push-notify](#deb-build-push-notify) -- [mattermost-notify](#mattermost-notify) -- [plone-package-test-notify](#plone-package-test-notify) -- [plone-theme-build-push-notify](#plone-theme-build-push-notify) -- [rundeck-notify](#rundeck-notify) -- [tag-notify](#tag-notify) +- [iMio github actions](#imio-github-actions) + - [Actions](#actions) + - [build-push-notify](#build-push-notify) + - [Inputs](#inputs) + - [Example of usage](#example-of-usage) + - [check-url-availibility](#check-url-availibility) + - [Example of usage](#example-of-usage-1) + - [code-analysis-notify](#code-analysis-notify) + - [Inputs](#inputs-1) + - [Example of usage](#example-of-usage-2) + - [deb-build-push-notify](#deb-build-push-notify) + - [Inputs](#inputs-2) + - [Example of usage](#example-of-usage-3) + - [helm-release-notify](#helm-release-notify) + - [Inputs](#inputs-3) + - [Example of usage](#example-of-usage-4) + - [helm-test-notify](#helm-test-notify) + - [Inputs](#inputs-4) + - [Example of usage](#example-of-usage-5) + - [mattermost-notify](#mattermost-notify) + - [Inputs](#inputs-5) + - [Example of usage](#example-of-usage-6) + - [plone-package-test-notify](#plone-package-test-notify) + - [Inputs](#inputs-6) + - [Example of usage](#example-of-usage-7) + - [plone-theme-build-push-notify](#plone-theme-build-push-notify) + - [Inputs](#inputs-7) + - [Example of usage](#example-of-usage-8) + - [rundeck-notify](#rundeck-notify) + - [Inputs](#inputs-8) + - [Example of usage](#example-of-usage-9) + - [tag-notify](#tag-notify) + - [Inputs](#inputs-9) + - [Example of usage](#example-of-usage-10) + - [Contribute](#contribute) + - [Release](#release) ### build-push-notify @@ -99,6 +126,45 @@ Build a deb package, push it on a repository and optionally notify via a matterm [IMIO/scripts-teleservices](https://github.com/IMIO/scripts-teleservices/blob/613d1563be3ddbafb3c66347022558c5dffb678c/.github/workflows/deb.yml#L20) +--- +### helm-release-notify + +Release a helm chart and optionally notify via a mattermost webhook + +#### Inputs + +| name | required | type | default | description | +| ---------------------- | -------- | ------ | --------------- | ----------- | +| HELM_VERSION | yes | string | "v3.12.3" | Helm version to use | +| HELM_DEPENDENCIES | no | string | | Helm dependencies | +| INDEX_DIR | yes | string | "." | Index directory | +| CHARTS_DIR | yes | string | "." | Charts directory | +| TARGET_DIR | yes | string | "test" | Target directory to release | +| MATTERMOST_WEBHOOK_URL | no | string | | Webhook URL to send notifications on Mattermost | + +#### Example of usage + +/ + +--- +### helm-test-notify + +Lint and test a helm chart and optionally notify via a mattermost webhook + +#### Inputs + +| name | required | type | default | description | +| ---------------------- | -------- | ------ | --------------- | ----------- | +| PYTHON_VERSION | yes | string | "3.10" | Python version to use | +| HELM_VERSION | yes | string | "v3.12.3" | Helm version to use | +| HELM_RELEASE | yes | string | "test" | Helm release name | +| HELM_NAMESPACE | yes | string | "test" | Helm namespace name | +| MATTERMOST_WEBHOOK_URL | no | string | | Webhook URL to send notifications on Mattermost | + +#### Example of usage + +/ + --- ### mattermost-notify diff --git a/helm-release-notify/action.yml b/helm-release-notify/action.yml new file mode 100644 index 0000000..5a8de1a --- /dev/null +++ b/helm-release-notify/action.yml @@ -0,0 +1,75 @@ +name: Release Helm Chart and Notify +description: Release Helm chart and notify on Mattermost +inputs: + HELM_VERSION: + description: 'Helm version to use' + required: true + default: 'v3.12.3' + HELM_DEPENDENCIES: + description: 'Helm dependencies' + required: false + INDEX_DIR: + description: 'Index directory' + required: true + default: '.' + CHARTS_DIR: + description: 'Charts directory' + required: true + default: '.' + TARGET_DIR: + description: 'Target directory to release' + required: true + default: 'test' + MATTERMOST_WEBHOOK_URL: + description: 'Webhook URL to send notifications on Mattermost' + required: false +runs: + using: 'composite' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.PRIVATE_KEY }} + owner: ${{ github.repository_owner }} + repositories: "helm-charts" + - name: Get Helm chart version + id: get-version + run: | + echo ::set-output name=version::$(yq eval '.version' ${{ inputs.CHARTS_DIR }}/Chart.yaml) + shell: bash + - name: Publish Helm chart + uses: tylerauerbeck/helm-gh-pages@main + with: + token: ${{ steps.app-token.outputs.token }} + charts_dir: ${{ inputs.CHARTS_DIR }} + index_dir: ${{ inputes.INDEX_DIR }} + charts_url: https://imio.github.io/helm-charts/ + owner: IMIO + repository: helm-charts + branch: gh-pages + target_dir: ${{ inputs.TARGET_DIR }} + helm_version: ${{ inputs.HELM_VERSION }} + dependencies: ${{ inputs.HELM_DEPENDENCIES }} + - name : Send notification on Mattermost + if: ${{ inputs.MATTERMOST_WEBHOOK_URL != '' }} + run: | + JOB_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + MESSAGE="Success : ${{ github.repository }} has published a Helm release with version ${{ steps.get-version.outputs.version }}. [Click here to see job on GitHub]($JOB_URL)" + curl -i -X POST -H 'Content-Type: application/json' -d "{\"text\": \"$MESSAGE\"}" ${{ inputs.MATTERMOST_WEBHOOK_URL }} + shell: bash + - name : Send failure notification on Mattermost + if: ${{ failure() && inputs.MATTERMOST_WEBHOOK_URL != '' }} + env: + IMAGE_NAME: ${{ inputs.IMAGE_NAME }} + IMAGE_TAG: ${{ inputs.IMAGE_TAG }} + NEW_IMAGE_TAGS: ${{ inputs.NEW_IMAGE_TAGS }} + run: | + JOB_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + MESSAGE="Error : Helm release has failed. (Repository: ${{ github.repository }}) [Click here to see job on GitHub]($JOB_URL)" + curl -i -X POST -H 'Content-Type: application/json' -d "{\"text\": \"$MESSAGE\"}" ${{ inputs.MATTERMOST_WEBHOOK_URL }} + shell: bash \ No newline at end of file diff --git a/helm-test-notify/action.yml b/helm-test-notify/action.yml new file mode 100644 index 0000000..8c15fab --- /dev/null +++ b/helm-test-notify/action.yml @@ -0,0 +1,63 @@ +name: Lint and Test Helm Chart and Notify +description: Lint and test Helm chart and notify on Mattermost +inputs: + PYTHON_VERSION: + description: 'Python version to use' + required: true + default: '3.10' + HELM_VERSION: + description: 'Helm version to use' + required: true + default: 'v3.12.3' + HELM_RELEASE: + description: 'Helm release name' + required: true + default: 'test' + HELM_NAMESPACE: + description: 'Helm namespace name' + required: true + default: 'test' + MATTERMOST_WEBHOOK_URL: + description: 'Webhook URL to send notifications on Mattermost' + required: false +runs: + using: 'composite' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + with: + version: ${{ inputs.HELM_VERSION }} + - uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.PYTHON_VERSION }} + check-latest: true + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.6.1 + - name: Run chart-testing (lint) + run: ct lint --chart-dirs . --charts . --target-branch ${{ github.event.repository.default_branch }} + shell: bash + - name: Create kind cluster + uses: helm/kind-action@v1.10.0 + - name: Run chart-testing (install) + # run: ct install --chart-dirs . --charts . --target-branch ${{ github.event.repository.default_branch }} + # can't use it until https://github.com/helm/chart-testing/issues/310 is resolved + run: helm install ${{ inputs.HELM_RELEASE }} . -f values.yaml --namespace ${{ inputs.HELM_NAMESPACE }} --create-namespace + shell: bash + - name : Send notification on Mattermost + if: ${{ inputs.MATTERMOST_WEBHOOK_URL != '' }} + run: | + JOB_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + MESSAGE="Success : helm lint and tests. (Repository: ${{ github.repository }}, Branch: ${{ github.ref_name }}, Commit: ${{ github.sha }}) [Click here to see job on GitHub]($JOB_URL)" + curl -i -X POST -H 'Content-Type: application/json' -d "{\"text\": \"$MESSAGE\"}" ${{ inputs.MATTERMOST_WEBHOOK_URL }} + shell: bash + - name : Send failure notification on Mattermost + if: ${{ failure() && inputs.MATTERMOST_WEBHOOK_URL != '' }} + run: | + JOB_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + MESSAGE="Error : helm lint and tests have failed. (Repository: ${{ github.repository }}, Branch: ${{ github.ref_name }}, Commit: ${{ github.sha }}) [Click here to see job on GitHub]($JOB_URL)" + curl -i -X POST -H 'Content-Type: application/json' -d "{\"text\": \"$MESSAGE\"}" ${{ inputs.MATTERMOST_WEBHOOK_URL }} + shell: bash \ No newline at end of file