Skip to content

Commit

Permalink
simplify cli version check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-astro committed Sep 18, 2024
1 parent cae54c7 commit 4ecbd17
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,21 @@ runs:
run: |
echo ::group::Install Astro CLI
# skip Astro CLI installation if already installed
CLI_VERSION=${{ inputs.cli-version }}
# if Astro CLI is pre-installed, fetch it's version
if command -v astro &> /dev/null; then
echo "Astro CLI is already installed"
exit 0
# "astro version" commands returns the CLI version, its output is of the form: "Astro CLI Version: 1.29.0"
CLI_VERSION=$(astro version | awk '{print $4}')
fi
CLI_VERSION=${{ inputs.cli-version }}
# Check if the Astro CLI version is less than 1.28.1 for dbt-deploy
if [[ "${{ inputs.action }}" == "dbt-deploy" && $CLI_VERSION != "" ]]; then
if [[ "${{ inputs.deploy-type }}" == "dbt" && $CLI_VERSION != "" ]]; then
REQUIRED_VERSION="1.28.1"
CURRENT_VERSION=$(astro --version | awk '{print $3}')
if [[ $CURRENT_VERSION =~ ([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
CURRENT_MAJOR=${BASH_REMATCH[1]}
CURRENT_MINOR=${BASH_REMATCH[2]}
CURRENT_PATCH=${BASH_REMATCH[3]}
REQUIRED_MAJOR=$(echo $REQUIRED_VERSION | awk -F. '{print $1}')
REQUIRED_MINOR=$(echo $REQUIRED_VERSION | awk -F. '{print $2}')
REQUIRED_PATCH=$(echo $REQUIRED_VERSION | awk -F. '{print $3}')
if [[ $CURRENT_MAJOR -lt 1 || ($CURRENT_MAJOR -eq 1 && $CURRENT_MINOR -lt 28) || ($CURRENT_MAJOR -eq 1 && $CURRENT_MINOR -eq 28 && $CURRENT_PATCH -lt 1) ]]; then
echo "DBT Deploy requires Astro CLI version $REQUIRED_VERSION or higher"
exit 1
Expand All @@ -147,6 +143,12 @@ runs:
fi
fi
# skip Astro CLI installation if already installed
if command -v astro &> /dev/null; then
echo "Astro CLI is already installed"
exit 0
fi
# check if CLI_VERSION does not starts with "v", then add "v" to it
if [[ $CLI_VERSION != "" && $CLI_VERSION != v* ]]; then
CLI_VERSION=v$CLI_VERSION
Expand Down Expand Up @@ -403,12 +405,16 @@ runs:
fi
done
# Note: the order of these following checks is important to ensure that we skip/trigger deploy correctly in following cases:
# 1. When there is no change in the input root folder we should skip deploy, but not when it's deployment preview create action
# 2. When user has passed a custom image then we would need to deploy the image
# 3. When the action is deployment preview delete, then we should skip any form of deploy
if [[ $skip_deploy == 1 ]]; then
# skip all deploy steps
dags_only=2
fi
# check if user has passed a custom image, then we would need to deploy the image
# check if user has passed a custom image or the action has created a new deployment preview, then we would need to deploy the image
if [[ ${{ inputs.image-name }} != "no-custom-image" || ${{ steps.dag-deploy-enabled.outputs.DAG_DEPLOY_ENABLED }} == false || ${{ steps.deployment-preview.outputs.IMAGE_DEPLOY_ONLY }} == true ]]; then
dags_only=0
fi
Expand Down

0 comments on commit 4ecbd17

Please sign in to comment.