Skip to content

Commit

Permalink
feat(ci): reusable workflows (#1)
Browse files Browse the repository at this point in the history
* feat(ci): add notification

Signed-off-by: Evgeniy Frolov <[email protected]>

* chore(ci): update notification workflow

Signed-off-by: Evgeniy Frolov <[email protected]>

* chore(ci): add cleanup workflow update notification

Signed-off-by: Evgeniy Frolov <[email protected]>

---------

Signed-off-by: Evgeniy Frolov <[email protected]>
  • Loading branch information
Fral738 authored Dec 17, 2024
1 parent f39b126 commit 3f25f72
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: cleanup

on:
workflow_call:
inputs:
werfDir:
required: false
type: string
withoutKube:
required: false
type: string
werfRepo:
required: false
type: string
secrets:
cleanupToken:
description: "cleanup token"
required: true
kubeconfig:
required: false
githubToken:
required: true

defaults:
run:
shell: bash

jobs:
cleanup:
name: cleanup
runs-on: ubuntu-latest-16-cores
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install werf
uses: werf/actions/install@v2
with:
channel: alpha

- name: Cleanup
run: |
. $(werf ci-env github --as-file)
werf cleanup
env:
WERF_DIR: ${{ inputs.werfDir }}
WERF_WITHOUT_KUBE: ${{ inputs.withoutKube }}
GITHUB_TOKEN: ${{ secrets.githubToken }}
WERF_REPO_GITHUB_TOKEN: ${{ secrets.cleanupToken }}
WERF_KUBE_CONFIG_BASE64: ${{ secrets.kubeconfig }}
WERF_REPO: ${{ inputs.werfRepo }}
73 changes: 73 additions & 0 deletions .github/workflows/notification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: notification

on:
workflow_call:
secrets:
webhook:
description: "Loop webhook URL"
required: true
notificationChannel:
description: "Loop notification channel"
required: true
loopNotificationGroup:
description: "Loop notification group"
required: false

defaults:
run:
shell: bash

jobs:
notify:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Run workflow status conclusion manager
uses: technote-space/workflow-conclusion-action@v3

- if: env.WORKFLOW_CONCLUSION == 'failure'
name: get failed jobs
id: failed_jobs
run: |
echo 'failed<<EOF' >> $GITHUB_OUTPUT
echo "$(curl ${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq -r '.jobs[]| select (.conclusion == "failure") | .html_url')" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- if: env.WORKFLOW_CONCLUSION == 'failure' && (startsWith(github.ref, 'refs/pull/') || github.event_name == 'workflow_dispatch')
name: get user
id: get_user
run: |
echo username=$(curl ${{ github.api_url }}/users/${{ github.triggering_actor }} | jq -r '.name' | tr '[:upper:]' '[:lower:]' | tr " " . ) >> $GITHUB_OUTPUT
- if: "(env.WORKFLOW_CONCLUSION == 'failure' && ! startsWith(github.ref, 'refs/pull/') && github.event_name != 'workflow_dispatch' )"
name: Failure notify
uses: mattermost/action-mattermost-notify@master
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.webhook }}
MATTERMOST_CHANNEL: ${{ secrets.notificationChannel }}
TEXT: |
${{ secrets.loopNotificationGroup }} Прод упал :pepe_monkaw:
[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) ${{ github.ref_name }} :pepe_deadge:
Упавшие джобы:
${{ steps.failed_jobs.outputs.failed }}
- if: "env.WORKFLOW_CONCLUSION == 'success' && ! startsWith(github.ref, 'refs/pull/') && ! github.event_name == 'workflow_dispatch'"
name: Success notify
uses: mattermost/action-mattermost-notify@master
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.webhook }}
MATTERMOST_CHANNEL: ${{ secrets.notificationChannel }}
TEXT: |
Workflow успешно завершился :bender:
[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) ${{ github.ref_name }} :success:
- if: env.WORKFLOW_CONCLUSION == 'failure' && (startsWith(github.ref, 'refs/pull/') || github.event_name == 'workflow_dispatch')
name: Failure notify for PRs
uses: mattermost/action-mattermost-notify@master
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.webhook }}
MATTERMOST_CHANNEL: ${{ secrets.notificationChannel }}
TEXT: |
@${{ steps.get_user.outputs.username }} Проблема в ветке :press_f:
[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) ${{ github.ref_name }} :pepe_deadge:
Упавшие джобы:
${{ steps.failed_jobs.outputs.failed }}

0 comments on commit 3f25f72

Please sign in to comment.