Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub action for posting daily CI summary #3126

Merged
merged 2 commits into from Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/workflows/alpine-32bit-build-and-test.yaml
Expand Up @@ -81,13 +81,3 @@ jobs:
with:
name: PostgreSQL log ${{ matrix.pg }}
path: postgres.log

- name: Slack Notification
if: failure() && github.event_name != 'pull_request'
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: '#ff0000'
SLACK_USERNAME: GitHub Action
SLACK_TITLE: Regression 32-bit PG${{ matrix.pg }} ${{ job.status }}
SLACK_MESSAGE: ${{ github.event.head_commit.message }}
uses: rtCamp/action-slack-notify@v2.0.2
10 changes: 0 additions & 10 deletions .github/workflows/apt-packages.yaml
Expand Up @@ -70,13 +70,3 @@ jobs:
if [ "$version" != "$installed_version" ];then
false
fi

- name: Slack Notification
if: failure() && github.event_name != 'pull_request'
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: '#ff0000'
SLACK_USERNAME: GitHub Action
SLACK_TITLE: APT Package ${{ matrix.image }} PG${{ matrix.pg }} ${{ job.status }}
SLACK_MESSAGE: ${{ github.event.head_commit.message }}
uses: rtCamp/action-slack-notify@v2.0.2
23 changes: 23 additions & 0 deletions .github/workflows/ci_summary.yaml
@@ -0,0 +1,23 @@
name: CI Summary
on:
schedule:
# run daily 8:00 CET on master branch
- cron: '0 7 * * *'
jobs:
ci_summary:
if: github.repository == 'timescale/timescaledb'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: "Build message"
env:
SLACK_CHANNEL: "CEKV5LMK3"
run: python scripts/gh_ci_summary.py > message.json

- name: "Notify Slack"
uses: krider2010/slack-bot-action@1.0.1
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
MESSAGE_FILE: message.json

10 changes: 0 additions & 10 deletions .github/workflows/linux-build-and-test.yaml
Expand Up @@ -160,13 +160,3 @@ jobs:
with:
name: Coredumps ${{ matrix.os }} ${{ matrix.name }} ${{ matrix.pg }}
path: coredumps

- name: Slack Notification
if: failure() && github.event_name != 'pull_request' && runner.os != 'macOS'
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: '#ff0000'
SLACK_USERNAME: GitHub Action
SLACK_TITLE: Regression ${{ matrix.os }} PG${{ matrix.pg }} ${{ matrix.name }} ${{ job.status }}
SLACK_MESSAGE: ${{ github.event.head_commit.message }}
uses: rtCamp/action-slack-notify@v2.0.2
10 changes: 0 additions & 10 deletions .github/workflows/rpm-packages.yaml
Expand Up @@ -70,13 +70,3 @@ jobs:
if [ "$version" != "$installed_version" ];then
false
fi

- name: Slack Notification
if: failure() && github.event_name != 'pull_request'
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: '#ff0000'
SLACK_USERNAME: GitHub Action
SLACK_TITLE: RPM Package ${{ matrix.image }} PG${{ matrix.pg }} ${{ job.status }}
SLACK_MESSAGE: ${{ github.event.head_commit.message }}
uses: rtCamp/action-slack-notify@v2.0.2
10 changes: 0 additions & 10 deletions .github/workflows/update-test.yaml
Expand Up @@ -44,13 +44,3 @@ jobs:
with:
name: Extension update diff ${{ matrix.pg }}
path: update_test.*.diff.*

- name: Slack Notification
if: failure() && github.event_name != 'pull_request'
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: '#ff0000'
SLACK_USERNAME: GitHub Action
SLACK_TITLE: Update test PG${{ matrix.pg }} ${{ job.status }}
SLACK_MESSAGE: ${{ github.event.head_commit.message }}
uses: rtCamp/action-slack-notify@v2.0.2
59 changes: 59 additions & 0 deletions scripts/gh_ci_summary.py
@@ -0,0 +1,59 @@
#!/usr/bin/python3

from datetime import datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add basic unit tests for this code similar to what we have for the Git hooks: https://github.com/timescale/timescaledb/blob/master/scripts/githooks/commit_msg_tests.py

Otherwise, there's a lot of Python code to "just trust" here.

import requests
import json
import os

# API reference: https://docs.github.com/en/rest/reference/actions#workflow-runs
# Slack message formatting: https://api.slack.com/reference/surfaces/formatting
url = 'https://api.github.com/repos/timescale/timescaledb/actions/runs?event=schedule&status=completed'

message=list()

def get_json(url):
response = requests.get(url)
return response.json()

# get runs from last 24 hours
def process_runs(runs):
failed=list()

for run in runs:
start = datetime.strptime(run['created_at'], "%Y-%m-%dT%H:%M:%SZ")
delta = datetime.now() - start

if delta.days >= 1:
break

if run['conclusion'] != 'success':
failed.append(run)

return failed

def print_run_details(run):
job_data = get_json(run['jobs_url'])
for job in job_data['jobs']:
if job['conclusion'] != 'success':
message.append("<{html_url}|{workflow_name} {name}>".format(workflow_name=run['name'], **job))

def print_summary(failed):
if len(failed) > 0:
message.append("Failed scheduled CI runs in last 24 hours:")
for run in failed:
print_run_details(run)
else:
message.append("No failed scheduled CI runs in last 24 hours :tada:")

try:
data = get_json(url)
failed = process_runs(data['workflow_runs'])
print_summary(failed)
except json.decoder.JSONDecodeError:
message.append("Error processing GitHub response")

slack_msg=dict()
slack_msg['channel'] = os.environ['SLACK_CHANNEL']
slack_msg['text'] = "\n".join(message)

print(json.dumps(slack_msg))