Skip to content

Commit

Permalink
Handle case for branch rebase/force push (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-astro authored Feb 21, 2025
1 parent b46210f commit ef3b6be
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 40 deletions.
27 changes: 3 additions & 24 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@ name: E2E Tests for Astro Deploy Action

on:
push:
branches:
- main
workflow_dispatch:
inputs:
workspace_id:
description: "Workspace ID"
required: false
default: ""
org_id:
description: "Organization ID"
required: false
default: ""
astronomer_host:
description: "Astronomer Host"
required: false
default: ""
token:
description: "API Token"
required: false
default: ""

env:
ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}
Expand All @@ -30,6 +10,7 @@ jobs:
redact-inputs:
name: Redact Inputs
runs-on: ubuntu-latest
environment: e2e-test
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -79,9 +60,7 @@ jobs:
- name: Install dependencies
run: |
sudo add-apt-repository ppa:rmescandon/yq
sudo apt update
sudo apt install yq -y
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq
curl -sSL https://install.astronomer.io | sudo bash -s
astro context switch ${{ steps.get-astro-env-info.outputs.astronomer_host }}
Expand Down Expand Up @@ -814,7 +793,7 @@ jobs:
with:
is_wake_on_deploy: ${{ matrix.deployment_id == needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}
dag_tarball_version_before: ""
image_version_before: "12.5.0"
image_version_before: "12.7.1"
hibernation_spec_before: '{"schedules":[{"isEnabled":true,"hibernateAtCron":"0 * * * *","wakeAtCron":"1 * * * *"},{"isEnabled":true,"hibernateAtCron":"1 * * * *","wakeAtCron":"0 * * * *"}]}'
dag_tarball_version_after: ${{ steps.get-deployment-after-create-preview.outputs.desired_dag_tarball_version }}
image_version_after: ${{ steps.get-deployment-after-create-preview.outputs.desired_image_version }}
Expand Down
29 changes: 16 additions & 13 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ runs:
GITHUB_EVENT_BEFORE=${{ github.event.before }}
GITHUB_EVENT_AFTER=${{ github.event.after }}
if [[ "$GITHUB_EVENT_BEFORE" == "0000000000000000000000000000000000000000" || -z $GITHUB_EVENT_BEFORE && -z $GITHUB_EVENT_AFTER ]]; then
DBT_DEPLOY=true
files=()
DBT_DEPLOY=true
files=()
else
files=$(git diff --name-only $GITHUB_EVENT_BEFORE $GITHUB_EVENT_AFTER)
echo "files changed: $files"
Expand Down Expand Up @@ -365,23 +365,26 @@ runs:
cd ${{ inputs.root-folder }}
fi
branch=$(echo "${GITHUB_REF#refs/heads/}")
echo "Branch pushed to: $branch"
git fetch origin $branch
DAGS_ONLY_DEPLOY=false
SKIP_IMAGE_OR_DAGS_DEPLOY=true
SKIP_IMAGE_OR_DAGS_DEPLOY=false
files=()
# case when the triggered event is a manual workflow dispatch or a new branch or tag creation, we would need to deploy the image because we cannot determine that it does not need to be deployed
GITHUB_EVENT_BEFORE=${{ github.event.before }}
GITHUB_EVENT_AFTER=${{ github.event.after }}
# case when the triggered event is a manual workflow dispatch or a new branch or tag creation, we would need to deploy the image because we cannot determine that it does not need to be deployed
if [[ "$GITHUB_EVENT_BEFORE" == "0000000000000000000000000000000000000000" || -z $GITHUB_EVENT_BEFORE && -z $GITHUB_EVENT_AFTER ]]; then
DAGS_ONLY_DEPLOY=false
SKIP_IMAGE_OR_DAGS_DEPLOY=false
files=()
echo "Manual workflow dispatch or a new branch or tag creation, hence missing github event before and/or after commit hash"
else
files=$(git diff --name-only $GITHUB_EVENT_BEFORE $GITHUB_EVENT_AFTER)
echo "files changed: $files"
echo "event that triggered the workflow: $GITHUB_REF"
branch=$(echo "${GITHUB_REF#refs/heads/}")
git fetch origin $branch
if ! git cat-file -e "${{ github.event.before }}" 2>/dev/null; then
echo "Commit ${{ github.event.before }} does not exist, falling back to image deploy."
else
SKIP_IMAGE_OR_DAGS_DEPLOY=true
files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
echo "files changed: $files"
fi
fi
for file in $files; do
Expand Down
2 changes: 1 addition & 1 deletion e2e-setup/astro-project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM quay.io/astronomer/astro-runtime:12.5.0
FROM quay.io/astronomer/astro-runtime:12.7.1
2 changes: 1 addition & 1 deletion e2e-setup/deployment-templates/deployment-hibernate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ deployment:
configuration:
name: deploy-action-hibernate-e2e
description: ""
runtime_version: 12.5.0
runtime_version: 12.7.1
dag_deploy_enabled: true
ci_cd_enforcement: false
scheduler_size: SMALL
Expand Down
2 changes: 1 addition & 1 deletion e2e-setup/deployment-templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ deployment:
configuration:
name: deploy-action-non-dev-e2e
description: ""
runtime_version: 12.5.0
runtime_version: 12.7.1
dag_deploy_enabled: true
ci_cd_enforcement: false
scheduler_size: SMALL
Expand Down
2 changes: 2 additions & 0 deletions e2e-setup/mocks/dag-deploy-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if [[ "$1" == "diff" ]]; then
echo "e2e-setup/astro-project/dags/exampledag.py"
elif [[ "$1" == "fetch" ]]; then
echo "Handling git fetch, doing nothing"
elif [[ "$1" == "cat-file" ]]; then
echo "Handling git cat-file, doing nothing"
else
echo "Error: git mock script isn't configured to handle $1" >&2
exit 1
Expand Down
2 changes: 2 additions & 0 deletions e2e-setup/mocks/image-deploy-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if [[ "$1" == "diff" ]]; then
echo "e2e-setup/astro-project/Dockerfile"
elif [[ "$1" == "fetch" ]]; then
echo "Handling git fetch, doing nothing"
elif [[ "$1" == "cat-file" ]]; then
echo "Handling git cat-file, doing nothing"
else
echo "Error: git mock script isn't configured to handle $1" >&2
exit 1
Expand Down
2 changes: 2 additions & 0 deletions e2e-setup/mocks/no-deploy-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if [[ "$1" == "diff" ]]; then
echo "README.md"
elif [[ "$1" == "fetch" ]]; then
echo "Handling git fetch, doing nothing"
elif [[ "$1" == "cat-file" ]]; then
echo "Handling git cat-file, doing nothing"
else
echo "Error: git mock script isn't configured to handle $1" >&2
exit 1
Expand Down

0 comments on commit ef3b6be

Please sign in to comment.