はじめに
この記事は前回の記事(dbt+PipeRider+SQLite ユーズケース)に続いて、PipeRider GitHub Actionを導入して、GitHubでCI(Continuous Integration)と言うことを達成する。
先ずこの三つファイルをローカルプロジェクトのルート階層に付け加える
-
.github/workflows/ci.yml
- GitHubワークフローの定義 -
requirements.txt
- PipeRider Actionは正しく実行するように必要なPyPi packages -
profiles.yml
- dbtプロジェクトに関するprofiles
requirements.txt
dbt-sqlite
piperider
ci.yml
crypto.so
はUbuntuでdbt-sqliteの必要なライブラリー
name: piperider-ci
env:
# Eanble Debug
ACTIONS_STEP_DEBUG: true
on:
# Define the trigger on events; pull requests to the main branch
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
piperider-ci:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: download the crypto library
run: curl -LJO https://github.com/nalgeon/sqlean/releases/download/0.15.2/crypto.so
- name: PipeRider CLI Action
uses: InfuseAI/piperider-action@v0.4.1
id: piperider
env:
DBT_PROFILES_DIR: ${{ github.workspace }}
profiles.yml
sp500_index:
outputs:
dev:
type: sqlite
threads: 1
database: sp500
schema: 'main'
schemas_and_paths:
main: 'sp500.db'
schema_directory: '.'
extensions:
- './crypto'
target: dev
ローカルリポジトリをGitHubにプッシュする
[日本語版] Adding a local repository to GitHub using Gitを参考にする
.gitignore
Gitの管理対象から外すファイルがあったら、ルールを書き込んでいく。
例:
target/
dbt_packages/
__pycache__/
logs/
例のリポジトリのストラクチャー
├── .github
├── .piperider
├── analyses
├── macros
├── models
├── seeds
├── snapshots
├── tests
├── .gitignore
├── LICENSE
├── README.md
├── dbt_project.yml
├── profiles.yml
├── requirements.txt
└── sp500.db
Pull Requestを作成する
新たなbranchを作成する
git checkout -b action-test
第一モデルmodels/example/my_first_dbt_model.sql
を編集する
2022-01-05にPRICE.DATEを変更する
{{ config(materialized='view') }}
with source_data as (
select * from PRICE
left join SYMBOL ON SYMBOL.SYMBOL = PRICE.SYMBOL
WHERE PRICE.DATE = '2022-01-05'
)
select *
from source_data
ファイルの変更を記録して、GitHubのリポジトリへpushする
git commit -a -m "changed recorded date from 2022-01-04 to 2022-01-05"
git push
Pull requestはワークフローのrunを誘発して、runは終ったらレポートを生成する
以上
参考
PipeRider GitHub Action
ワークフローに Snowflake か Slack 通知の追加について