From 874d67804e4e4dc96a9aef52dbe26b78e356aeb3 Mon Sep 17 00:00:00 2001 From: Mila Page Date: Fri, 22 Mar 2024 13:37:42 -0700 Subject: [PATCH] Attempt to use an env var (may not work) --- .../workflows/internal-archive-release.yml | 58 +++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/.github/workflows/internal-archive-release.yml b/.github/workflows/internal-archive-release.yml index 0a701c8..9d01d86 100644 --- a/.github/workflows/internal-archive-release.yml +++ b/.github/workflows/internal-archive-release.yml @@ -32,14 +32,37 @@ defaults: shell: bash env: - PYTHON_TARGET_VERSION: 3.11 + PYTHON_TARGET_VERSION: 3.8 NOTIFICATION_PREFIX: "[Internal Archive Release]" TEMP_PROFILE_NAME: "temp_aws_profile" + HATCH_ADAPTERS: '["postgres"]' # Must be valid JSON + + jobs: + env-var-setup: + runs-on: ubuntu-latest + outputs: + is_hatch_adapter: ${{ steps.condition_check.outputs.is_hatch_adapter }} + steps: + - name: Check if dbms_name is not contained in HATCH_ADAPTERS + id: condition_check + env: + HATCH_ADAPTERS: "${{ env.HATCH_ADAPTERS }} + run: | + echo "HATCH_ADAPTERS=$HATCH_ADAPTERS" >> $GITHUB_ENV + ADAPTERS=$(jq -r '.' <<< "${HATCH_ADAPTERS}") + DBMS_NAME="${{ github.event.inputs.dbms_name }}" + if jq -e --arg dbms "$DBMS_NAME" '.[] <<< "${ADAPTERS}" | select(. == $dbms)'; then + echo "::set-output name=is_hatch_adapter::false" + else + echo "::set-output name=is_hatch_adapter::true" + fi + job-setup: name: Job Setup runs-on: ubuntu-latest + needs: [env-var-setup] steps: - name: "[DEBUG] Print Variables" run: | @@ -66,7 +89,7 @@ jobs: run-unit-tests: runs-on: ubuntu-latest - needs: [job-setup] + needs: [job-setup, env-var-setup] env: TOXENV: unit @@ -86,7 +109,8 @@ jobs: # Testing with Tox # - name: "Install Python Dependencies" - if: contains(fromJSON( '["redshift", "snowflake", "bigquery"]' ), inputs.dbms_name) + if: ! "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" + run: | python -m pip install --user --upgrade pip python -m pip install tox @@ -94,18 +118,18 @@ jobs: python -m tox --version - name: "Run Tests using tox" - if: contains(fromJSON( '["redshift", "snowflake", "bigquery"]' ), inputs.dbms_name) + if: ! "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" run: tox # # Testing with Hatch # - name: "Setup `hatch`" - if: contains(fromJSON('["postgres"]'), inputs.dbms_name) + if: "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main - name: "Run Tests using hatch" - if: contains(fromJSON('["postgres"]'), inputs.dbms_name) + if: "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" run: hatch run unit-tests:all #################### @@ -115,8 +139,8 @@ jobs: run-integration-tests: name: 'Integration Tests (Tox)' runs-on: ubuntu-latest - needs: [job-setup] - if: contains(fromJSON( '["redshift", "snowflake", "bigquery"]' ), inputs.dbms_name) + needs: [job-setup, env-var-setup] + if: ! "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" env: TOXENV: integration @@ -178,8 +202,8 @@ jobs: run-integration-tests-hatch: name: 'Integration Tests (Hatch)' - needs: [job-setup] - if: contains(fromJSON('["postgres"]'), inputs.dbms_name) + needs: [job-setup, env-var-setup] + if: "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" uses: "dbt-labs/dbt-postgres/.github/workflows/integration-tests.yml@main" with: @@ -194,7 +218,7 @@ jobs: create-internal-release: name: Create release for internal archive runs-on: ubuntu-latest - needs: [run-unit-tests, run-integration-tests, run-integration-tests-hatch] + needs: [env-var-setup, run-unit-tests, run-integration-tests, run-integration-tests-hatch] # Build artifact if # 1. All succeed # 2. Spark invoked (it runs tests via its in-repo workflow) @@ -253,13 +277,13 @@ jobs: v="${base}${new_number}" tee <<< "version = \"${v}\"" "${version_file}" if [ -f "${setup_file}" ]; then - sed -i "s/^package_version = \".*\"/package_version = \"${v}\"/" "${setup_file}" + sed -i "s/^package_version = .*$/package_version = \"${v}\"/" "${setup_file}" fi else v="${version_in_file}+build1" tee <<< "version = \"${v}\"" "${version_file}" if [ -f "${setup_file}" ]; then - sed -i "s/^package_version = \".*\"/package_version = \"${v}\"/" "${setup_file}" + sed -i "s/^package_version = .*$/package_version = \"${v}\"/" "${setup_file}" fi fi @@ -271,18 +295,18 @@ jobs: # 1. Build with setup.py # - name: "Build Distributions - scripts/build-dist.sh" - if: contains(fromJSON( '["redshift", "snowflake", "bigquery", "spark"]' ), inputs.dbms_name) + if: ! "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" run: scripts/build-dist.sh # # 2. Build with Hatch # - name: "Setup `hatch`" - if: contains(fromJSON('["postgres"]'), inputs.dbms_name) + if: "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main - name: "Build Distributions - hatch" - if: contains(fromJSON('["postgres"]'), inputs.dbms_name) + if: "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" run: hatch build ################### @@ -295,7 +319,7 @@ jobs: - name: "Check Distribution Descriptions" run: | version_file="dbt/adapters//__version__.py" - if [[ "${{ inputs.dbms_name }}" == 'postgres' ]]; then + if [[ "${{ needs.env-var-setup.outputs.is_hatch_adapter }}" == 'true' ]]; then hatch run build:check-all else twine check dist/*