Skip to content

Commit

Permalink
refactor(dex): integrate base_trades check into dbt_run workflow
Browse files Browse the repository at this point in the history
- Move base_trades check from dex.yml into dbt_run.yml
- Remove inputs for base_trades changes and modified files
- Use step outputs directly in dbt_run.yml
- Simplify dex.yml by removing check-base-trades job
  • Loading branch information
Hosuke committed Jan 7, 2025
1 parent ec1dcaa commit 7e7ec04
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 46 deletions.
38 changes: 25 additions & 13 deletions .github/workflows/dbt_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ on:
description: 'DBT run for project'
required: true
type: string
base_trades_changes:
description: 'Whether there are base_trades changes'
required: false
type: string
default: 'false'
modified_base_trades:
description: 'List of modified base_trades files'
required: false
type: string
default: ''

jobs:
dbt-test:
Expand All @@ -26,6 +16,28 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check for base_trades changes
id: check_base_trades
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
git fetch origin ${{ github.base_ref }}
CHANGES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "dbt_subprojects/${{ inputs.project }}/models/.*/.*_base_trades\.sql$" || true)
else
CHANGES=$(git diff --name-only HEAD~1 | grep -E "dbt_subprojects/${{ inputs.project }}/models/.*/.*_base_trades\.sql$" || true)
fi
if [ ! -z "$CHANGES" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "modified_files=$CHANGES" >> $GITHUB_OUTPUT
echo "Found changes in base_trades files:"
echo "$CHANGES"
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No base_trades changes found"
fi
- name: Setup variables
run: | # Spellbook is a special case because it's not a subdirectory
Expand Down Expand Up @@ -66,11 +78,11 @@ jobs:
run: "dbt -x run $PROFILE --select state:modified --exclude tag:prod_exclude tag:remove --defer --state . --project-dir ${PROJECT_DIR}"

- name: Test base_trades changes
if: inputs.base_trades_changes == 'true'
if: steps.check_base_trades.outputs.has_changes == 'true'
working-directory: ${{env.PROJECT_DIR}}
run: |
dbt run $PROFILE --select dex_ci_trades_test --vars "{'MODIFIED_BASE_TRADES': '${{ inputs.modified_base_trades }}'}"
dbt test $PROFILE --select dex_ci_trades_test --vars "{'MODIFIED_BASE_TRADES': '${{ inputs.modified_base_trades }}'}"
dbt run $PROFILE --select dex_ci_trades_test --vars "{'MODIFIED_BASE_TRADES': '${{ steps.check_base_trades.outputs.modified_files }}'}"
dbt test $PROFILE --select dex_ci_trades_test --vars "{'MODIFIED_BASE_TRADES': '${{ steps.check_base_trades.outputs.modified_files }}'}"
- name: dbt test initial model(s)
run: "dbt test $PROFILE --select state:new state:modified --exclude tag:prod_exclude tag:remove --defer --state . --project-dir ${PROJECT_DIR}"
Expand Down
34 changes: 1 addition & 33 deletions .github/workflows/dex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,7 @@ concurrency:
cancel-in-progress: true

jobs:
check-base-trades:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check.outputs.has_changes }}
modified_files: ${{ steps.check.outputs.modified_files }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check for base_trades changes
id: check
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
git fetch origin ${{ github.base_ref }}
CHANGES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | grep -E "dbt_subprojects/dex/models/.*/.*_base_trades\.sql$" || true)
else
CHANGES=$(git diff --name-only HEAD~1 | grep -E "dbt_subprojects/dex/models/.*/.*_base_trades\.sql$" || true)
fi
if [ ! -z "$CHANGES" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "modified_files=$CHANGES" >> $GITHUB_OUTPUT
echo "Found changes in base_trades files:"
echo "$CHANGES"
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No base_trades changes found"
fi
dbt-run:
needs: check-base-trades
uses: ./.github/workflows/dbt_run.yml
with:
project: 'dex'
base_trades_changes: ${{ needs.check-base-trades.outputs.has_changes }}
modified_base_trades: ${{ needs.check-base-trades.outputs.modified_files }}
project: 'dex'

0 comments on commit 7e7ec04

Please sign in to comment.