Skip to content

Commit

Permalink
[CI/CD] Implement slack notifications for test-dbt-installation-* w…
Browse files Browse the repository at this point in the history
…orkflows (#69)


test-dbt-installation-notify-job-statuses.yml:
- Added initial implementation;

test-dbt-installation-main.yml:
- Enabled schedule trigger;

test-dbt-installation-docker.yml:
- Added step to dump job status;
- Added steps to generate artifact name and upload artifact;
- Added step to generate statistics regarding jobs;

test-dbt-installation-homebrew.yml:
- Main job was renamed;
- Added step to dump job status;
- Added steps to generate artifact name and upload artifact;
- Added step to generate statistics regarding jobs;

test-dbt-installation-pip.yml:
- Added step to dump job status;
- Added steps to generate artifact name and upload artifact;
- Added step to generate statistics regarding jobs;

test-dbt-installation-sources.yml:
- Added step to dump job status;
- Added steps to generate artifact name and upload artifact;
- Added step to generate statistics regarding jobs;
  • Loading branch information
alexander-smolyakov committed Jan 25, 2023
1 parent be4f866 commit ba5ae9a
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 37 deletions.
52 changes: 45 additions & 7 deletions .github/workflows/test-dbt-installation-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,24 @@ permissions:
env:
GITHUB_PACKAGES_LINK: "ghcr.io"
NOTIFICATION_PREFIX: "[Docker Installation Tests]"
ARTIFACT_BASENAME: "docker-installation-test"
ARTIFACT_RETENTION_DAYS: 1

jobs:
generate-artifact-name:
runs-on: ubuntu-latest

outputs:
artifact-name: ${{ steps.artifact-name.outputs.name }}

steps:
- name: "Generate Artifact Name"
id: artifact-name
run: |
date=$(date +'%m%d%Y')
name="${{ env.ARTIFACT_BASENAME }}-$date"
echo "name=$name" >> $GITHUB_OUTPUT
fetch-container-tags:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -85,7 +101,7 @@ jobs:
docker-installation-test:
runs-on: ubuntu-latest
needs: fetch-container-tags
needs: [fetch-container-tags, generate-artifact-name]

strategy:
fail-fast: false
Expand Down Expand Up @@ -119,15 +135,37 @@ jobs:
image: ${{ steps.image-info.outputs.ref }}
run: dbt --version

slack-notification:
name: "Post Scheduled Run Failures"
needs: docker-installation-test
- name: "Dump Job Status"
if: ${{ always() }}
id: job-status
run: |
file="test-${{ strategy.job-index }}-tag-${{ matrix.tag }}.json"
# Create file
touch $file
# Write job status to file
echo $JOB_STATUS >> $file
# Set path to file for subsequent steps
echo "path=$file" >> $GITHUB_OUTPUT
env:
JOB_STATUS: ${{ toJson(job.status) }}

- name: "Upload Job Status For Slack Notification"
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: ${{ needs.generate-artifact-name.outputs.artifact-name }}
path: ${{ steps.job-status.outputs.path }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

send-slack-notification:
needs: [generate-artifact-name, docker-installation-test]
if: ${{ failure() && github.event_name == 'schedule' }}

uses: dbt-labs/dbt-release/.github/workflows/slack-post-notification.yml@main
uses: ./.github/workflows/test-dbt-installation-notify-job-statuses.yml
with:
status: "failure"
notification_title: "Docker nightly integration test failed for - ${{ inputs.package_name }}"
artifact_name: ${{ needs.generate-artifact-name.outputs.artifact-name }}
installation_method: "Docker"
package_name: ${{ inputs.package_name }}

secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
55 changes: 48 additions & 7 deletions .github/workflows/test-dbt-installation-homebrew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,28 @@ on:
permissions:
contents: read # required for slack-post-notification workflow

env:
ARTIFACT_BASENAME: "homebrew-installation-test"
ARTIFACT_RETENTION_DAYS: 1

jobs:
homebrew-integration-test:
generate-artifact-name:
runs-on: ubuntu-latest

outputs:
artifact-name: ${{ steps.artifact-name.outputs.name }}

steps:
- name: "Generate Artifact Name"
id: artifact-name
run: |
date=$(date +'%m%d%Y')
name="${{ env.ARTIFACT_BASENAME }}-$date"
echo "name=$name" >> $GITHUB_OUTPUT
homebrew-installation-test:
runs-on: macos-11
needs: generate-artifact-name

steps:
- name: "Prepare Brew"
Expand Down Expand Up @@ -68,15 +87,37 @@ jobs:
run: |
dbt --version
slack-notification:
name: "Post Scheduled Run Failures"
needs: homebrew-integration-test
- name: "Dump Job Status"
if: ${{ always() }}
id: job-status
run: |
file="test-${{ inputs.package_name }}.json"
# Create file
touch $file
# Write job status to file
echo $JOB_STATUS >> $file
# Set path to file for subsequent steps
echo "path=$file" >> $GITHUB_OUTPUT
env:
JOB_STATUS: ${{ toJson(job.status) }}

- name: "Upload Job Status For Slack Notification"
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: ${{ needs.generate-artifact-name.outputs.artifact-name }}
path: ${{ steps.job-status.outputs.path }}
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}

send-slack-notification:
needs: [generate-artifact-name, homebrew-installation-test]
if: ${{ failure() && github.event_name == 'schedule' }}

uses: dbt-labs/dbt-release/.github/workflows/slack-post-notification.yml@main
uses: ./.github/workflows/test-dbt-installation-notify-job-statuses.yml
with:
status: "failure"
notification_title: "Homebrew nightly integration test failed for - ${{ inputs.package_name }}"
artifact_name: ${{ needs.generate-artifact-name.outputs.artifact-name }}
installation_method: "Homebrew"
package_name: ${{ inputs.package_name }}

secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
26 changes: 16 additions & 10 deletions .github/workflows/test-dbt-installation-main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# **what?**
# Launch all dbt installations tests from one workflow

# **why?**
# Simplify the process of launching and tracking of installations tests

# **when?**
# This workflow will run on a schedule every night and also can be
Expand Down Expand Up @@ -28,14 +30,15 @@ on:
- "source"

# run this once per night to ensure no regressions
# schedule:
# - cron: "0 9,13,18 * * *" # 9:00, 13:00, 18:00 UTC
schedule:
- cron: "0 9,13,18 * * *" # 9:00, 13:00, 18:00 UTC

jobs:
dbt-installation-homebrew:
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'homebrew'
github.event_name == 'schedule'
|| (inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'homebrew')
strategy:
fail-fast: false
Expand All @@ -51,8 +54,9 @@ jobs:

dbt-installation-pip:
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'pip'
github.event_name == 'schedule'
|| (inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'pip')
strategy:
fail-fast: false
matrix:
Expand All @@ -73,8 +77,9 @@ jobs:

dbt-installation-docker:
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'docker'
github.event_name == 'schedule'
|| (inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'docker')
strategy:
fail-fast: false
matrix:
Expand All @@ -95,8 +100,9 @@ jobs:

dbt-installation-source:
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'source'
github.event_name == 'schedule'
|| (inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'source')
strategy:
fail-fast: false
matrix:
Expand Down
113 changes: 113 additions & 0 deletions .github/workflows/test-dbt-installation-notify-job-statuses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# **what?**
# Check dumps of installation test jobs to aggregate statistics
# and send the Slack notification.

# **why?**
# A consistent way to notify about failed dbt installation test
# and provide additional context for the notification.

# **when?**
# When dbt installation test failed.
# This reusable workflow can be launched on call by specifying:
# artifact_name - that contains jobs dump
# package_name - dbt adapter/repo/container that was tested
# installation_method - installation method that failed

name: dbt Installation - Notify Job Statuses In Slack

on:
workflow_call:
inputs:
artifact_name:
required: true
type: string
installation_method:
required: true
type: string
package_name:
required: true
type: string
secrets:
SLACK_WEBHOOK_URL:
description: Slack app webhook url
required: true

jobs:
get-jobs-statuses:
name: "Check Job Statuses"
runs-on: ubuntu-latest

outputs:
jobs-statuses: ${{ steps.get-job_statistics.outputs.result }}

steps:
- name: "Download Artifact ${{ inputs.artifact_name }}"
uses: actions/download-artifact@v3
with:
name: ${{ inputs.version_number }}
path: .

- name: "[DEBUG] Display Structure Of All Downloaded Files"
run: ls -R

- name: "Generate Slack Message"
uses: actions/github-script@v6
id: get-job_statistics
with:
result-encoding: string
script: |
const fs = require('fs');
const path = require('path');
const artifact_folder = './${{ inputs.artifact_name }}'
const JOB_STATUSES_ENUM = {
success: "success",
failure: "failure",
cancelled: "cancelled"
};
const jobs_statuses = {
failure: [],
success: [],
cancelled: [],
undefined: []
};
const files_list = fs.readdirSync(artifact_folder);
core.debug(files_list);
files_list.map(file => {
const buffer = fs.readFileSync(`${artifact_folder}/${file}`);
const jobs_status = buffer.toString().trim().replace(/['"]+/g, '');
switch (jobs_status) {
case JOB_STATUSES_ENUM.success:
jobs_statuses.success.push(file);
break;
case JOB_STATUSES_ENUM.failure:
jobs_statuses.failure.push(file);
break;
case JOB_STATUSES_ENUM.cancelled:
jobs_statuses.cancelled.push(file);
break;
default:
jobs_statuses.undefined.push(file);
}
});
const job_statistics = `Test jobs statuses: ${JOB_STATUSES_ENUM.success} - ${jobs_statuses.success.length}, ${JOB_STATUSES_ENUM.failure} - ${jobs_statuses.failure.length}, ${JOB_STATUSES_ENUM.cancelled} - ${jobs_statuses.cancelled.length}, undefined - ${jobs_statuses.undefined.length}.`;
core.debug(job_statistics);
return job_statistics;
slack-notification:
name: "Post Scheduled Run Failures"
needs: get-jobs-statuses

uses: dbt-labs/dbt-release/.github/workflows/slack-post-notification.yml@main
with:
status: "failure"
notification_title: "${{ inputs.installation_method }} nightly installation test failed for - ${{ inputs.package_name }}. ${{ needs.get-jobs-statuses.outputs.jobs-statuses }}"

secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Loading

0 comments on commit ba5ae9a

Please sign in to comment.