Skip to content

Commit

Permalink
Merge pull request #1 from sdf-labs/elias/addErrorChecking
Browse files Browse the repository at this point in the history
Added proper exit code error checking to entrypoint.sh script
  • Loading branch information
eliasdefaria authored Mar 14, 2024
2 parents ed09fa2 + d5264ab commit 8fd9ede
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: On Pull Request Run Compile

on:
push:
branches:
- 'main'
- main
pull_request:

jobs:
dbt_init_challenge_job:
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ ARG SDF_VERSION=0.1.170

# Install dependencies
RUN apt-get update && apt-get install -y \
yq \
curl \
&& rm -rf /var/lib/apt/lists/*
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
&& 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
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile.normal
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.12.2-bookworm
ARG SDF_VERSION=0.1.170

# 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"]
35 changes: 28 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,29 @@ cd ${WORKSPACE_DIR}
input_command=$1
input_is_dbt=$2

check_exit_status() {
exit_status=$1
command_log=$2
echo "checking exit status: $exit_status"
if [ $exit_status -ne 0 ]; then
# Log the error message to GitHub output
{
echo 'log<<EOF'
echo "Command failed with status $exit_status"
echo "$command_log"
echo EOF
} >>$GITHUB_OUTPUT

echo "result=failed" >>$GITHUB_OUTPUT
exit $exit_status
fi
}

# Check if the variable starts with 'sdf push'
if [[ $input_command == "sdf push"* ]]; then
echo "'sdf push' runs 'sdf auth login' using headless credentials"
sdf auth login --access-key "${ACCESS_KEY}" --secret-key "${SECRET_KEY}"
check_exit_status $? ""
fi

if [[ -n $input_is_dbt ]]; then
Expand All @@ -20,13 +39,16 @@ 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::"
check_exit_status $? ""
fi

# run sdf auth login snwoflake if necessary
Expand All @@ -36,20 +58,19 @@ if [[ -n $snowflake_provider ]]; then
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)
echo "log: $log"
exit_status=$?
echo "$log"
check_exit_status $exit_status "$log"

{
echo 'log<<EOF'
echo "$log"
echo EOF
} >>$GITHUB_OUTPUT
if [ $? -eq 0 ]; then
echo "result=passed" >>$GITHUB_OUTPUT
else
echo "result=failed" >>$GITHUB_OUTPUT
exit 1
fi
echo "result=passed" >>$GITHUB_OUTPUT

0 comments on commit 8fd9ede

Please sign in to comment.