Skip to content

Commit

Permalink
Add e2e tests for deploy action (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-astro authored Sep 18, 2024
1 parent 310c0a3 commit 1248bd5
Show file tree
Hide file tree
Showing 21 changed files with 1,226 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/e2e/get_astro_env_info/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Get Astro Environment Info
description: Get information about the Astro environment
inputs:
input_workspace_id:
description: The workspace ID specified via user input
required: true
secret_workspace_id:
description: The workspace ID via pre configured secret
required: true
input_organization_id:
description: The organization ID specified via user input
required: true
secret_organization_id:
description: The organization ID via pre configured secret
required: true
input_astro_api_token:
description: The Astronomer API token specified via user input
required: true
secret_astro_api_token:
description: The Astronomer API token via pre configured secret
required: true
input_astronomer_host:
description: The Astronomer host specified via user input
required: true
secret_astronomer_host:
description: The Astronomer host via pre configured secret
required: true

outputs:
organization_id:
value: ${{ steps.get-info.outputs.ORGANIZATION_ID }}
workspace_id:
value: ${{ steps.get-info.outputs.WORKSPACE_ID }}
astronomer_host:
value: ${{ steps.get-info.outputs.ASTRONOMER_HOST }}
astro_api_token:
value: ${{ steps.get-info.outputs.ASTRO_API_TOKEN }}

runs:
using: "composite"
steps:
- name: Get info from inputs or secrets
shell: bash
id: get-info
run: |
if [ "${{ inputs.input_workspace_id }}" != "" ]; then
echo "Using provided workspace_id"
echo "WORKSPACE_ID=${{ inputs.input_workspace_id }}" >> $GITHUB_OUTPUT
else
echo "WORKSPACE_ID=${{ inputs.secret_workspace_id }}" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.input_organization_id }}" != "" ]; then
echo "Using provided org_id"
echo "ORGANIZATION_ID=${{ inputs.input_organization_id }}" >> $GITHUB_OUTPUT
else
echo "ORGANIZATION_ID=${{ inputs.secret_organization_id }}" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.input_astronomer_host }}" != "" ]; then
echo "Using provided astronomer_host"
echo "ASTRONOMER_HOST=${{ inputs.input_astronomer_host }}" >> $GITHUB_OUTPUT
else
echo "ASTRONOMER_HOST=${{ inputs.secret_astronomer_host }}" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.input_astro_api_token }}" != "" ]; then
echo "Using provided token"
echo "ASTRO_API_TOKEN=${{ inputs.input_astro_api_token }}" >> $GITHUB_OUTPUT
echo "ASTRO_API_TOKEN=${{ inputs.input_astro_api_token }}" >> $GITHUB_ENV
else
echo "ASTRO_API_TOKEN=${{ inputs.secret_astro_api_token }}" >> $GITHUB_OUTPUT
echo "ASTRO_API_TOKEN=${{ inputs.secret_astro_api_token }}" >> $GITHUB_ENV
fi
43 changes: 43 additions & 0 deletions .github/workflows/e2e/get_deployment_info/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Get Deployment Info
description: Get deployment info from Astronomer API
inputs:
deployment_id:
description: The deployment ID
required: true
organization_id:
description: The organization ID
required: true
astro_api_token:
description: The Astronomer API token
required: true
astronomer_host:
description: The Astronomer host
required: true
expected_status_code:
description: The expected status code
default: 200

outputs:
desired_dag_tarball_version:
description: The desired DAG tarball version
value: ${{ steps.get-deployment-info.outputs.desired_dag_tarball_version }}
desired_image_version:
description: The image version
value: ${{ steps.get-deployment-info.outputs.desired_image_version }}

runs:
using: "composite"
steps:
- name: Get Deployment Info
id: get-deployment-info
shell: bash
run: |
STATUS_CODE=$(curl -s -w "%{http_code}" -o response.json -H "Authorization: Bearer ${{ inputs.astro_api_token }}" "https://api.${{ inputs.astronomer_host }}/v1alpha1/organizations/${{ inputs.organization_id }}/deployments/${{ inputs.deployment_id }}")
if [[ $STATUS_CODE -ne ${{ inputs.expected_status_code }} ]]; then
echo "Failed to get expected status code from GET Deployment API. Status code: $STATUS_CODE"
exit 1
fi
desired_dag_tarball_version=$(cat response.json | jq -r '.desiredDagTarballVersion')
desired_image_version=$(cat response.json | jq -r '.desiredImageVersion')
echo "desired_dag_tarball_version=$desired_dag_tarball_version" >> $GITHUB_OUTPUT
echo "desired_image_version=$desired_image_version" >> $GITHUB_OUTPUT
45 changes: 45 additions & 0 deletions .github/workflows/e2e/validate_deployment/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Validate Deployment Deploy Versions
description: Validate deployment info from Astronomer API

inputs:
is_dag_only_deploy:
description: Whether the deploy operation was DAG-only
default: false
dag_tarball_version_before:
description: The desired DAG tarball version before the test
required: true
image_version_before:
description: The image version before the test
required: true
dag_tarball_version_after:
description: The desired DAG tarball version after the test
required: true
image_version_after:
description: The image version after the test
required: true

runs:
using: "composite"
steps:
- name: Validate Deployment
id: validate-deployment
shell: bash
run: |
# If it's dag only deploy then validate that only desiredDagTarballVersion was updated
if [[ "${{ inputs.is_dag_only_deploy }}" == "true" ]]; then
if [[ "${{ inputs.dag_tarball_version_before }}" != "${{ inputs.dag_tarball_version_after }}" && "${{ inputs.image_version_before }}" == "${{ inputs.image_version_after }}" ]]; then
echo "Deploy Action validation succeeded: desiredDagTarballVersion only updated"
exit 0
fi
echo "Deploy Action validation failed"
exit 1
fi
# If it's not dag only deploy then validate that both desiredDagTarballVersion and imageVersion were updated
if [[ "${{ inputs.dag_tarball_version_before }}" != "${{ inputs.dag_tarball_version_after }}" && "${{ inputs.image_version_before }}" != "${{ inputs.image_version_after }}" ]]; then
echo "Deploy Action validation succeeded: desiredDagTarballVersion and imageVersion updated"
exit 0
fi
echo "Deploy Action validation failed: neither desiredDagTarballVersion or imageVersion were updated after the test"
exit 1
Loading

0 comments on commit 1248bd5

Please sign in to comment.