-
Notifications
You must be signed in to change notification settings - Fork 134
Add CI check that vendored dbt-factory is byte-identical to upstream #168
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
Open
park-peter
wants to merge
2
commits into
databricks:main
Choose a base branch
from
park-peter:dbt-factory-vendor-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| name: dbt-factory vendor sync | ||
|
|
||
| # Verifies the vendored copy of databricks-dbt-factory has not drifted: | ||
| # 1. each vendored core file is byte-identical to the upstream release named in NOTICE; | ||
| # 2. the example and template copies are byte-identical to each other; | ||
| # 3. both NOTICE files cite the same upstream commit. | ||
| # The upstream commit is read from contrib/dbt_factory/NOTICE, so bumping the vendored | ||
| # version is a one-line NOTICE change and this check re-pins to it automatically. | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize] | ||
| paths: | ||
| - 'contrib/dbt_factory/**' | ||
| - 'contrib/templates/dbt-factory/**' | ||
| - '.github/workflows/dbt-factory-vendor-sync.yml' | ||
| merge_group: | ||
| types: [checks_requested] | ||
|
|
||
| jobs: | ||
| byte-identical: | ||
| runs-on: | ||
| group: databricks-protected-runner-group | ||
| labels: linux-ubuntu-latest | ||
|
|
||
| env: | ||
| UPSTREAM_REPO: https://github.com/mwojtyczka/databricks-dbt-factory | ||
| EXAMPLE_CORE: contrib/dbt_factory/src/databricks_dbt_factory | ||
| TEMPLATE_CORE: contrib/templates/dbt-factory/template/{{.project_name}}/src/databricks_dbt_factory | ||
| EXAMPLE_NOTICE: contrib/dbt_factory/NOTICE | ||
| TEMPLATE_NOTICE: contrib/templates/dbt-factory/template/{{.project_name}}/NOTICE | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - name: Verify vendored core is byte-identical to upstream | ||
| shell: bash | ||
| run: |- | ||
| set -euo pipefail | ||
|
|
||
| # --- 1. Read the pinned upstream commit from the example NOTICE --- | ||
| notice_sha() { grep -oE 'commit [0-9a-f]{40}' "$1" | head -1 | awk '{print $2}'; } | ||
| sha="$(notice_sha "$EXAMPLE_NOTICE")" | ||
| if [ -z "$sha" ]; then | ||
| echo "::error file=$EXAMPLE_NOTICE::could not find an 'Adapted from: commit <40-hex>' line" | ||
| exit 1 | ||
| fi | ||
| version="$(grep -oE '\(v[0-9]+\.[0-9]+\.[0-9]+\)' "$EXAMPLE_NOTICE" | head -1 | tr -d '()')" | ||
| echo "Vendored upstream commit: $sha (${version:-unknown version})" | ||
|
|
||
| # --- 2. Both NOTICE files must cite the same commit --- | ||
| tpl_sha="$(notice_sha "$TEMPLATE_NOTICE")" | ||
| if [ "$sha" != "$tpl_sha" ]; then | ||
| echo "::error::NOTICE files disagree on the upstream commit:" | ||
| echo " $EXAMPLE_NOTICE -> $sha" | ||
| echo " $TEMPLATE_NOTICE -> ${tpl_sha:-<none>}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # --- 3. Fetch upstream at exactly that commit --- | ||
| up="$(mktemp -d)" | ||
| git init --quiet "$up" | ||
| git -C "$up" remote add origin "$UPSTREAM_REPO" | ||
| git -C "$up" fetch --quiet --depth 1 origin "$sha" | ||
| git -C "$up" checkout --quiet FETCH_HEAD | ||
| up_core="$up/src/databricks_dbt_factory" | ||
|
|
||
| fail=0 | ||
|
|
||
| # --- 4. The two vendored copies must contain the same set of files --- | ||
| if ! diff <(cd "$EXAMPLE_CORE" && find . -type f | sort) \ | ||
| <(cd "$TEMPLATE_CORE" && find . -type f | sort) >/dev/null; then | ||
| echo "::error::example and template vendored copies contain different files:" | ||
| diff <(cd "$EXAMPLE_CORE" && find . -type f | sort) \ | ||
| <(cd "$TEMPLATE_CORE" && find . -type f | sort) || true | ||
| fail=1 | ||
| fi | ||
|
|
||
| # --- 5. Every vendored file: identical to upstream, and identical across copies --- | ||
| while IFS= read -r rel; do | ||
| ex="$EXAMPLE_CORE/$rel" | ||
| tpl="$TEMPLATE_CORE/$rel" | ||
| upf="$up_core/$rel" | ||
|
|
||
| if [ ! -f "$upf" ]; then | ||
| echo "::error file=$ex::vendored file '$rel' does not exist in upstream $sha" | ||
| fail=1 | ||
| continue | ||
| fi | ||
| if ! cmp -s "$ex" "$upf"; then | ||
| echo "::error file=$ex::'$rel' differs from upstream $sha" | ||
| diff -u "$upf" "$ex" | head -40 || true | ||
| fail=1 | ||
| fi | ||
| if ! cmp -s "$ex" "$tpl"; then | ||
| echo "::error file=$tpl::template copy of '$rel' differs from the example copy" | ||
| diff -u "$ex" "$tpl" | head -40 || true | ||
| fail=1 | ||
| fi | ||
| done < <(cd "$EXAMPLE_CORE" && find . -type f | sed 's|^\./||' | sort) | ||
|
|
||
| if [ "$fail" -ne 0 ]; then | ||
| echo "::error::vendored databricks-dbt-factory has drifted from upstream $sha." | ||
| echo "Re-vendor from upstream at that commit (or update NOTICE if the version changed) so the copies match." | ||
| exit 1 | ||
| fi | ||
| echo "OK: both vendored copies are byte-identical to upstream $sha and to each other." | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please limit to the contrib/dbt factory path, so it only triggers when those paths are changed.