From 2f45bcc2574c10518aea5517921ff26989a286af Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 22:47:15 +0000 Subject: [PATCH 01/42] Try to build & publish a base image --- .github/workflows/docker-image.yml | 40 ++++++++++++++++++++++++++++++ Dockerfile.base | 17 +++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 Dockerfile.base diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..b997edc --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,40 @@ +name: Base Docker Image CI + +on: + push: + branches: [ main ] + paths: + - 'Dockerfile.base' + pull_request: + branches: [ main ] + paths: + - 'Dockerfile.base' + + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2.5.0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2.2.0 + + - name: Build and push Docker image + run: | + docker build \ + --file Dockerfile.base \ + --platform linux/amd64,linux/arm64 \ + --push \ + --tag ghcr.io/${{ github.repository }}:${{ github.sha }} \ No newline at end of file diff --git a/Dockerfile.base b/Dockerfile.base new file mode 100644 index 0000000..a76b4bb --- /dev/null +++ b/Dockerfile.base @@ -0,0 +1,17 @@ +FROM python:3.12.2-bookworm +ARG SDF_VERSION=0.1.192 + +# Install dependencies +RUN apt-get update && apt-get install -y \ + yq \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Install sdf +RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} + +# Install dbt-snowflake plugin using pip +RUN python3.12 -m venv .venv && . .venv/bin/activate \ + && python3 -m pip install dbt-snowflake==1.7.2 \ + && python3 -m pip install --upgrade dbt-core==1.7.9 \ + && python3 -m pip install protobuf==4.25.3 \ No newline at end of file From 563cd165e862fcb36144f2fb9477e832524ca88e Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 22:50:19 +0000 Subject: [PATCH 02/42] use buildx build --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b997edc..10fd3d0 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -33,7 +33,7 @@ jobs: - name: Build and push Docker image run: | - docker build \ + docker buildx build \ --file Dockerfile.base \ --platform linux/amd64,linux/arm64 \ --push \ From 0b988953daaa6eb95a446fd821839262bfe2e986 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 22:53:21 +0000 Subject: [PATCH 03/42] fix path --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 10fd3d0..479dceb 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -37,4 +37,4 @@ jobs: --file Dockerfile.base \ --platform linux/amd64,linux/arm64 \ --push \ - --tag ghcr.io/${{ github.repository }}:${{ github.sha }} \ No newline at end of file + --tag ghcr.io/${{ github.repository }}:${{ github.sha }} . \ No newline at end of file From 206624b8fc33d361ef763cedffc7df923bd75a7f Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 22:58:01 +0000 Subject: [PATCH 04/42] add aarch64 support --- Dockerfile.base | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile.base b/Dockerfile.base index a76b4bb..fcc8c47 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -8,7 +8,11 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* # Install sdf -RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} +RUN if [ "$(uname -m)" = "aarch64" ]; then \ + curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} --target aarch64-unknown-linux-gnu ; \ + else \ + curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} ; \ + fi # Install dbt-snowflake plugin using pip RUN python3.12 -m venv .venv && . .venv/bin/activate \ From af35f5b7ceb3cfdebec3b1fbc121843f60548fce Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 23:21:02 +0000 Subject: [PATCH 05/42] only push on merge main --- .github/workflows/docker-image.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 479dceb..78949e6 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,4 +1,4 @@ -name: Base Docker Image CI +name: Base sdf-action Docker Image (DBT based) on: push: @@ -6,11 +6,9 @@ on: paths: - 'Dockerfile.base' pull_request: - branches: [ main ] paths: - 'Dockerfile.base' - - + jobs: build: runs-on: ubuntu-latest @@ -30,11 +28,20 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v2.2.0 - - - name: Build and push Docker image + + - name: Build Docker image + if: github.event_name == 'pull' + run: | + docker buildx build \ + --file Dockerfile.base \ + --platform linux/amd64,linux/arm64 \ + --tag ghcr.io/${{ github.repository }}-dbt-base:latest . + + - name: Build and Push Docker image on main branch + if: github.event_name == 'push' && github.ref == 'refs/heads/main' run: | docker buildx build \ --file Dockerfile.base \ --platform linux/amd64,linux/arm64 \ --push \ - --tag ghcr.io/${{ github.repository }}:${{ github.sha }} . \ No newline at end of file + --tag ghcr.io/${{ github.repository }}-dbt-base:latest . \ No newline at end of file From 8c8a902f97767026cb59e47d77e0deaeebb7a039 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 23:23:39 +0000 Subject: [PATCH 06/42] fix event name --- Dockerfile | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2c8d7c2..67449a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,4 @@ -FROM python:3.12.2-bookworm -ARG SDF_VERSION=0.1.192 - -# Install dependencies -RUN apt-get update && apt-get install -y \ - yq \ - curl \ - && rm -rf /var/lib/apt/lists/* - -# Install sdf -RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} - -# Install dbt-snowflake plugin using pip -RUN python3.12 -m venv .venv && . .venv/bin/activate \ - && python3 -m pip install dbt-snowflake==1.7.2 \ - && python3 -m pip install --upgrade dbt-core==1.7.9 \ - && python3 -m pip install protobuf==4.25.3 +FROM ghcr.io/sdf-labs/sdf-action-base:latest # Copy your code file from your action repository to the filesystem path `/` of the container COPY entrypoint.sh /entrypoint.sh From d4f2a88bb824c5a42e1a7baf4f0144c493d44ef6 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 23:28:39 +0000 Subject: [PATCH 07/42] debug event_name --- .github/workflows/docker-image.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 78949e6..5628cea 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -28,9 +28,13 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v2.2.0 + + - name: Debug + run: | + echo "GitHub Event Name: ${{ github.event_name }}" - name: Build Docker image - if: github.event_name == 'pull' + if: github.event_name == 'pull_request' run: | docker buildx build \ --file Dockerfile.base \ From b6041b1e7e2fc6bea1bd26924eb48af956afab38 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 23:31:28 +0000 Subject: [PATCH 08/42] remove unused --- .github/workflows/docker-image.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 5628cea..de32949 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -28,10 +28,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v2.2.0 - - - name: Debug - run: | - echo "GitHub Event Name: ${{ github.event_name }}" - name: Build Docker image if: github.event_name == 'pull_request' From 8a109aed5754536df1fbf5d84c00669ae0ccef59 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 5 Apr 2024 23:32:29 +0000 Subject: [PATCH 09/42] revert, use base image after it's built --- Dockerfile | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 67449a8..2c8d7c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,20 @@ -FROM ghcr.io/sdf-labs/sdf-action-base:latest +FROM python:3.12.2-bookworm +ARG SDF_VERSION=0.1.192 + +# Install dependencies +RUN apt-get update && apt-get install -y \ + yq \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Install sdf +RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} + +# Install dbt-snowflake plugin using pip +RUN python3.12 -m venv .venv && . .venv/bin/activate \ + && python3 -m pip install dbt-snowflake==1.7.2 \ + && python3 -m pip install --upgrade dbt-core==1.7.9 \ + && python3 -m pip install protobuf==4.25.3 # Copy your code file from your action repository to the filesystem path `/` of the container COPY entrypoint.sh /entrypoint.sh From 128ea6dd4a98210590528204aa1e23a1a0b137a5 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Tue, 9 Apr 2024 16:48:25 +0000 Subject: [PATCH 10/42] name updates --- .github/workflows/{main.yml => examples-test.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{main.yml => examples-test.yml} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/examples-test.yml similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/examples-test.yml From 484cb5555acde36e00573c971f6e71e1d78f12f4 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Tue, 9 Apr 2024 17:25:38 +0000 Subject: [PATCH 11/42] update README --- README.md | 28 +++++++++++++++++++++++++++- action.yml | 6 +++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a06392..db27688 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,28 @@ # sdf-action -[WIP] A Github Action to run `sdf` CLI in workflows. +Github Action to run `sdf` CLI in workflows. + +## Usage +Check out this [example workflow](./.github/workflows/examples-test.yml) to see how to use this action. + +## Parameters + +* `snowflake_`* parameters are required if the `snowflake` table provider is used +* `aws_*` parameters are required if the `redshift` table provider is used +* `access_key` and `secret_key` are required if the `sdf push` is used in `command` + +| Parameter | Description | Required | Default | +| --- | --- | --- | --- | +| `command` | The `sdf` CLI command to run. | No | `sdf compile` +| `workspace_dir` | The directory of the workspace" | No | "." | +| `access_key` | access key created from the [console](https://console.sdf.com/catalog/settings/general) to be used in `sdf push` | No | | +| `secret_key` | secret key created from the [console](https://console.sdf.com/catalog/settings/general) to be used in `sdf push` | No | | +| `is_dbt` | Set to a non-empty string if the workspace is dbt based | No | false | "" +| `dbt_target` | The dbt target | No | "." | +| `snowflake_account_id` | The snowflake account | No | "" +| `snowflake_username` | The snowflake username | No | "" +| `snowflake_password` | The snowflake password | No | "" +| `snowflake_role` | The snowflake role | No | "" +| `snowflake_warehouse` | The snowflake warehouse | No | "" +| `aws_region` | The aws region | No | "" +| `aws_access_key_id` | The aws access key id created from an IAM user | No | "" +| `aws_secret_access_key` | The aws secret created from an IAM user | No | "" diff --git a/action.yml b/action.yml index 6f36e12..5f558ef 100644 --- a/action.yml +++ b/action.yml @@ -5,11 +5,11 @@ inputs: command: description: "The sdf command to run" default: "sdf compile" - required: true + required: false workspace_dir: description: "The directory of the workspace" default: "." - required: true + required: false access_key: description: "The access key" required: false @@ -18,7 +18,7 @@ inputs: required: false is_dbt: description: "Whether the workspace is dbt based or not" - required: true + required: false default: "" dbt_target: description: "The dbt target" From b057ab0dd7f071119fb73e70bff156d532732dac Mon Sep 17 00:00:00 2001 From: xuliangs Date: Tue, 9 Apr 2024 17:59:42 +0000 Subject: [PATCH 12/42] manually trigger a push --- .github/workflows/docker-image.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index de32949..ad7b394 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,13 +1,10 @@ name: Base sdf-action Docker Image (DBT based) on: - push: - branches: [ main ] - paths: - - 'Dockerfile.base' pull_request: paths: - 'Dockerfile.base' + workflow_dispatch: jobs: build: @@ -34,14 +31,14 @@ jobs: run: | docker buildx build \ --file Dockerfile.base \ - --platform linux/amd64,linux/arm64 \ - --tag ghcr.io/${{ github.repository }}-dbt-base:latest . + --platform linux/amd64,linux/arm64 . - - name: Build and Push Docker image on main branch - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + - name: Release Docker image + if: github.event_name == 'workflow_dispatch' run: | docker buildx build \ --file Dockerfile.base \ --platform linux/amd64,linux/arm64 \ --push \ - --tag ghcr.io/${{ github.repository }}-dbt-base:latest . \ No newline at end of file + --tag ghcr.io/${{ github.repository }}-dbt-base:latest \ + --tag ghcr.io/${{ github.repository }}-dbt-base:${{ github.run_number }} . \ No newline at end of file From 1b437da558c4572c6784e18cdccdc9c281f4b5ff Mon Sep 17 00:00:00 2001 From: xuliangs Date: Wed, 10 Apr 2024 18:37:53 +0000 Subject: [PATCH 13/42] Test run dbt steps outside the action --- .github/workflows/examples-test.yml | 95 +++++++++++++++++++++-------- entrypoint.sh | 18 +++--- 2 files changed, 76 insertions(+), 37 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index add3968..4cd2d52 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -4,17 +4,83 @@ on: pull_request: jobs: - dbt_init_challenge_job: + # dbt_init_challenge_job: + # runs-on: ubuntu-latest + # name: Run sdf push on a DBT + Snowflake workspace + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # - name: sdf push step + # uses: ./ # Uses an action in the root directory + # id: sdf + # with: + # command: 'sdf push' + # workspace_dir: 'workspace/dbt_init_challenge' + # access_key: ${{ secrets.ACCESS_KEY }} + # secret_key: ${{ secrets.SECRET_KEY }} + + # is_dbt: 'true' + # snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + # snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} + # snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} + # snowflake_role: 'dbt_test_role' + # snowflake_warehouse: 'dbt_dev_wh' + # dbt_target: 'dev' + + # # Use the output from the `sdf` step + # - name: Display the sdf output + # run: | + # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY + # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY + + # tpch_redshift: + # runs-on: ubuntu-latest + # name: Run sdf compile on a Redshift workspace + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # - name: sdf compile step + # uses: ./ # Uses an action in the root directory + # id: sdf + # with: + # command: 'sdf compile --show all' + # workspace_dir: 'workspace/tpch_redshift' + + # aws_region: 'us-west-2' + # aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + + # # Use the output from the `sdf` step + # - name: Display the sdf output + # run: | + # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY + # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY + + dbt_init_challenge: runs-on: ubuntu-latest name: Run sdf push on a DBT + Snowflake workspace steps: - name: Checkout uses: actions/checkout@v4 + - name: Run DBT commands + uses: mwhitaker/dbt-action@master + with: + dbt_command: "dbt deps && dbt compile" + dbt_project_folder: "workspace/dbt_init_challenge" + + # debug step + - name: List files in the workspace + run: ls -la workspace/dbt_init_challenge/target + - name: sdf push step uses: ./ # Uses an action in the root directory id: sdf with: - command: 'sdf push' + command: 'sdf compile' workspace_dir: 'workspace/dbt_init_challenge' access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} @@ -35,28 +101,3 @@ jobs: echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY echo '```' >>$GITHUB_STEP_SUMMARY - tpch_redshift: - runs-on: ubuntu-latest - name: Run sdf compile on a Redshift workspace - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: sdf compile step - uses: ./ # Uses an action in the root directory - id: sdf - with: - command: 'sdf compile --show all' - workspace_dir: 'workspace/tpch_redshift' - - aws_region: 'us-west-2' - aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - - # Use the output from the `sdf` step - - name: Display the sdf output - run: | - echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY - echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY - diff --git a/entrypoint.sh b/entrypoint.sh index 3a21b3a..296c7b1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,7 +20,7 @@ check_exit_status() { echo "$command_log" echo EOF } >>$GITHUB_OUTPUT - + echo "result=failed" >>$GITHUB_OUTPUT exit $exit_status fi @@ -34,16 +34,14 @@ if [[ $input_command == "sdf push"* ]]; then fi if [[ -n $input_is_dbt ]]; then - echo "python3 version - $(python3 --version)" - echo "::group::Setting up dbt" - echo "running dbt deps" - dbt deps - check_exit_status $? "" + # echo "running dbt deps" + # dbt deps + # check_exit_status $? "" - echo "running dbt compile" - dbt compile - check_exit_status $? "" + # echo "running dbt compile" + # dbt compile + # check_exit_status $? "" echo "running dbt compile done" sdf dbt refresh @@ -73,4 +71,4 @@ check_exit_status $exit_status "$log" echo "$log" echo EOF } >>$GITHUB_OUTPUT -echo "result=passed" >>$GITHUB_OUTPUT \ No newline at end of file +echo "result=passed" >>$GITHUB_OUTPUT From 1aad57bf5e08f4e1ccb28b5837de8f69085f1f68 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Wed, 10 Apr 2024 23:12:52 +0000 Subject: [PATCH 14/42] test dbt compile in a separate step --- .github/workflows/examples-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 4cd2d52..79a2bbc 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -69,7 +69,7 @@ jobs: - name: Run DBT commands uses: mwhitaker/dbt-action@master with: - dbt_command: "dbt deps && dbt compile" + dbt_command: "dbt compile" dbt_project_folder: "workspace/dbt_init_challenge" # debug step From c6949a66071026e633205c47a52b2034fd208a8e Mon Sep 17 00:00:00 2001 From: xuliangs Date: Wed, 10 Apr 2024 23:24:10 +0000 Subject: [PATCH 15/42] add env vars --- .github/workflows/examples-test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 79a2bbc..2be2ac1 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -68,6 +68,10 @@ jobs: uses: actions/checkout@v4 - name: Run DBT commands uses: mwhitaker/dbt-action@master + env: + DBT_TARGET: dev + SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} with: dbt_command: "dbt compile" dbt_project_folder: "workspace/dbt_init_challenge" @@ -80,7 +84,7 @@ jobs: uses: ./ # Uses an action in the root directory id: sdf with: - command: 'sdf compile' + command: 'sdf compile --profiles-dir .' workspace_dir: 'workspace/dbt_init_challenge' access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From 1ec2eb75a8c48d377a4221bb5d8969b809c08863 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 17:48:07 +0000 Subject: [PATCH 16/42] remove dbt installation --- .github/workflows/examples-test.yml | 90 ++++++++++++++++------------- Dockerfile | 6 -- action.yml | 3 - entrypoint.sh | 8 --- 4 files changed, 51 insertions(+), 56 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 2be2ac1..5002aa2 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -4,28 +4,22 @@ on: pull_request: jobs: - # dbt_init_challenge_job: + # tpch_redshift: # runs-on: ubuntu-latest - # name: Run sdf push on a DBT + Snowflake workspace + # name: Run sdf compile on a Redshift workspace # steps: # - name: Checkout # uses: actions/checkout@v4 - # - name: sdf push step + # - name: sdf compile step # uses: ./ # Uses an action in the root directory # id: sdf # with: - # command: 'sdf push' - # workspace_dir: 'workspace/dbt_init_challenge' - # access_key: ${{ secrets.ACCESS_KEY }} - # secret_key: ${{ secrets.SECRET_KEY }} + # command: 'sdf compile --show all' + # workspace_dir: 'workspace/tpch_redshift' - # is_dbt: 'true' - # snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - # snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} - # snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} - # snowflake_role: 'dbt_test_role' - # snowflake_warehouse: 'dbt_dev_wh' - # dbt_target: 'dev' + # aws_region: 'us-west-2' + # aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # # Use the output from the `sdf` step # - name: Display the sdf output @@ -34,23 +28,40 @@ jobs: # echo '```' >>$GITHUB_STEP_SUMMARY # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY # echo '```' >>$GITHUB_STEP_SUMMARY - - # tpch_redshift: + + # dbt_init_challenge_v1 - sdf relies on dbt commands run in the same job + # dbt_init_challenge_v1: # runs-on: ubuntu-latest - # name: Run sdf compile on a Redshift workspace + # name: Run sdf push on a DBT + Snowflake workspace # steps: # - name: Checkout # uses: actions/checkout@v4 - # - name: sdf compile step + + # - name: Run DBT commands + # uses: mwhitaker/dbt-action@master + # env: + # DBT_TARGET: dev + # SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + # SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} + # with: + # dbt_command: "dbt compile" + # dbt_project_folder: "workspace/dbt_init_challenge" + + # - name: sdf push step # uses: ./ # Uses an action in the root directory # id: sdf # with: - # command: 'sdf compile --show all' - # workspace_dir: 'workspace/tpch_redshift' + # command: 'sdf compile' + # workspace_dir: 'workspace/dbt_init_challenge' + # access_key: ${{ secrets.ACCESS_KEY }} + # secret_key: ${{ secrets.SECRET_KEY }} - # aws_region: 'us-west-2' - # aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # is_dbt: 'true' + # snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + # snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} + # snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} + # snowflake_role: 'dbt_test_role' + # snowflake_warehouse: 'dbt_dev_wh' # # Use the output from the `sdf` step # - name: Display the sdf output @@ -60,31 +71,33 @@ jobs: # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY # echo '```' >>$GITHUB_STEP_SUMMARY - dbt_init_challenge: + # dbt_init_challenge_v2: rus dbt commands in a container job + dbt_init_challenge_v2: + container: + image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest runs-on: ubuntu-latest - name: Run sdf push on a DBT + Snowflake workspace + name: Run dbt commands in a job steps: - name: Checkout uses: actions/checkout@v4 + - name: Run DBT commands - uses: mwhitaker/dbt-action@master - env: + env: DBT_TARGET: dev SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} - with: - dbt_command: "dbt compile" - dbt_project_folder: "workspace/dbt_init_challenge" - - # debug step - - name: List files in the workspace - run: ls -la workspace/dbt_init_challenge/target - + run: | + cd workspace/dbt_init_challenge + dbt deps + dbt compile + - name: List target files + run: | + ls -l workspace/dbt_init_challenge/target + - name: sdf push step uses: ./ # Uses an action in the root directory - id: sdf with: - command: 'sdf compile --profiles-dir .' + command: 'sdf compile' workspace_dir: 'workspace/dbt_init_challenge' access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} @@ -95,8 +108,7 @@ jobs: snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} snowflake_role: 'dbt_test_role' snowflake_warehouse: 'dbt_dev_wh' - dbt_target: 'dev' - + # Use the output from the `sdf` step - name: Display the sdf output run: | diff --git a/Dockerfile b/Dockerfile index 2c8d7c2..71160a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,12 +10,6 @@ RUN apt-get update && apt-get install -y \ # Install sdf RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} -# Install dbt-snowflake plugin using pip -RUN python3.12 -m venv .venv && . .venv/bin/activate \ - && python3 -m pip install dbt-snowflake==1.7.2 \ - && python3 -m pip install --upgrade dbt-core==1.7.9 \ - && python3 -m pip install protobuf==4.25.3 - # Copy your code file from your action repository to the filesystem path `/` of the container COPY entrypoint.sh /entrypoint.sh diff --git a/action.yml b/action.yml index 5f558ef..744252a 100644 --- a/action.yml +++ b/action.yml @@ -20,9 +20,6 @@ inputs: description: "Whether the workspace is dbt based or not" required: false default: "" - dbt_target: - description: "The dbt target" - required: false # required if snowflake table provider is used snowflake_account_id: diff --git a/entrypoint.sh b/entrypoint.sh index 296c7b1..a1c5b0d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,14 +35,6 @@ fi if [[ -n $input_is_dbt ]]; then echo "::group::Setting up dbt" - # echo "running dbt deps" - # dbt deps - # check_exit_status $? "" - - # echo "running dbt compile" - # dbt compile - # check_exit_status $? "" - echo "running dbt compile done" sdf dbt refresh echo "::endgroup::" From 0baa092c2f3a03af4b08bb552a7d17d488be50a2 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 17:59:28 +0000 Subject: [PATCH 17/42] add volume --- .github/workflows/examples-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 5002aa2..8cd96f4 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -75,6 +75,8 @@ jobs: dbt_init_challenge_v2: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest + volumes: + - ${{ github.workspace }}:/workspace/dbt_init_challenge runs-on: ubuntu-latest name: Run dbt commands in a job steps: @@ -93,9 +95,9 @@ jobs: - name: List target files run: | ls -l workspace/dbt_init_challenge/target - - name: sdf push step uses: ./ # Uses an action in the root directory + id: sdf with: command: 'sdf compile' workspace_dir: 'workspace/dbt_init_challenge' From c0bef6267bfe7613daf003e2be15c63b2f8cce32 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 19:09:56 +0000 Subject: [PATCH 18/42] use mount volumes --- .github/workflows/examples-test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 8cd96f4..0387015 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -76,7 +76,7 @@ jobs: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest volumes: - - ${{ github.workspace }}:/workspace/dbt_init_challenge + - dbt-volume:${{ github.workspace }}/dbt_init_challenge/target runs-on: ubuntu-latest name: Run dbt commands in a job steps: @@ -94,13 +94,14 @@ jobs: dbt compile - name: List target files run: | - ls -l workspace/dbt_init_challenge/target + echo "path - ${{ github.workspace }}/dbt_init_challenge/target" + ls -l ${{ github.workspace }}/dbt_init_challenge/target - name: sdf push step uses: ./ # Uses an action in the root directory id: sdf with: command: 'sdf compile' - workspace_dir: 'workspace/dbt_init_challenge' + workspace_dir: ${{ github.workspace }}/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From cd457287da0ca3c2e54765e8274db8bcbd5e8b5d Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 19:16:00 +0000 Subject: [PATCH 19/42] try fix --- .github/workflows/examples-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 0387015..b7e649c 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -76,7 +76,7 @@ jobs: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest volumes: - - dbt-volume:${{ github.workspace }}/dbt_init_challenge/target + - ${{ github.workspace }}:workspace/dbt_init_challenge runs-on: ubuntu-latest name: Run dbt commands in a job steps: @@ -89,7 +89,7 @@ jobs: SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} run: | - cd workspace/dbt_init_challenge + cd ${{ github.workspace }}/dbt_init_challenge dbt deps dbt compile - name: List target files @@ -101,7 +101,7 @@ jobs: id: sdf with: command: 'sdf compile' - workspace_dir: ${{ github.workspace }}/dbt_init_challenge + workspace_dir: workspace/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From 9daf94261dce7f62a5218f7ff8d23f77a6c88eca Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 19:19:34 +0000 Subject: [PATCH 20/42] use absolute path --- .github/workflows/examples-test.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index b7e649c..bec338b 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -76,7 +76,7 @@ jobs: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest volumes: - - ${{ github.workspace }}:workspace/dbt_init_challenge + - ${{ github.workspace }}:/workspace/dbt_init_challenge runs-on: ubuntu-latest name: Run dbt commands in a job steps: @@ -89,19 +89,18 @@ jobs: SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} run: | - cd ${{ github.workspace }}/dbt_init_challenge + cd /workspace/dbt_init_challenge dbt deps dbt compile - name: List target files run: | - echo "path - ${{ github.workspace }}/dbt_init_challenge/target" - ls -l ${{ github.workspace }}/dbt_init_challenge/target + ls -l /workspace/dbt_init_challenge - name: sdf push step uses: ./ # Uses an action in the root directory id: sdf with: command: 'sdf compile' - workspace_dir: workspace/dbt_init_challenge + workspace_dir: /workspace/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From 5bef1e25a5527f4d53711a4b6951b78b7c986af0 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 19:23:37 +0000 Subject: [PATCH 21/42] add bind mount --- .github/workflows/examples-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index bec338b..4f29b99 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -75,6 +75,7 @@ jobs: dbt_init_challenge_v2: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest + options: --mount type=bind,source=${{ github.workspace }},target=/workspace volumes: - ${{ github.workspace }}:/workspace/dbt_init_challenge runs-on: ubuntu-latest From 248c4cb245b2ac6a00781ecf03204a8fcac211af Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 19:48:10 +0000 Subject: [PATCH 22/42] uses bind mount --- .github/workflows/examples-test.yml | 2 -- entrypoint.sh | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 4f29b99..48d0ff1 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -76,8 +76,6 @@ jobs: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest options: --mount type=bind,source=${{ github.workspace }},target=/workspace - volumes: - - ${{ github.workspace }}:/workspace/dbt_init_challenge runs-on: ubuntu-latest name: Run dbt commands in a job steps: diff --git a/entrypoint.sh b/entrypoint.sh index a1c5b0d..24a37e8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,5 @@ #!/bin/bash -l -source /.venv/bin/activate - echo "workspace dir set as: \"${WORKSPACE_DIR}\"" cd ${WORKSPACE_DIR} From 30cf5d152a65aa181ec59a3875397cbb52c1d407 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 19:56:37 +0000 Subject: [PATCH 23/42] fix --- .github/workflows/examples-test.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 48d0ff1..09dc29c 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -75,7 +75,9 @@ jobs: dbt_init_challenge_v2: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest - options: --mount type=bind,source=${{ github.workspace }},target=/workspace + volumes: + - ${{ github.workspace }}:/repo + runs-on: ubuntu-latest name: Run dbt commands in a job steps: @@ -88,18 +90,18 @@ jobs: SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} run: | - cd /workspace/dbt_init_challenge + cd /repo/workspace/dbt_init_challenge dbt deps dbt compile - name: List target files run: | - ls -l /workspace/dbt_init_challenge + ls -l /repo/workspace/dbt_init_challenge - name: sdf push step uses: ./ # Uses an action in the root directory id: sdf with: command: 'sdf compile' - workspace_dir: /workspace/dbt_init_challenge + workspace_dir: ${{ github.workspace }}/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From 35934e23a9d7e2cd470c98c1a9f15691024623dd Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:12:20 +0000 Subject: [PATCH 24/42] path dir --- .github/workflows/examples-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 09dc29c..f6ebda2 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -101,7 +101,7 @@ jobs: id: sdf with: command: 'sdf compile' - workspace_dir: ${{ github.workspace }}/dbt_init_challenge + workspace_dir: ${{ github.workspace }}/workspace/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From 8495f3ac1a19a039b6cb2d95273ca7f71e960437 Mon Sep 17 00:00:00 2001 From: "Xuliang (Harry) Sun" <32334165+xuliangs@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:12:44 -0700 Subject: [PATCH 25/42] Update examples-test.yml --- .github/workflows/examples-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 09dc29c..f6ebda2 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -101,7 +101,7 @@ jobs: id: sdf with: command: 'sdf compile' - workspace_dir: ${{ github.workspace }}/dbt_init_challenge + workspace_dir: ${{ github.workspace }}/workspace/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From 393c3a49b5d67c651145b497be7fe64ea8ceeec0 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:16:07 +0000 Subject: [PATCH 26/42] add ls --- .github/workflows/examples-test.yml | 2 +- entrypoint.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index f6ebda2..4fe8068 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -95,7 +95,7 @@ jobs: dbt compile - name: List target files run: | - ls -l /repo/workspace/dbt_init_challenge + ls -l /repo/workspace/dbt_init_challenge/target - name: sdf push step uses: ./ # Uses an action in the root directory id: sdf diff --git a/entrypoint.sh b/entrypoint.sh index 24a37e8..e4e4bb2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/bash -l echo "workspace dir set as: \"${WORKSPACE_DIR}\"" +ls -l . cd ${WORKSPACE_DIR} input_command=$1 From 3026399145be190724d25dce3d08fcef4c9c4eb8 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:18:58 +0000 Subject: [PATCH 27/42] move --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e4e4bb2..40211c8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,8 @@ #!/bin/bash -l echo "workspace dir set as: \"${WORKSPACE_DIR}\"" -ls -l . cd ${WORKSPACE_DIR} +ls -l . input_command=$1 input_is_dbt=$2 From d553b4a8200f661c81cbc57bf5b3b8b575247d82 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:22:37 +0000 Subject: [PATCH 28/42] add more logs --- entrypoint.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 40211c8..61b3f29 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,9 @@ echo "workspace dir set as: \"${WORKSPACE_DIR}\"" cd ${WORKSPACE_DIR} -ls -l . + +echo "ls -l ./target" +ls -l ./target input_command=$1 input_is_dbt=$2 From da0a2c78fac9ff4d16e24228aa8f0c44f41ec8dd Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:34:17 +0000 Subject: [PATCH 29/42] pass in target --- .github/workflows/examples-test.yml | 4 ++-- action.yml | 4 ++++ entrypoint.sh | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 4fe8068..0a5b87a 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -93,9 +93,9 @@ jobs: cd /repo/workspace/dbt_init_challenge dbt deps dbt compile - - name: List target files + - name: List target sdf models run: | - ls -l /repo/workspace/dbt_init_challenge/target + ls -l ./target/compiled/sdf/models - name: sdf push step uses: ./ # Uses an action in the root directory id: sdf diff --git a/action.yml b/action.yml index 744252a..46f2649 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,10 @@ inputs: description: "Whether the workspace is dbt based or not" required: false default: "" + dbt_target: + description: "The dbt target" + required: false + default: "dev" # required if snowflake table provider is used snowflake_account_id: diff --git a/entrypoint.sh b/entrypoint.sh index 61b3f29..0605a98 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,7 +4,7 @@ echo "workspace dir set as: \"${WORKSPACE_DIR}\"" cd ${WORKSPACE_DIR} echo "ls -l ./target" -ls -l ./target +ls -l ./target/compiled/sdf/models input_command=$1 input_is_dbt=$2 From e5f4c5d924a267f3d079e79f1ee09850f55ed66d Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:36:49 +0000 Subject: [PATCH 30/42] fix --- .github/workflows/examples-test.yml | 4 ++-- entrypoint.sh | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml index 0a5b87a..4fe8068 100644 --- a/.github/workflows/examples-test.yml +++ b/.github/workflows/examples-test.yml @@ -93,9 +93,9 @@ jobs: cd /repo/workspace/dbt_init_challenge dbt deps dbt compile - - name: List target sdf models + - name: List target files run: | - ls -l ./target/compiled/sdf/models + ls -l /repo/workspace/dbt_init_challenge/target - name: sdf push step uses: ./ # Uses an action in the root directory id: sdf diff --git a/entrypoint.sh b/entrypoint.sh index 0605a98..576877f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,7 +4,7 @@ echo "workspace dir set as: \"${WORKSPACE_DIR}\"" cd ${WORKSPACE_DIR} echo "ls -l ./target" -ls -l ./target/compiled/sdf/models +ls -l ./target/ input_command=$1 input_is_dbt=$2 @@ -38,6 +38,9 @@ if [[ -n $input_is_dbt ]]; then echo "::group::Setting up dbt" echo "running dbt compile done" sdf dbt refresh + + echo "ls -l ./target" + ls -l ./target/ echo "::endgroup::" check_exit_status $? "" fi From a99ea77ca6b3e424a7b162038d3b8e3b9a654118 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:48:16 +0000 Subject: [PATCH 31/42] clean up --- .github/workflows/examples-test.yml | 122 ---------------------------- .github/workflows/examples.yml | 119 +++++++++++++++++++++++++++ Dockerfile | 8 +- Dockerfile.base | 6 -- Dockerfile.normal | 17 ---- README.md | 2 +- entrypoint.sh | 7 -- 7 files changed, 126 insertions(+), 155 deletions(-) delete mode 100644 .github/workflows/examples-test.yml create mode 100644 .github/workflows/examples.yml delete mode 100644 Dockerfile.normal diff --git a/.github/workflows/examples-test.yml b/.github/workflows/examples-test.yml deleted file mode 100644 index 4fe8068..0000000 --- a/.github/workflows/examples-test.yml +++ /dev/null @@ -1,122 +0,0 @@ -name: Test sdf-action - -on: - pull_request: - -jobs: - # tpch_redshift: - # runs-on: ubuntu-latest - # name: Run sdf compile on a Redshift workspace - # steps: - # - name: Checkout - # uses: actions/checkout@v4 - # - name: sdf compile step - # uses: ./ # Uses an action in the root directory - # id: sdf - # with: - # command: 'sdf compile --show all' - # workspace_dir: 'workspace/tpch_redshift' - - # aws_region: 'us-west-2' - # aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - - # # Use the output from the `sdf` step - # - name: Display the sdf output - # run: | - # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY - # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY - - # dbt_init_challenge_v1 - sdf relies on dbt commands run in the same job - # dbt_init_challenge_v1: - # runs-on: ubuntu-latest - # name: Run sdf push on a DBT + Snowflake workspace - # steps: - # - name: Checkout - # uses: actions/checkout@v4 - - # - name: Run DBT commands - # uses: mwhitaker/dbt-action@master - # env: - # DBT_TARGET: dev - # SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - # SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} - # with: - # dbt_command: "dbt compile" - # dbt_project_folder: "workspace/dbt_init_challenge" - - # - name: sdf push step - # uses: ./ # Uses an action in the root directory - # id: sdf - # with: - # command: 'sdf compile' - # workspace_dir: 'workspace/dbt_init_challenge' - # access_key: ${{ secrets.ACCESS_KEY }} - # secret_key: ${{ secrets.SECRET_KEY }} - - # is_dbt: 'true' - # snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - # snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} - # snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} - # snowflake_role: 'dbt_test_role' - # snowflake_warehouse: 'dbt_dev_wh' - - # # Use the output from the `sdf` step - # - name: Display the sdf output - # run: | - # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY - # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY - - # dbt_init_challenge_v2: rus dbt commands in a container job - dbt_init_challenge_v2: - container: - image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest - volumes: - - ${{ github.workspace }}:/repo - - runs-on: ubuntu-latest - name: Run dbt commands in a job - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Run DBT commands - env: - DBT_TARGET: dev - SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} - run: | - cd /repo/workspace/dbt_init_challenge - dbt deps - dbt compile - - name: List target files - run: | - ls -l /repo/workspace/dbt_init_challenge/target - - name: sdf push step - uses: ./ # Uses an action in the root directory - id: sdf - with: - command: 'sdf compile' - workspace_dir: ${{ github.workspace }}/workspace/dbt_init_challenge - access_key: ${{ secrets.ACCESS_KEY }} - secret_key: ${{ secrets.SECRET_KEY }} - - is_dbt: 'true' - snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} - snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} - snowflake_role: 'dbt_test_role' - snowflake_warehouse: 'dbt_dev_wh' - - # Use the output from the `sdf` step - - name: Display the sdf output - run: | - echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY - echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY - diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml new file mode 100644 index 0000000..358c1ac --- /dev/null +++ b/.github/workflows/examples.yml @@ -0,0 +1,119 @@ +name: Test sdf-action + +on: + pull_request: + +jobs: + tpch_redshift: + runs-on: ubuntu-latest + name: Run sdf compile on a Redshift workspace + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: sdf compile step + uses: ./ # Uses an action in the root directory + id: sdf + with: + command: 'sdf compile --show all' + workspace_dir: 'workspace/tpch_redshift' + + aws_region: 'us-west-2' + aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + + # Use the output from the `sdf` step + - name: Display the sdf output + run: | + echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + + # dbt_init_challenge_v1 - uses dbt-action + dbt_init_challenge_v1: + runs-on: ubuntu-latest + name: Run sdf push on a DBT + Snowflake workspace + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run DBT commands + uses: mwhitaker/dbt-action@master + env: + DBT_TARGET: dev + SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} + with: + dbt_command: "dbt compile" + dbt_project_folder: "workspace/dbt_init_challenge" + + - name: sdf push step + uses: ./ # Uses an action in the root directory + id: sdf + with: + command: 'sdf compile' + workspace_dir: 'workspace/dbt_init_challenge' + access_key: ${{ secrets.ACCESS_KEY }} + secret_key: ${{ secrets.SECRET_KEY }} + + is_dbt: 'true' + snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} + snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} + snowflake_role: 'dbt_test_role' + snowflake_warehouse: 'dbt_dev_wh' + + # Use the output from the `sdf` step + - name: Display the sdf output + run: | + echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + + # dbt_init_challenge_v2: rus dbt commands in a container job + dbt_init_challenge_v2: + container: + image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest + volumes: + - ${{ github.workspace }}:/repo + + runs-on: ubuntu-latest + name: Run dbt commands in a job + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run DBT commands + env: + DBT_TARGET: dev + SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} + run: | + cd /repo/workspace/dbt_init_challenge + dbt deps + dbt compile + - name: sdf push step + uses: ./ # Uses an action in the root directory + id: sdf + with: + command: 'sdf compile' + workspace_dir: ${{ github.workspace }}/workspace/dbt_init_challenge + access_key: ${{ secrets.ACCESS_KEY }} + secret_key: ${{ secrets.SECRET_KEY }} + + is_dbt: 'true' + snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} + snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} + snowflake_role: 'dbt_test_role' + snowflake_warehouse: 'dbt_dev_wh' + + # Use the output from the `sdf` step + - name: Display the sdf output + run: | + echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + diff --git a/Dockerfile b/Dockerfile index 71160a0..022b1ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,13 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* # Install sdf -RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} +RUN if [ "$(uname -m)" = "aarch64" ]; then \ + curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} --target aarch64-unknown-linux-gnu ; \ + else \ + curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} ; \ + fi +# replace above with a pre-built image? -# Copy your code file from your action repository to the filesystem path `/` of the container COPY entrypoint.sh /entrypoint.sh # Set the code file as the entry point diff --git a/Dockerfile.base b/Dockerfile.base index fcc8c47..c1334da 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -13,9 +13,3 @@ RUN if [ "$(uname -m)" = "aarch64" ]; then \ else \ curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} ; \ fi - -# Install dbt-snowflake plugin using pip -RUN python3.12 -m venv .venv && . .venv/bin/activate \ - && python3 -m pip install dbt-snowflake==1.7.2 \ - && python3 -m pip install --upgrade dbt-core==1.7.9 \ - && python3 -m pip install protobuf==4.25.3 \ No newline at end of file diff --git a/Dockerfile.normal b/Dockerfile.normal deleted file mode 100644 index 062b8f6..0000000 --- a/Dockerfile.normal +++ /dev/null @@ -1,17 +0,0 @@ -FROM python:3.12.2-bookworm -ARG SDF_VERSION=0.1.192 - -# Install dependencies -RUN apt-get update && apt-get install -y \ - yq \ - curl \ - && rm -rf /var/lib/apt/lists/* - -# Install sdf -RUN curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} - -# Copy your code file from your action repository to the filesystem path `/` of the container -COPY entrypoint.sh /entrypoint.sh - -# Set the code file as the entry point -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index db27688..cb17bd2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Github Action to run `sdf` CLI in workflows. ## Usage -Check out this [example workflow](./.github/workflows/examples-test.yml) to see how to use this action. +Check out this [example workflow](./.github/workflows/examples.yml) to see how to use this action. ## Parameters diff --git a/entrypoint.sh b/entrypoint.sh index 576877f..dc1f643 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,9 +3,6 @@ echo "workspace dir set as: \"${WORKSPACE_DIR}\"" cd ${WORKSPACE_DIR} -echo "ls -l ./target" -ls -l ./target/ - input_command=$1 input_is_dbt=$2 @@ -36,11 +33,7 @@ fi if [[ -n $input_is_dbt ]]; then echo "::group::Setting up dbt" - echo "running dbt compile done" sdf dbt refresh - - echo "ls -l ./target" - ls -l ./target/ echo "::endgroup::" check_exit_status $? "" fi From 73a2c1d4a4c3e78c540f8d638b3a94ea987c80b1 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:53:25 +0000 Subject: [PATCH 32/42] remove pre-built image --- .github/workflows/docker-image.yml | 44 ------------------------------ .github/workflows/examples.yml | 10 +++---- Dockerfile.base | 15 ---------- 3 files changed, 5 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/docker-image.yml delete mode 100644 Dockerfile.base diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index ad7b394..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Base sdf-action Docker Image (DBT based) - -on: - pull_request: - paths: - - 'Dockerfile.base' - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2.5.0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2.2.0 - - - name: Build Docker image - if: github.event_name == 'pull_request' - run: | - docker buildx build \ - --file Dockerfile.base \ - --platform linux/amd64,linux/arm64 . - - - name: Release Docker image - if: github.event_name == 'workflow_dispatch' - run: | - docker buildx build \ - --file Dockerfile.base \ - --platform linux/amd64,linux/arm64 \ - --push \ - --tag ghcr.io/${{ github.repository }}-dbt-base:latest \ - --tag ghcr.io/${{ github.repository }}-dbt-base:${{ github.run_number }} . \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 358c1ac..fd63528 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -6,7 +6,7 @@ on: jobs: tpch_redshift: runs-on: ubuntu-latest - name: Run sdf compile on a Redshift workspace + name: Redshift workspace steps: - name: Checkout uses: actions/checkout@v4 @@ -32,7 +32,7 @@ jobs: # dbt_init_challenge_v1 - uses dbt-action dbt_init_challenge_v1: runs-on: ubuntu-latest - name: Run sdf push on a DBT + Snowflake workspace + name: Snowflake + dbt workspace - run dbt commands using dbt-action steps: - name: Checkout uses: actions/checkout@v4 @@ -47,7 +47,7 @@ jobs: dbt_command: "dbt compile" dbt_project_folder: "workspace/dbt_init_challenge" - - name: sdf push step + - name: sdf compile step uses: ./ # Uses an action in the root directory id: sdf with: @@ -79,7 +79,7 @@ jobs: - ${{ github.workspace }}:/repo runs-on: ubuntu-latest - name: Run dbt commands in a job + name: Snowflake + dbt workspace - run dbt commands in a container job steps: - name: Checkout uses: actions/checkout@v4 @@ -97,7 +97,7 @@ jobs: uses: ./ # Uses an action in the root directory id: sdf with: - command: 'sdf compile' + command: 'sdf push' workspace_dir: ${{ github.workspace }}/workspace/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} diff --git a/Dockerfile.base b/Dockerfile.base deleted file mode 100644 index c1334da..0000000 --- a/Dockerfile.base +++ /dev/null @@ -1,15 +0,0 @@ -FROM python:3.12.2-bookworm -ARG SDF_VERSION=0.1.192 - -# Install dependencies -RUN apt-get update && apt-get install -y \ - yq \ - curl \ - && rm -rf /var/lib/apt/lists/* - -# Install sdf -RUN if [ "$(uname -m)" = "aarch64" ]; then \ - curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} --target aarch64-unknown-linux-gnu ; \ - else \ - curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} ; \ - fi From f9aa82a27f5d294a377a313a494c40e72e7ff29b Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 20:57:58 +0000 Subject: [PATCH 33/42] try without volume --- .github/workflows/examples.yml | 124 ++++++++++++++++----------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index fd63528..df700a9 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -4,79 +4,79 @@ on: pull_request: jobs: - tpch_redshift: - runs-on: ubuntu-latest - name: Redshift workspace - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: sdf compile step - uses: ./ # Uses an action in the root directory - id: sdf - with: - command: 'sdf compile --show all' - workspace_dir: 'workspace/tpch_redshift' + # tpch_redshift: + # runs-on: ubuntu-latest + # name: Redshift workspace + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + # - name: sdf compile step + # uses: ./ # Uses an action in the root directory + # id: sdf + # with: + # command: 'sdf compile --show all' + # workspace_dir: 'workspace/tpch_redshift' - aws_region: 'us-west-2' - aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws_region: 'us-west-2' + # aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # Use the output from the `sdf` step - - name: Display the sdf output - run: | - echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY - echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY + # # Use the output from the `sdf` step + # - name: Display the sdf output + # run: | + # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY + # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY - # dbt_init_challenge_v1 - uses dbt-action - dbt_init_challenge_v1: - runs-on: ubuntu-latest - name: Snowflake + dbt workspace - run dbt commands using dbt-action - steps: - - name: Checkout - uses: actions/checkout@v4 + # # dbt_init_challenge_v1 - uses dbt-action + # dbt_init_challenge_v1: + # runs-on: ubuntu-latest + # name: Snowflake + dbt workspace - run dbt commands using dbt-action + # steps: + # - name: Checkout + # uses: actions/checkout@v4 - - name: Run DBT commands - uses: mwhitaker/dbt-action@master - env: - DBT_TARGET: dev - SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} - with: - dbt_command: "dbt compile" - dbt_project_folder: "workspace/dbt_init_challenge" + # - name: Run DBT commands + # uses: mwhitaker/dbt-action@master + # env: + # DBT_TARGET: dev + # SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + # SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} + # with: + # dbt_command: "dbt compile" + # dbt_project_folder: "workspace/dbt_init_challenge" - - name: sdf compile step - uses: ./ # Uses an action in the root directory - id: sdf - with: - command: 'sdf compile' - workspace_dir: 'workspace/dbt_init_challenge' - access_key: ${{ secrets.ACCESS_KEY }} - secret_key: ${{ secrets.SECRET_KEY }} + # - name: sdf compile step + # uses: ./ # Uses an action in the root directory + # id: sdf + # with: + # command: 'sdf compile' + # workspace_dir: 'workspace/dbt_init_challenge' + # access_key: ${{ secrets.ACCESS_KEY }} + # secret_key: ${{ secrets.SECRET_KEY }} - is_dbt: 'true' - snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} - snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} - snowflake_role: 'dbt_test_role' - snowflake_warehouse: 'dbt_dev_wh' + # is_dbt: 'true' + # snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + # snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} + # snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} + # snowflake_role: 'dbt_test_role' + # snowflake_warehouse: 'dbt_dev_wh' - # Use the output from the `sdf` step - - name: Display the sdf output - run: | - echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY - echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - echo '```' >>$GITHUB_STEP_SUMMARY + # # Use the output from the `sdf` step + # - name: Display the sdf output + # run: | + # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY + # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + # echo '```' >>$GITHUB_STEP_SUMMARY # dbt_init_challenge_v2: rus dbt commands in a container job dbt_init_challenge_v2: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest - volumes: - - ${{ github.workspace }}:/repo + # volumes: + # - ${{ github.workspace }}:/repo runs-on: ubuntu-latest name: Snowflake + dbt workspace - run dbt commands in a container job @@ -90,7 +90,7 @@ jobs: SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} run: | - cd /repo/workspace/dbt_init_challenge + cd ${{ github.workspace }}/workspace/dbt_init_challenge dbt deps dbt compile - name: sdf push step From c2f22ffcdea4924af80ba12a63434ef2e15e8f81 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 21:00:58 +0000 Subject: [PATCH 34/42] use workspace --- .github/workflows/examples.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index df700a9..d419533 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -47,7 +47,7 @@ jobs: # dbt_command: "dbt compile" # dbt_project_folder: "workspace/dbt_init_challenge" - # - name: sdf compile step + # - name: sdf push step # uses: ./ # Uses an action in the root directory # id: sdf # with: @@ -75,8 +75,8 @@ jobs: dbt_init_challenge_v2: container: image: ghcr.io/dbt-labs/dbt-snowflake:1.5.latest - # volumes: - # - ${{ github.workspace }}:/repo + volumes: + - ${{ github.workspace }}:/repo runs-on: ubuntu-latest name: Snowflake + dbt workspace - run dbt commands in a container job @@ -90,7 +90,7 @@ jobs: SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} run: | - cd ${{ github.workspace }}/workspace/dbt_init_challenge + cd /repo/workspace/dbt_init_challenge dbt deps dbt compile - name: sdf push step @@ -98,7 +98,7 @@ jobs: id: sdf with: command: 'sdf push' - workspace_dir: ${{ github.workspace }}/workspace/dbt_init_challenge + workspace_dir: workspace/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From 251782a804c58b3ba6c57bfcd0264c7b6de99f01 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 21:05:11 +0000 Subject: [PATCH 35/42] simplify --- .github/workflows/examples.yml | 119 +++++++++++++++++---------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index d419533..1967d8f 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -4,72 +4,72 @@ on: pull_request: jobs: - # tpch_redshift: - # runs-on: ubuntu-latest - # name: Redshift workspace - # steps: - # - name: Checkout - # uses: actions/checkout@v4 - # - name: sdf compile step - # uses: ./ # Uses an action in the root directory - # id: sdf - # with: - # command: 'sdf compile --show all' - # workspace_dir: 'workspace/tpch_redshift' + tpch_redshift: + runs-on: ubuntu-latest + name: Redshift workspace + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: sdf compile step + uses: ./ # Uses an action in the root directory + id: sdf + with: + command: 'sdf compile --show all' + workspace_dir: 'workspace/tpch_redshift' - # aws_region: 'us-west-2' - # aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} - # aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws_region: 'us-west-2' + aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - # # Use the output from the `sdf` step - # - name: Display the sdf output - # run: | - # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY - # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY + # Use the output from the `sdf` step + - name: Display the sdf output + run: | + echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY - # # dbt_init_challenge_v1 - uses dbt-action - # dbt_init_challenge_v1: - # runs-on: ubuntu-latest - # name: Snowflake + dbt workspace - run dbt commands using dbt-action - # steps: - # - name: Checkout - # uses: actions/checkout@v4 + # dbt_init_challenge_v1 - uses dbt-action + dbt_init_challenge_v1: + runs-on: ubuntu-latest + name: Snowflake + dbt workspace - run dbt commands using dbt-action + steps: + - name: Checkout + uses: actions/checkout@v4 - # - name: Run DBT commands - # uses: mwhitaker/dbt-action@master - # env: - # DBT_TARGET: dev - # SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - # SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} - # with: - # dbt_command: "dbt compile" - # dbt_project_folder: "workspace/dbt_init_challenge" + - name: Run DBT commands + uses: mwhitaker/dbt-action@master + env: + DBT_TARGET: dev + SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} + with: + dbt_command: "dbt compile" + dbt_project_folder: "workspace/dbt_init_challenge" - # - name: sdf push step - # uses: ./ # Uses an action in the root directory - # id: sdf - # with: - # command: 'sdf compile' - # workspace_dir: 'workspace/dbt_init_challenge' - # access_key: ${{ secrets.ACCESS_KEY }} - # secret_key: ${{ secrets.SECRET_KEY }} + - name: sdf push step + uses: ./ # Uses an action in the root directory + id: sdf + with: + command: 'sdf compile' + workspace_dir: 'workspace/dbt_init_challenge' + access_key: ${{ secrets.ACCESS_KEY }} + secret_key: ${{ secrets.SECRET_KEY }} - # is_dbt: 'true' - # snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} - # snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} - # snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} - # snowflake_role: 'dbt_test_role' - # snowflake_warehouse: 'dbt_dev_wh' + is_dbt: 'true' + snowflake_account_id: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} + snowflake_username: ${{ secrets.SNOWFLAKE_USERNAME }} + snowflake_password: ${{ secrets.SNOWFLAKE_PASSWORD }} + snowflake_role: 'dbt_test_role' + snowflake_warehouse: 'dbt_dev_wh' - # # Use the output from the `sdf` step - # - name: Display the sdf output - # run: | - # echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY - # echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY - # echo '```' >>$GITHUB_STEP_SUMMARY + # Use the output from the `sdf` step + - name: Display the sdf output + run: | + echo "### SDF Run Logs 🪵" >> $GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY + echo "${{ steps.sdf.outputs.log }}" >>$GITHUB_STEP_SUMMARY + echo '```' >>$GITHUB_STEP_SUMMARY # dbt_init_challenge_v2: rus dbt commands in a container job dbt_init_challenge_v2: @@ -98,6 +98,7 @@ jobs: id: sdf with: command: 'sdf push' + # relative path to ${{ github.workspace }} which is automatically mounted by GitHub Actions workspace_dir: workspace/dbt_init_challenge access_key: ${{ secrets.ACCESS_KEY }} secret_key: ${{ secrets.SECRET_KEY }} From eafaad800184fe6f1bb98c5dbaaeea30e783931a Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 21:26:04 +0000 Subject: [PATCH 36/42] Use latest release --- Dockerfile | 2 +- .../dbt_init_challenge/workspace.sdf.yml | 20 ++++++++--------- workspace/tpch_redshift/workspace.sdf.yml | 22 ++++++++++--------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 022b1ab..c17dce5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.12.2-bookworm -ARG SDF_VERSION=0.1.192 +ARG SDF_VERSION=0.2.0 # Install dependencies RUN apt-get update && apt-get install -y \ diff --git a/workspace/dbt_init_challenge/workspace.sdf.yml b/workspace/dbt_init_challenge/workspace.sdf.yml index d950d3a..f27151b 100644 --- a/workspace/dbt_init_challenge/workspace.sdf.yml +++ b/workspace/dbt_init_challenge/workspace.sdf.yml @@ -1,15 +1,15 @@ workspace: - edition: "1.1" + edition: "1.2" name: dbt_hol includes: - path: target/compiled/sdf/models index: catalog-schema-table-name - dialect: snowflake - default-catalog: dbt_hol_dev - default-schema: public - default-profile: dbg ---- -provider: - sources: - - census.public.* - type: snowflake + providers: + - namespaces: + - target: census.public.* + type: snowflake + defaults: + environment: dbg + dialect: snowflake + catalog: dbt_hol_dev + schema: public diff --git a/workspace/tpch_redshift/workspace.sdf.yml b/workspace/tpch_redshift/workspace.sdf.yml index 74fb3dd..b039d2e 100644 --- a/workspace/tpch_redshift/workspace.sdf.yml +++ b/workspace/tpch_redshift/workspace.sdf.yml @@ -1,14 +1,16 @@ workspace: - edition: "1.1" + edition: "1.2" name: "tpch" - default-catalog: sample_data_dev - default-schema: tpch - compute: "local" + defaults: + environment: dbg + dialect: redshift + catalog: sample_data_dev + schema: tpch + compute: "local" includes: - path: queries/ ---- -provider: - type: redshift - cluster-identifier: sdf-cli-tests - sources: - - sample_data_dev + providers: + - type: redshift + cluster-identifier: sdf-cli-tests + namespaces: + - target: sample_data_dev.*.* From f3425cb2378a3bc6fa1883b100de71ee9a320f84 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 21:29:09 +0000 Subject: [PATCH 37/42] use 0.2.1 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c17dce5..86d533b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.12.2-bookworm -ARG SDF_VERSION=0.2.0 +ARG SDF_VERSION=0.2.1 # Install dependencies RUN apt-get update && apt-get install -y \ From df3fccf96e310afa40c0ddd48b8927d4307a0345 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 21:38:39 +0000 Subject: [PATCH 38/42] remove auth login snowflake --- .github/workflows/examples.yml | 4 ++-- Dockerfile | 1 - entrypoint.sh | 10 ---------- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 1967d8f..3c80047 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -47,7 +47,7 @@ jobs: dbt_command: "dbt compile" dbt_project_folder: "workspace/dbt_init_challenge" - - name: sdf push step + - name: Run sdf compile uses: ./ # Uses an action in the root directory id: sdf with: @@ -93,7 +93,7 @@ jobs: cd /repo/workspace/dbt_init_challenge dbt deps dbt compile - - name: sdf push step + - name: Run sdf push uses: ./ # Uses an action in the root directory id: sdf with: diff --git a/Dockerfile b/Dockerfile index 86d533b..978cced 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,6 @@ ARG SDF_VERSION=0.2.1 # Install dependencies RUN apt-get update && apt-get install -y \ - yq \ curl \ && rm -rf /var/lib/apt/lists/* diff --git a/entrypoint.sh b/entrypoint.sh index dc1f643..54ac08f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -38,16 +38,6 @@ if [[ -n $input_is_dbt ]]; then check_exit_status $? "" fi -# run sdf auth login snwoflake if necessary -snowflake_provider=$(yq .provider.type workspace.sdf.yml | grep snowflake | tail -1) -if [[ -n $snowflake_provider ]]; then - echo "snowflake provider used: running 'sdf auth login'" - sdf auth login snowflake \ - --account-id "${SNOWFLAKE_ACCOUNT_ID}" --username "${SNOWFLAKE_USERNAME}" --password "${SNOWFLAKE_PASSWORD}" \ - --role "${SNOWFLAKE_ROLE}" --warehouse "${SNOWFLAKE_WAREHOUSE}" - check_exit_status $? "" -fi - # run and save outputs echo "running command: $input_command" log=$($input_command 2>&1) From eba61bc2e8c23c3640f2c5e81d39d2bc1b7dfdf2 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Thu, 11 Apr 2024 22:34:47 +0000 Subject: [PATCH 39/42] nit fixes --- README.md | 22 +++++++++++----------- action.yml | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index cb17bd2..cc9de5f 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,16 @@ Check out this [example workflow](./.github/workflows/examples.yml) to see how t | Parameter | Description | Required | Default | | --- | --- | --- | --- | | `command` | The `sdf` CLI command to run. | No | `sdf compile` -| `workspace_dir` | The directory of the workspace" | No | "." | +| `workspace_dir` | The directory of the workspace | No | `"."` | | `access_key` | access key created from the [console](https://console.sdf.com/catalog/settings/general) to be used in `sdf push` | No | | | `secret_key` | secret key created from the [console](https://console.sdf.com/catalog/settings/general) to be used in `sdf push` | No | | -| `is_dbt` | Set to a non-empty string if the workspace is dbt based | No | false | "" -| `dbt_target` | The dbt target | No | "." | -| `snowflake_account_id` | The snowflake account | No | "" -| `snowflake_username` | The snowflake username | No | "" -| `snowflake_password` | The snowflake password | No | "" -| `snowflake_role` | The snowflake role | No | "" -| `snowflake_warehouse` | The snowflake warehouse | No | "" -| `aws_region` | The aws region | No | "" -| `aws_access_key_id` | The aws access key id created from an IAM user | No | "" -| `aws_secret_access_key` | The aws secret created from an IAM user | No | "" +| `is_dbt` | Set to a non-empty string if the workspace is dbt based | No | `""` | | +| `dbt_target` | The dbt target | No | `"dev"` | +| `snowflake_account_id` | The snowflake account | No | | +| `snowflake_username` | The snowflake username | No | | +| `snowflake_password` | The snowflake password | No | | +| `snowflake_role` | The snowflake role | No | | +| `snowflake_warehouse` | The snowflake warehouse | No | | +| `aws_region` | The aws region | No | | +| `aws_access_key_id` | The aws access key id created from an IAM user | No | | +| `aws_secret_access_key` | The aws secret created from an IAM user | No | | diff --git a/action.yml b/action.yml index 46f2649..1fe4b37 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ # action.yml -name: "dbt action" +name: "sdf action" description: "Run sdf cli commands" inputs: command: From 8b9a3161f3949bf154fa98c70c5ca9bc481cc6ac Mon Sep 17 00:00:00 2001 From: xuliangs Date: Wed, 24 Apr 2024 19:06:40 +0000 Subject: [PATCH 40/42] Update to use the latest cli --- .github/workflows/examples.yml | 4 ++++ CONTRIBUTING.md | 0 Dockerfile | 2 +- LICENSE | 13 +++++++++++++ workspace/dbt_init_challenge/workspace.sdf.yml | 4 ++-- 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 3c80047..29650dd 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -40,6 +40,8 @@ jobs: - name: Run DBT commands uses: mwhitaker/dbt-action@master env: + CATALOG: dbt_hol_dev + SCHEMA: public DBT_TARGET: dev SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} @@ -86,6 +88,8 @@ jobs: - name: Run DBT commands env: + CATALOG: dbt_hol_dev + SCHEMA: public DBT_TARGET: dev SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile index 978cced..f18f419 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.12.2-bookworm -ARG SDF_VERSION=0.2.1 +ARG SDF_VERSION=0.2.12 # Install dependencies RUN apt-get update && apt-get install -y \ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1dca4aa --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright [2024] [SDF Labs] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/workspace/dbt_init_challenge/workspace.sdf.yml b/workspace/dbt_init_challenge/workspace.sdf.yml index f27151b..b93b4f9 100644 --- a/workspace/dbt_init_challenge/workspace.sdf.yml +++ b/workspace/dbt_init_challenge/workspace.sdf.yml @@ -11,5 +11,5 @@ workspace: defaults: environment: dbg dialect: snowflake - catalog: dbt_hol_dev - schema: public + catalog: "${{ env_var('CATALOG') }}" + schema: "${{ env_var('SCHEMA') }}" From f91268f1ac89b19636f11ac2ad68a69c656ec378 Mon Sep 17 00:00:00 2001 From: xuliangs Date: Wed, 24 Apr 2024 19:12:07 +0000 Subject: [PATCH 41/42] fix env var --- .github/workflows/examples.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 29650dd..52f4563 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -40,8 +40,6 @@ jobs: - name: Run DBT commands uses: mwhitaker/dbt-action@master env: - CATALOG: dbt_hol_dev - SCHEMA: public DBT_TARGET: dev SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} @@ -52,6 +50,9 @@ jobs: - name: Run sdf compile uses: ./ # Uses an action in the root directory id: sdf + env: + CATALOG: dbt_hol_dev + SCHEMA: public with: command: 'sdf compile' workspace_dir: 'workspace/dbt_init_challenge' @@ -88,8 +89,6 @@ jobs: - name: Run DBT commands env: - CATALOG: dbt_hol_dev - SCHEMA: public DBT_TARGET: dev SNOWFLAKE_ACCOUNT_ID: ${{ secrets.SNOWFLAKE_ACCOUNT_ID }} SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} @@ -100,6 +99,9 @@ jobs: - name: Run sdf push uses: ./ # Uses an action in the root directory id: sdf + env: + CATALOG: dbt_hol_dev + SCHEMA: public with: command: 'sdf push' # relative path to ${{ github.workspace }} which is automatically mounted by GitHub Actions From d316bf3d00d93dae5b4fd2784b0758ca431f8dac Mon Sep 17 00:00:00 2001 From: xuliangs Date: Fri, 26 Apr 2024 22:18:30 +0000 Subject: [PATCH 42/42] Move cli installation to entrypoint.sh --- CONTRIBUTING.md | 2 ++ Dockerfile | 10 +--------- README.md | 1 + action.yml | 5 +++++ entrypoint.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e69de29..db0478f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -0,0 +1,2 @@ +# Contributing to sdf-action + diff --git a/Dockerfile b/Dockerfile index f18f419..12aa49d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,11 @@ FROM python:3.12.2-bookworm -ARG SDF_VERSION=0.2.12 # Install dependencies RUN apt-get update && apt-get install -y \ + jq \ curl \ && rm -rf /var/lib/apt/lists/* -# Install sdf -RUN if [ "$(uname -m)" = "aarch64" ]; then \ - curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} --target aarch64-unknown-linux-gnu ; \ - else \ - curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${SDF_VERSION} ; \ - fi -# replace above with a pre-built image? - COPY entrypoint.sh /entrypoint.sh # Set the code file as the entry point diff --git a/README.md b/README.md index cc9de5f..4a4c053 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Check out this [example workflow](./.github/workflows/examples.yml) to see how t | Parameter | Description | Required | Default | | --- | --- | --- | --- | +| `sdf_version` | SDF CLI version | No | `"0.2.10"` | `command` | The `sdf` CLI command to run. | No | `sdf compile` | `workspace_dir` | The directory of the workspace | No | `"."` | | `access_key` | access key created from the [console](https://console.sdf.com/catalog/settings/general) to be used in `sdf push` | No | | diff --git a/action.yml b/action.yml index 1fe4b37..2b3e906 100644 --- a/action.yml +++ b/action.yml @@ -2,6 +2,10 @@ name: "sdf action" description: "Run sdf cli commands" inputs: + sdf_version: + description: "The version of the sdf cli" + default: "0.2.10" + required: false command: description: "The sdf command to run" default: "sdf compile" @@ -64,6 +68,7 @@ runs: args: - ${{ inputs.command }} - ${{ inputs.is_dbt }} + - ${{ inputs.sdf_version }} env: WORKSPACE_DIR: ${{ inputs.workspace_dir }} ACCESS_KEY: ${{ inputs.access_key }} diff --git a/entrypoint.sh b/entrypoint.sh index 54ac08f..ea2bc3e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,51 @@ #!/bin/bash -l -echo "workspace dir set as: \"${WORKSPACE_DIR}\"" -cd ${WORKSPACE_DIR} - input_command=$1 input_is_dbt=$2 +sdf_version=$3 + +is_less_semvar() { + # split the version strings into arrays + IFS='.' read -ra version1 <<<"$1" + IFS='.' read -ra version2 <<<"$2" + + i=0 + while true; do + v1="${version1[$i]:-0}" + v2="${version2[$i]:-0}" + + # compare numerically + if ((v1 < v2)); then + echo 1 + return + elif ((v1 > v2)); then + echo 0 + return + fi + ((i++)) + + # run out of components to compare + if [[ -z "${version1[$i]}" && -z "${version2[$i]}" ]]; then + echo 0 + return + fi + done +} + +min_version=$(curl https://api.sdf.com/api/v2/public.minVersion | jq -r '.result.data.json') +if [[ $(is_less_semvar $sdf_version $min_version) -eq 1 ]]; then + echo "The input SDF CLI version is lower than the minimum required version: $min_version" + exit 1 +fi + +if [ "$(uname -m)" = "aarch64" ]; then + curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${sdf_version} --target aarch64-unknown-linux-gnu +else + curl -LSfs https://cdn.sdf.com/releases/download/install.sh | bash -s -- --version ${sdf_version} +fi + +echo "workspace dir set as: \"${WORKSPACE_DIR}\"" +cd ${WORKSPACE_DIR} check_exit_status() { exit_status=$1