Skip to content

Commit

Permalink
[CI/CD] Add implementation for test-dbt-installation-docker workflow (
Browse files Browse the repository at this point in the history
#67)


test-dbt-installation-docker:
- Added initial implementation;
- Updated workflow docs;

test-dbt-installation-main:
- Added selector to provide an ability to run specific dbt installation tests;
  • Loading branch information
alexander-smolyakov committed Jan 23, 2023
1 parent a8a0a0a commit bf7a74d
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 8 deletions.
90 changes: 86 additions & 4 deletions .github/workflows/test-dbt-installation-docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# **what?**
# This workflow pulls docker images with dbt adapters on board from GitHub Packages.
# Workflow pulls images with "1.*.latest" tags only.
# It then runs 'dbt --version' to verify the installation was successful.
# If it fails for the scheduled runs, it will post to our team alerts channel.

# **why?**
# This is a simple way to test all adapter installations at a single
# time. It allows us to test them on a schedule as well to check for
# any breaking dependency changes that might happen and alert us on it.

# **when?**
# This reusable workflow can be called or started manually
Expand All @@ -27,19 +34,94 @@ on:

permissions:
contents: read # required for slack-post-notification workflow
packages: read # required to fetch tags for a container

env:
GITHUB_PACKAGES_LINK: "ghcr.io"
NOTIFICATION_PREFIX: "[Docker Installation Tests]"

jobs:
docker-integration-test:
fetch-container-tags:
runs-on: ubuntu-latest

outputs:
latest-tags: ${{ steps.get-latest-tags.outputs.result }}

steps:
- name: "Fetch ${{ inputs.package_name }} Tags From ${{ env.GITHUB_PACKAGES_LINK }}"
# Description: Fetch tags for specific container and filter out `latest` tags
# GH API doc: https://docs.github.com/en/rest/packages?apiVersion=2022-11-28#list-package-versions-for-a-package-owned-by-an-organization
uses: actions/github-script@v6
id: get-latest-tags
with:
retries: 3
script: |
try {
const response = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
package_type: 'container',
package_name: '${{ inputs.package_name }}',
org: 'dbt-labs',
})
let tags = [];
if (response.data) {
const package_data = response.data;
for (const [key, value] of Object.entries(package_data)) {
if (value.metadata.container.tags) {
tags = tags.concat(value.metadata.container.tags)
}
}
tags = tags.filter(t => t.endsWith('latest'))
}
return tags
} catch (error) {
core.setFailed(error.message);
}
- name: "[ANNOTATION] ${{ inputs.package_name }} - tags to test"
run: |
title="${{ inputs.package_name }} - tags to test"
message="The workflow will run tests for the following tags of the ${{ inputs.package_name }} image: ${{ steps.get-latest-tags.outputs.result }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
docker-installation-test:
runs-on: ubuntu-latest
needs: fetch-container-tags

strategy:
fail-fast: false
matrix:
tag: ${{ fromJSON(needs.fetch-container-tags.outputs.latest-tags) }}

steps:
- name: "Output Package Name - ${{ inputs.package_name }}"
- name: "Resolve Image Ref"
id: image-info
run: |
# Link example: ghcr.io/dbt-labs/dbt-bigquery:1.3.latest
ref=${{ env.GITHUB_PACKAGES_LINK }}/dbt-labs/${{ inputs.package_name }}:${{ matrix.tag }}
echo "ref=$ref" >> $GITHUB_OUTPUT
- name: "[DEBUG] Show Docker Version"
run: |
docker version
- name: "Pull Image - ${{ steps.image-info.outputs.ref }}"
run: |
docker pull ${{ steps.image-info.outputs.ref }}
- name: "[DEBUG] Show Available Images"
run: |
echo ${{ inputs.package_name }}
docker image ls --all
- name: "Verify ${{ inputs.package_name }} Version"
uses: addnab/docker-run-action@v3
with:
registry: ${{ env.GITHUB_PACKAGES_LINK }}
image: ${{ steps.image-info.outputs.ref }}
run: dbt --version

slack-notification:
name: "Post Scheduled Run Failures"
needs: docker-integration-test
needs: docker-installation-test
if: ${{ failure() && github.event_name == 'schedule' }}

uses: dbt-labs/dbt-release/.github/workflows/slack-post-notification.yml@main
Expand Down
30 changes: 26 additions & 4 deletions .github/workflows/test-dbt-installation-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,33 @@ name: dbt Installation Tests

permissions:
contents: read # required for slack-post-notification workflow
packages: read # required to fetch tags for a container

on:
workflow_dispatch:
inputs:
test-installation-method:
description: "Choose installation method(s) to test"
required: true
type: choice
default: "all"
options:
- "all"
- "homebrew"
- "pip"
- "docker"
- "source"

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

jobs:
dbt-installation-homebrew:
if: ${{ always() }}
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'homebrew'
strategy:
fail-fast: false
matrix:
Expand All @@ -34,7 +50,9 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_TEST_CHANNEL }}

dbt-installation-pip:
if: ${{ always() }}
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'pip'
strategy:
fail-fast: false
matrix:
Expand All @@ -54,7 +72,9 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_TEST_CHANNEL }}

dbt-installation-docker:
if: ${{ always() }}
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'docker'
strategy:
fail-fast: false
matrix:
Expand All @@ -74,7 +94,9 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_TEST_CHANNEL }}

dbt-installation-source:
if: ${{ always() }}
if: >-
inputs.test-installation-method == 'all'
|| inputs.test-installation-method == 'source'
strategy:
fail-fast: false
matrix:
Expand Down

0 comments on commit bf7a74d

Please sign in to comment.