From ee961e87c10b9ea3914ff41396761f5a385530eb Mon Sep 17 00:00:00 2001 From: Jamie Zieziula Date: Wed, 2 Oct 2024 16:49:21 -0400 Subject: [PATCH] Add `Notify on Failure` workflow alert & minor linting/deps (#45) * failure workflow and minor linting * contributing * remove main branch' --------- Co-authored-by: jamie zieziula --- .github/workflows/helm-chart-release.yaml | 7 +++- .github/workflows/notify-on-failure.yaml | 46 +++++++++++++++++++++ .github/workflows/release-build-deploy.yaml | 6 +-- .gitignore | 3 ++ .mise.toml | 6 +++ .pre-commit-config.yaml | 10 +++++ CONTRIBUTING.md | 12 ++++++ 7 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/notify-on-failure.yaml create mode 100644 .mise.toml create mode 100644 CONTRIBUTING.md diff --git a/.github/workflows/helm-chart-release.yaml b/.github/workflows/helm-chart-release.yaml index 10c13d8..e86bea2 100644 --- a/.github/workflows/helm-chart-release.yaml +++ b/.github/workflows/helm-chart-release.yaml @@ -1,11 +1,14 @@ -name: Create prefect-helm release +--- +name: Trigger Downstream Helm Chart Release -on: +"on": # As soon as this repo creates an official release, we will # create a corresponding release in the helm chart repo release: types: [released] +permissions: {} + jobs: create_helm_release: runs-on: ubuntu-latest diff --git a/.github/workflows/notify-on-failure.yaml b/.github/workflows/notify-on-failure.yaml new file mode 100644 index 0000000..5745c3e --- /dev/null +++ b/.github/workflows/notify-on-failure.yaml @@ -0,0 +1,46 @@ +--- +name: Notify on Failure + +"on": + workflow_run: + workflows: + - Build and Publish prometheus-prefect-exporter Image + - Trigger Downstream Helm Chart Release + types: [completed] + +permissions: {} + +jobs: + notify: + name: Notify on Failure + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + permissions: + # required to introspect the workflow run + actions: read + # required to read from the repo + contents: read + steps: + - name: Format date + run: | + formatted_date=$(date -d "${{ github.event.workflow_run.run_started_at }}" "+%b %d at %I:%M %p") + echo "FORMATTED_DATE=$formatted_date" >> $GITHUB_ENV + + - name: Send Slack notification + uses: 8398a7/action-slack@v3 + with: + status: custom + # https://api.slack.com/reference/messaging/attachments + custom_payload: | + { + attachments: [{ + pretext: ':x: Workflow triggered by ${{ github.actor }} failed', + title: '${{ github.event.workflow_run.display_title }} #${{github.event.workflow_run.run_number}}', + title_link: '${{ github.event.workflow_run.html_url }}', + footer: '${{ github.repository }} | ${{ env.FORMATTED_DATE }} UTC', + footer_icon: 'https://slack-imgs.com/?c=1&o1=wi32.he32.si&url=https%3A%2F%2Fslack.github.com%2Fstatic%2Fimg%2Ffavicon-neutral.png', + color: 'danger', + }] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_GHA_JOB_STATUS }} diff --git a/.github/workflows/release-build-deploy.yaml b/.github/workflows/release-build-deploy.yaml index 1d3236e..7ef181d 100644 --- a/.github/workflows/release-build-deploy.yaml +++ b/.github/workflows/release-build-deploy.yaml @@ -1,17 +1,17 @@ -name: Build and publish prometheus-prefect-exporter image +--- +name: Build and Publish prometheus-prefect-exporter Image "on": push: tags: - '*' -# Do not grant jobs any permissions by default permissions: {} jobs: build_push_exporter: permissions: - # required to clone repository + # required to read from the repo contents: read runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index d9c18c0..0725357 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # Python artifacts __pycache__/ + +# OS +.DS_Store diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..3638bae --- /dev/null +++ b/.mise.toml @@ -0,0 +1,6 @@ +[tools] +actionlint = '1.7.1' +pre-commit = '3.7.1' +python = '3.11' +ruff = '0.4.9' +shellcheck = '0.10.0' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 299ab08..29d87f9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,7 @@ repos: - id: end-of-file-fixer - id: no-commit-to-branch - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.2.1 hooks: @@ -13,7 +14,16 @@ repos: language_version: python3 args: [--fix, --exit-non-zero-on-fix, --show-fixes] - id: ruff-format + + - repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.7.2 + hooks: + - id: shellcheck + args: ["--severity=error"] + - repo: https://github.com/rhysd/actionlint rev: v1.7.1 hooks: - id: actionlint + args: + - -shellcheck= diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4a62a96 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,12 @@ +# Contributing to Prometheus Prefect Exporter + +## Local development + +To get started, ensure you have the required dependencies installed: + +```shell +mise install +``` + +Be sure to run `pre-commit install` before starting any development. [`pre-commit`](https://pre-commit.com/) +will help catch simple issues before committing.