Skip to content

Commit

Permalink
ci/cd: add dependabot and Workflow runs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Jun 30, 2022
1 parent 9a25d22 commit bdc6303
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/actions/notify/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Define notification message
description: Identify an appropriate notification message.
branding:
icon: 'message-square'
color: 'green'

inputs:
emoji:
description: Prefix for the title.
default: 🤖

channel:
description: Notification channel.
required: true

success:
description: Is the result successful?
required: true
default: 'true'

runs:
using: composite
steps:
- name: Define notification message
id: message
run: |
if [ '${{ github.event.head_commit.message != null }}' == 'true' ]
then
(cat <<-message
txt=${{ github.event.head_commit.message }}
message
) | head -1 >> $GITHUB_OUTPUT
elif [ '${{ github.event.inputs.reason != null }}' == 'true' ]
then
(cat <<-message
txt=${{ github.event.inputs.reason }}
message
) | head -1 >> $GITHUB_OUTPUT
elif [ '${{ github.event.schedule != null }}' == 'true' ]
then
echo txt='regular healthcheck' >> $GITHUB_OUTPUT
else
echo Cannot define notification message && exit 1
fi
shell: bash

- name: Send Slack notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: ${{ inputs.success == 'true' && 'success' || 'failure' }}
SLACK_FOOTER: made with ❤️ for everyone by <https://www.octolab.org/|OctoLab>
SLACK_ICON: https://cdn.octolab.org/geek/octolab.png
SLACK_MESSAGE: ${{ steps.message.outputs.txt }}
SLACK_TITLE: '${{ inputs.emoji }} ${{ github.repository }}: ${{ github.workflow }}'
SLACK_USERNAME: Notifier
SLACK_WEBHOOK: ${{ inputs.channel }}
32 changes: 32 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2

updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
time: '05:00'
timezone: UTC
labels:
- 'type: improvement'
- 'scope: inventory'
- 'scope: deps'
commit-message:
prefix: 'ci/cd'
include: 'scope'
open-pull-requests-limit: 30

- package-ecosystem: docker
directory: /
schedule:
interval: daily
time: '05:00'
timezone: UTC
labels:
- 'type: improvement'
- 'scope: inventory'
- 'scope: deps'
commit-message:
prefix: 'ci/cd'
include: 'scope'
open-pull-requests-limit: 30
61 changes: 61 additions & 0 deletions .github/workflows/cleanup.runs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Workflow runs cleanup

on:
schedule:
- cron: 0 6 1 * * # at 06:00 on day-of-month 1, UTC

workflow_dispatch:
inputs:
pattern:
description: The name of workflow to clean.
type: choice
options:
- All
- Continuous delivery
- Workflow runs cleanup
default: Workflow runs cleanup
required: true
dry_run:
description: Only log actions, do not perform any delete operations.
type: boolean
required: false
reason:
description: The reason for dispatching it manually.
type: string
default: manual healthcheck
required: true

jobs:
delete:
name: Deleting
runs-on: ubuntu-latest

steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
delete_workflow_pattern: ${{ github.event.inputs.pattern || 'all' }}
dry_run: ${{ fromJSON('["", "true"]')[github.event.inputs.dry_run == 'true'] }}
retain_days: 0
keep_minimum_runs: 0

notify:
name: Notifying
needs: [ delete ]
runs-on: ubuntu-latest
if: failure() || success()

steps:
- name: Checkout the repository
uses: actions/checkout@v4
with: { fetch-depth: 0 }

- name: Send notification
uses: ./.github/actions/notify
continue-on-error: true
with:
emoji: 🧹
channel: ${{ secrets.SLACK_WEBHOOK }}
success: ${{ ! contains(needs.*.result, 'failure') }}

0 comments on commit bdc6303

Please sign in to comment.