Skip to content

Commit ef3b6be

Browse files
authored
Handle case for branch rebase/force push (#109)
1 parent b46210f commit ef3b6be

File tree

8 files changed

+28
-40
lines changed

8 files changed

+28
-40
lines changed

.github/workflows/tests.yaml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@ name: E2E Tests for Astro Deploy Action
22

33
on:
44
push:
5-
branches:
6-
- main
7-
workflow_dispatch:
8-
inputs:
9-
workspace_id:
10-
description: "Workspace ID"
11-
required: false
12-
default: ""
13-
org_id:
14-
description: "Organization ID"
15-
required: false
16-
default: ""
17-
astronomer_host:
18-
description: "Astronomer Host"
19-
required: false
20-
default: ""
21-
token:
22-
description: "API Token"
23-
required: false
24-
default: ""
255

266
env:
277
ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}
@@ -30,6 +10,7 @@ jobs:
3010
redact-inputs:
3111
name: Redact Inputs
3212
runs-on: ubuntu-latest
13+
environment: e2e-test
3314
steps:
3415
- name: Checkout code
3516
uses: actions/checkout@v4
@@ -79,9 +60,7 @@ jobs:
7960
- name: Install dependencies
8061
run: |
8162
82-
sudo add-apt-repository ppa:rmescandon/yq
83-
sudo apt update
84-
sudo apt install yq -y
63+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq
8564
8665
curl -sSL https://install.astronomer.io | sudo bash -s
8766
astro context switch ${{ steps.get-astro-env-info.outputs.astronomer_host }}
@@ -814,7 +793,7 @@ jobs:
814793
with:
815794
is_wake_on_deploy: ${{ matrix.deployment_id == needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}
816795
dag_tarball_version_before: ""
817-
image_version_before: "12.5.0"
796+
image_version_before: "12.7.1"
818797
hibernation_spec_before: '{"schedules":[{"isEnabled":true,"hibernateAtCron":"0 * * * *","wakeAtCron":"1 * * * *"},{"isEnabled":true,"hibernateAtCron":"1 * * * *","wakeAtCron":"0 * * * *"}]}'
819798
dag_tarball_version_after: ${{ steps.get-deployment-after-create-preview.outputs.desired_dag_tarball_version }}
820799
image_version_after: ${{ steps.get-deployment-after-create-preview.outputs.desired_image_version }}

action.yaml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ runs:
322322
GITHUB_EVENT_BEFORE=${{ github.event.before }}
323323
GITHUB_EVENT_AFTER=${{ github.event.after }}
324324
if [[ "$GITHUB_EVENT_BEFORE" == "0000000000000000000000000000000000000000" || -z $GITHUB_EVENT_BEFORE && -z $GITHUB_EVENT_AFTER ]]; then
325-
DBT_DEPLOY=true
326-
files=()
325+
DBT_DEPLOY=true
326+
files=()
327327
else
328328
files=$(git diff --name-only $GITHUB_EVENT_BEFORE $GITHUB_EVENT_AFTER)
329329
echo "files changed: $files"
@@ -365,23 +365,26 @@ runs:
365365
cd ${{ inputs.root-folder }}
366366
fi
367367
368-
branch=$(echo "${GITHUB_REF#refs/heads/}")
369-
echo "Branch pushed to: $branch"
370-
git fetch origin $branch
371-
372368
DAGS_ONLY_DEPLOY=false
373-
SKIP_IMAGE_OR_DAGS_DEPLOY=true
369+
SKIP_IMAGE_OR_DAGS_DEPLOY=false
370+
files=()
374371
375-
# 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
376372
GITHUB_EVENT_BEFORE=${{ github.event.before }}
377373
GITHUB_EVENT_AFTER=${{ github.event.after }}
374+
# 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
378375
if [[ "$GITHUB_EVENT_BEFORE" == "0000000000000000000000000000000000000000" || -z $GITHUB_EVENT_BEFORE && -z $GITHUB_EVENT_AFTER ]]; then
379-
DAGS_ONLY_DEPLOY=false
380-
SKIP_IMAGE_OR_DAGS_DEPLOY=false
381-
files=()
376+
echo "Manual workflow dispatch or a new branch or tag creation, hence missing github event before and/or after commit hash"
382377
else
383-
files=$(git diff --name-only $GITHUB_EVENT_BEFORE $GITHUB_EVENT_AFTER)
384-
echo "files changed: $files"
378+
echo "event that triggered the workflow: $GITHUB_REF"
379+
branch=$(echo "${GITHUB_REF#refs/heads/}")
380+
git fetch origin $branch
381+
if ! git cat-file -e "${{ github.event.before }}" 2>/dev/null; then
382+
echo "Commit ${{ github.event.before }} does not exist, falling back to image deploy."
383+
else
384+
SKIP_IMAGE_OR_DAGS_DEPLOY=true
385+
files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
386+
echo "files changed: $files"
387+
fi
385388
fi
386389
387390
for file in $files; do

e2e-setup/astro-project/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM quay.io/astronomer/astro-runtime:12.5.0
1+
FROM quay.io/astronomer/astro-runtime:12.7.1

e2e-setup/deployment-templates/deployment-hibernate.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ deployment:
22
configuration:
33
name: deploy-action-hibernate-e2e
44
description: ""
5-
runtime_version: 12.5.0
5+
runtime_version: 12.7.1
66
dag_deploy_enabled: true
77
ci_cd_enforcement: false
88
scheduler_size: SMALL

e2e-setup/deployment-templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ deployment:
22
configuration:
33
name: deploy-action-non-dev-e2e
44
description: ""
5-
runtime_version: 12.5.0
5+
runtime_version: 12.7.1
66
dag_deploy_enabled: true
77
ci_cd_enforcement: false
88
scheduler_size: SMALL

e2e-setup/mocks/dag-deploy-git.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ if [[ "$1" == "diff" ]]; then
77
echo "e2e-setup/astro-project/dags/exampledag.py"
88
elif [[ "$1" == "fetch" ]]; then
99
echo "Handling git fetch, doing nothing"
10+
elif [[ "$1" == "cat-file" ]]; then
11+
echo "Handling git cat-file, doing nothing"
1012
else
1113
echo "Error: git mock script isn't configured to handle $1" >&2
1214
exit 1

e2e-setup/mocks/image-deploy-git.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ if [[ "$1" == "diff" ]]; then
77
echo "e2e-setup/astro-project/Dockerfile"
88
elif [[ "$1" == "fetch" ]]; then
99
echo "Handling git fetch, doing nothing"
10+
elif [[ "$1" == "cat-file" ]]; then
11+
echo "Handling git cat-file, doing nothing"
1012
else
1113
echo "Error: git mock script isn't configured to handle $1" >&2
1214
exit 1

e2e-setup/mocks/no-deploy-git.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ if [[ "$1" == "diff" ]]; then
77
echo "README.md"
88
elif [[ "$1" == "fetch" ]]; then
99
echo "Handling git fetch, doing nothing"
10+
elif [[ "$1" == "cat-file" ]]; then
11+
echo "Handling git cat-file, doing nothing"
1012
else
1113
echo "Error: git mock script isn't configured to handle $1" >&2
1214
exit 1

0 commit comments

Comments
 (0)