Skip to content
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

feat: use changed-files instead of jitterbit for deployment workflow [DE-231] #147

Merged
merged 52 commits into from
May 16, 2023
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
be53c1f
test: delete a dbt model
emily-flambe May 10, 2023
951376e
Merge branch 'main' into ec/dbt-deploy-fixes
emily-flambe May 12, 2023
92ef8b6
Revert "test: delete a dbt model"
emily-flambe May 12, 2023
047d1a6
Merge branch 'ec/dbt-deploy-fixes' of https://github.com/community-te…
emily-flambe May 12, 2023
6bc5a6c
Delete v_campaigns.sql
emily-flambe May 12, 2023
adfad09
Revert "Delete v_campaigns.sql"
emily-flambe May 12, 2023
4e7167b
Delete _3_partner_views__models.yml
emily-flambe May 12, 2023
2df092e
Revert "Delete _3_partner_views__models.yml"
emily-flambe May 12, 2023
d1690c1
science: rename a schema YML file (will the workflow remove the delet…
emily-flambe May 12, 2023
afe344f
Revert "science: rename a schema YML file (will the workflow remove t…
emily-flambe May 12, 2023
0408270
Merge branch 'main' into ec/dbt-deploy-fixes
emily-flambe May 12, 2023
5a812fc
feat: deploy new yml and yaml files
emily-flambe May 12, 2023
03b9cbe
feat: update descriptions (DAG -> dbt)
emily-flambe May 12, 2023
4e9ba2c
Create TEST_yaml_deploy.yml
emily-flambe May 12, 2023
b673565
fix: typo
emily-flambe May 12, 2023
85cab80
fix: another typo
emily-flambe May 12, 2023
a912e84
science: trivial change to dbt_project.yml
emily-flambe May 12, 2023
bc865f5
Delete TEST_yaml_deploy.yml
emily-flambe May 12, 2023
2acd8d3
Merge branch 'main' into ec/dbt-deploy-fixes
emily-flambe May 12, 2023
0aeb1c3
Merge branch 'main' into ec/dbt-deploy-fixes
emily-flambe May 12, 2023
cafe4bf
rename: v_campaigns to v_campaigns_RENAMED
emily-flambe May 12, 2023
0582a45
science: revert change to dbt_project.yml
emily-flambe May 12, 2023
8930543
Create test_workflow.yaml
emily-flambe May 12, 2023
34e9a7b
temp: modify deploy_dev.yaml to try new workflow
emily-flambe May 12, 2023
a02b30e
Update test_workflow.yaml
emily-flambe May 12, 2023
2b9c6da
meh: aesthetics
emily-flambe May 12, 2023
78ba818
science
emily-flambe May 12, 2023
fdd3d36
Delete _3_partner_views__models.yml
emily-flambe May 12, 2023
268843c
Update test_workflow.yaml
emily-flambe May 12, 2023
361ce59
Update test_workflow.yaml
emily-flambe May 12, 2023
342b419
Update test_workflow.yaml
emily-flambe May 12, 2023
541221f
Update test_workflow.yaml
emily-flambe May 12, 2023
237c0f3
Update test_workflow.yaml
emily-flambe May 12, 2023
2367295
Update test_workflow.yaml
emily-flambe May 12, 2023
2db489a
feat: use `changed-files` instead of `jitterbit`
emily-flambe May 12, 2023
f5a6ff9
clean: remove test workflow
emily-flambe May 12, 2023
52fe0db
revert: un-rename v_campaigns.sql
emily-flambe May 12, 2023
ebb1812
revert: un-delete schema yml
emily-flambe May 12, 2023
256ffbd
Merge branch 'main' into ec/dbt-deploy-renamed-files
emily-flambe May 15, 2023
a98706d
science: set fetch-depth to 2
emily-flambe May 16, 2023
efe25d8
Create v_campaigns_TEST.sql
emily-flambe May 16, 2023
0043405
science: rename file (what will the workflow do with fetch_depth = 2?)
emily-flambe May 16, 2023
bb2fd3a
science: set fetch_depth to 0
emily-flambe May 16, 2023
8e2964e
science: rename file that already exists on main
emily-flambe May 16, 2023
60f4f9f
fix: echo RENAMED uses outputs.all_old_new_renamed_files
emily-flambe May 16, 2023
c854e2e
science: create a new file
emily-flambe May 16, 2023
a71815a
Delete v_campaigns_TEST_3.sql
emily-flambe May 16, 2023
c58b16c
science: fetch_depth 2 and delete a file
emily-flambe May 16, 2023
6e66052
revert: no fetch_depth, rename the things back
emily-flambe May 16, 2023
4563d76
Merge branch 'main' into ec/dbt-deploy-renamed-files
emily-flambe May 16, 2023
c2a381a
docs: add comment explaining duplicate file quirk in dev deploys
emily-flambe May 16, 2023
9a677a5
Merge branch 'ec/dbt-deploy-renamed-files' of https://github.com/comm…
emily-flambe May 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 151 additions & 39 deletions .github/workflows/deploy_cta_dbt_models.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
name: Deploy Google Composer DAGs
name: Deploy dbt to Google Composer

# BEWARE DUPLICATE FILES IN YOUR DEV DEPLOYS:
# After you deploy a branch to dev, the workflow will always be comparing your branch to main -
# so if (for example) you create a file and then delete it after triggering the dev deploy,
# the workflow will deploy the file when you create it, but it WILL NOT subsequently delete it.
# This is because the run triggered by the commit deleting the file will compare `main` to your branch,
# neither of which contain the file you added and deleted, so no action will be taken.
# Since your earlier commit deployed the file, it will continue to linger in dev.
# (This quirk does not apply to prod deploys since the workflow only runs once, when the PR is merged.)

on:
workflow_call:
Expand All @@ -17,83 +26,186 @@ env:

jobs:
deploy:
name: Deploy Google Composer DAGs
name: Deploy dbt to Google Composer
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
contents: 'read'
id-token: 'write'
steps:

#############
### setup ###
#############

# Checkout repo, this needs to happen first
- name: Checkout
uses: actions/checkout@v3

# Keyless Auth!
- id: 'auth'
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0
with:
workload_identity_provider: ${{ env.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.GOOGLE_SERVICE_ACCOUNT }}
# Set up gcloud pointing to our airbyte-prod project

# Set up gcloud pointing to CTA project
- name: Set up Cloud SDK
uses: 'google-github-actions/setup-gcloud@v0'
with:
project_id: ${{ env.GOOGLE_PROJECT_ID }}

##########################
### deploy DAG changes ###
##########################
###########################
### deploy file changes ###
###########################

# Get list of files in last commit
- id: 'files'
name: Get list of changed files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
with:
format: 'csv'
include_all_old_new_renamed_files: "true"

- name: List all new/modified/deleted/renamed files
run: |
echo "NEW:"
for file in ${{ steps.changed-files.outputs.added_files }}; do
if [[ ${#file} > 0 ]]; then
echo "$file was added."
else
echo "No files added."
fi
done
echo "MODIFIED:"
for file in ${{ steps.changed-files.outputs.modified_files }}; do
if [[ ${#file} > 0 ]]; then
echo "$file was modified."
else
echo "No files modified."
fi
done
echo "RENAMED:"
for file in ${{ steps.changed-files.outputs.all_old_new_renamed_files }}; do
if [[ ${#file} > 0 ]]; then
export old_name="$(echo "$file" | cut -d ',' -f 1)"
export new_name="$(echo "$file" | cut -d ',' -f 2)"
echo "$old_name was renamed to $new_name."
else
echo "No files renamed."
fi
done
echo "DELETED:"
for file in ${{ steps.changed-files.outputs.deleted_files }}; do
if [[ ${#file} > 0 ]]; then
echo "$file was deleted."
else
echo "No files deleted."
fi
done
# Deploy each dbt file that was added/modified
- name: Deploy added or modified dbt models
id: 'add_modify_dbt'
# Deploy new, modified, or renamed files (new file name)
- name: Deploy new files
id: 'deploy_new'
run: |
mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.files.outputs.added_modified }}')
mapfile -d ',' -t renamed_files < <(printf '%s,' '${{ steps.files.outputs.renamed }}')
added_modified_renamed_files+=( "${added_modified_files[@]}" "${renamed_files[@]}" )
for file in "${added_modified_renamed_files[@]}"; do
# Search for the filename
if [[ $(find dbt-cta -name $(basename ${file})) ]] && [[ ${file} == *.sql ]]; then
# Get full path of DAG file
file_name=$(realpath ${file});
path_to_file=$(dirname ${file});
gcloud composer environments storage dags import \
--project=$GOOGLE_PROJECT_ID \
--location=us-central1 \
for file in ${{ steps.changed-files.outputs.added_files }}; do
if [[ ${#file} > 0 ]]; then
# Search for the filename
if [[ $(find dbt-cta -name $(basename ${file})) ]] && [[ ${file} == *.sql || ${file} == *.yml || ${file} == *.yaml ]]; then
# Get full path of file
file_name=$(realpath ${file});
path_to_file=$(dirname ${file});
gcloud composer environments storage dags import \
--project=$GOOGLE_PROJECT_ID \
--location=us-central1 \
--environment=$GOOGLE_COMPOSER_ENVIRONMENT \
--destination=cta-dags/${path_to_file} \
--source=${file_name}
echo "Deployed new file: $(basename ${file}))"
else
echo "No new files to deploy."
fi
fi
done
- name: Deploy modified files
id: 'deploy_modified'
run: |
for file in ${{ steps.changed-files.outputs.modified_files }}; do
if [[ ${#file} > 0 ]]; then
# Search for the filename
if [[ $(find dbt-cta -name $(basename ${file})) ]] && [[ ${file} == *.sql || ${file} == *.yml || ${file} == *.yaml ]]; then
# Get full path of file
file_name=$(realpath ${file});
path_to_file=$(dirname ${file});
gcloud composer environments storage dags import \
--project=$GOOGLE_PROJECT_ID \
--location=us-central1 \
--environment=$GOOGLE_COMPOSER_ENVIRONMENT \
--destination=cta-dags/${path_to_file} \
--source=${file_name}
echo "Deployed modified file: $(basename ${file}))"
else
echo "No modified files to deploy."
fi
fi
done
- name: Deploy renamed files
id: 'deploy_renamed'
run: |
for file in ${{ steps.changed-files.outputs.renamed_files }}; do
if [[ ${#file} > 0 ]]; then
# Search for the filename
if [[ $(find dbt-cta -name $(basename ${file})) ]] && [[ ${file} == *.sql || ${file} == *.yml || ${file} == *.yaml ]]; then
# Get full path of file
file_name=$(realpath ${file});
path_to_file=$(dirname ${file});
gcloud composer environments storage dags import \
--project=$GOOGLE_PROJECT_ID \
--location=us-central1 \
--environment=$GOOGLE_COMPOSER_ENVIRONMENT \
--destination=cta-dags/${path_to_file} \
--source=${file_name}
echo "Deployed renamed file: $(basename ${file}))"
else
echo "No renamed files to deploy."
fi
fi
done
# Delete any files that were removed or renamed (old file name)
- name: Delete renamed files
id: 'delete_renamed'
run: |
for file in ${{ steps.changed-files.outputs.all_old_new_renamed_files }}; do
export old_name="$(echo "$file" | cut -d ',' -f 1)"
export new_name="$(echo "$file" | cut -d ',' -f 2)"
if [[ ${#file} > 0 ]]; then
gcloud composer environments storage dags delete cta-dags/${old_name} \
--environment=$GOOGLE_COMPOSER_ENVIRONMENT \
--destination=cta-dags/${path_to_file} \
--source=${file_name}
echo "Deployed file: $(basename ${file}))"
else
echo "Skipping $(basename ${file})) (no new dbt to deploy)."
--project=$GOOGLE_PROJECT_ID \
--location=us-central1
echo "Deleted renamed file: ${old_name} (renamed to ${new_name})."
else
echo "No renamed files to delete."
fi
done
# Delete any dbt that was removed
- name: Delete removed dbt
id: 'remove_dbt'
- name: Delete removed files
id: 'delete_removed'
run: |
mapfile -d ',' -t removed_files < <(printf '%s,' '${{ steps.files.outputs.removed }}')
for file in "${removed_files[@]}"; do
for file in ${{ steps.changed-files.outputs.deleted_files }}; do
if [[ ${#file} > 0 ]]; then
gcloud composer environments storage dags delete cta-dags/${file} \
--environment=$GOOGLE_COMPOSER_ENVIRONMENT \
--project=$GOOGLE_PROJECT_ID \
--location=us-central1
echo "Deleted file: ${file}"
else
echo "No dbt to remove for file removed: ${file}"
else
echo "No files to delete"
fi
done