-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/ci azure improvements #25
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
base: main
Are you sure you want to change the base?
Changes from all commits
a7bc860
5d795b2
46d1b7c
300d545
e47314f
0870cf2
ad10a3a
ded066b
6ce964d
2f84c3e
9f7adaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ on: # yamllint disable-line rule:truthy | |
| paths: | ||
| - transform/* | ||
| - transform/**/* | ||
| - automate/dbt/** | ||
|
|
||
| # Allows you to run this workflow manually from the Actions tab | ||
| workflow_dispatch: | ||
|
|
@@ -15,12 +16,60 @@ concurrency: | |
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| validate-branch: | ||
| name: Validate Branch | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout branch | ||
| uses: actions/checkout@v3.5.0 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
|
|
||
| - name: Set Secure Directory | ||
| run: git config --global --add safe.directory $GITHUB_WORKSPACE | ||
|
|
||
| - name: Validate branch naming and sync with main | ||
| run: automate/git/validate_branch.sh "${{ github.head_ref }}" "${{ github.base_ref }}" | ||
|
|
||
| detect-changes: | ||
| name: Detect dbt-related Changes | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| outputs: | ||
| dbt_changed: ${{ steps.check.outputs.dbt_changed }} | ||
|
|
||
| steps: | ||
| - name: Checkout branch | ||
| uses: actions/checkout@v3.5.0 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
|
|
||
| - name: Check for dbt-related changes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont know what this is for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those two lines just make sure the "what changed?" check is accurate.
|
||
| id: check | ||
| run: | | ||
| git fetch origin ${{ github.base_ref }} | ||
| CHANGED=$(git diff --name-only origin/${{ github.base_ref }} HEAD -- transform/ automate/dbt/) | ||
| if [ -n "$CHANGED" ]; then | ||
| echo "dbt_changed=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "dbt_changed=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| dbt: | ||
| name: Pull Request dbt Tests | ||
| needs: [validate-branch, detect-changes] | ||
| # always(): needed deps are skipped (not failed) on workflow_dispatch since they're PR-only; | ||
| # this still blocks on a real validate-branch failure, and requires a detected change on PRs. | ||
| if: ${{ always() && needs.validate-branch.result != 'failure' && (github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.dbt_changed == 'true') }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| # most people should use this one | ||
| container: datacoves/ci-basic-dbt-snowflake:3.3 | ||
| container: datacoves/ci-basic-dbt-snowflake:5.0 | ||
|
|
||
| defaults: | ||
| run: | ||
|
|
@@ -89,6 +138,15 @@ jobs: | |
|
|
||
|
|
||
| ##### Real dbt run given that we passed governance checks | ||
| # Slim CI: skip rebuilding models unchanged by this PR, clone their prod tables instead. | ||
| - name: Clone unchanged incremental models from prod | ||
| if: ${{ steps.prod_manifest.outputs.manifest_found == 'true' && contains(github.event.pull_request.labels.*.name, 'full-refresh') != true }} | ||
| run: "dbt clone -s state:modified+,config.materialized:incremental,state:old --state logs" | ||
|
|
||
| - name: Clone unchanged snapshot models from prod | ||
| if: ${{ steps.prod_manifest.outputs.manifest_found == 'true' && contains(github.event.pull_request.labels.*.name, 'full-refresh') != true }} | ||
| run: "dbt clone -s state:modified+,config.materialized:snapshot,state:old --state logs" | ||
|
|
||
| - name: Run dbt build slim mode | ||
| if: ${{ steps.prod_manifest.outputs.manifest_found == 'true' && contains(github.event.pull_request.labels.*.name, 'full-refresh') != true }} | ||
| run: "dbt build --fail-fast --defer --state logs --select state:modified+" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #! /bin/bash | ||
| set -e | ||
| cd "$DATACOVES__DBT_HOME" | ||
| git fetch --tags | ||
| date_version=$(date -u +%Y%m%d) | ||
| # Version scheme: YYYYMMDD.N.0, N = next unused sequence number for today. | ||
| last_sequence=$( | ||
| git tag --list "${date_version}.*" | | ||
| sed -E "s/^${date_version}\.([0-9]+)\..*/\1/" | | ||
| grep -E '^[0-9]+$' | sort -n | tail -1 | ||
| ) | ||
| if [ -z "$last_sequence" ]; then next_sequence=1; else next_sequence=$((last_sequence + 1)); fi | ||
| new_version="${date_version}.${next_sequence}.0" | ||
| # Anchored to line start so it only matches `version:`, not `config-version:`. | ||
| sed -i "s/^version:.*/version: '${new_version}'/g" dbt_project.yml | ||
| git add dbt_project.yml | ||
| # [skip ci] prevents this commit from retriggering push-to-main.yml. | ||
| git commit -m "Set deployment version to ${new_version} [skip ci]" | ||
| git tag -m "[skip ci]" "${new_version}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we checking branch names?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I implemented the |
||
| SOURCE_BRANCH="${1#refs/heads/}" | ||
| TARGET_BRANCH="${2#refs/heads/}" | ||
|
|
||
| if [ "$SOURCE_BRANCH" = "$TARGET_BRANCH" ]; then | ||
| echo "Source and target branch are the same ($SOURCE_BRANCH); skipping branch validation." | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ "$SOURCE_BRANCH" != feature/* && "$SOURCE_BRANCH" != infra/* ]]; then | ||
| echo "ERROR: Source branch '$SOURCE_BRANCH' must start with 'feature/' or 'infra/'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "$TARGET_BRANCH" != "main" ] && ! [[ "$SOURCE_BRANCH" == feature/* && "$TARGET_BRANCH" == feature/* ]]; then | ||
| echo "ERROR: Target branch must be 'main', or, for a feature/ source branch, another feature/ branch. Got '$TARGET_BRANCH'." | ||
| exit 1 | ||
| fi | ||
|
|
||
| git fetch origin main | ||
| # Require the PR branch to already contain latest main (avoids deploying stale merges). | ||
| commits_behind=$(git rev-list --count HEAD..origin/main) | ||
| if [ "$commits_behind" -gt 0 ]; then | ||
| echo "ERROR: Branch '$SOURCE_BRANCH' is $commits_behind commit(s) behind 'main'. Please merge/pull main into your branch and push again." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "$SOURCE_BRANCH" == infra/* ]]; then | ||
| changed_transform_files=$(git diff --name-only origin/main HEAD -- transform/) | ||
| if [ -n "$changed_transform_files" ]; then | ||
| echo "ERROR: infra/ branches cannot modify transform/. dbt model changes must use a feature/ branch." | ||
| echo "$changed_transform_files" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo "Branch validation passed: '$SOURCE_BRANCH' -> '$TARGET_BRANCH'." | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we need both versions * and **
look at this and ask claude
https://github.com/datacoves/balboa/blob/main/.github/workflows/10_feature_dbt_checks.yml#L8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It mirrors the existing
transform/*+transform/**/*style already in this file so the new paths matched the established convention. But you're right that it's redundant:automate/dbt/**already covers both direct and nested files, so I'll collapse it to a single line.