astronomer / deploy-action

Custom Github Actions
Other
20 stars 21 forks source link

Action fails if run on a tag push event #82

Closed dbsanfte closed 2 weeks ago

dbsanfte commented 1 month ago

The Github Action fails if run on a tag push event, even with checkout disabled:

Branch pushed to: refs/tags/v1.0.0
From https://github.com/***/my-project
 * tag               v1.0.0     -> FETCH_HEAD
fatal: bad object 0000000000000000000000000000000000000000

The error seems to be in the script here, because github.event.before on a tag resolves to 00000....:

https://github.com/astronomer/deploy-action/blob/1c0c1fe1cba39d33a4c30235dca3aa3ea1fa2a7e/action.yaml#L346

cd ./
  branch=$(echo "${GITHUB_REF#refs/heads/}")
  echo "Branch pushed to: $branch"
  git fetch origin $branch
  files=$(git diff --name-only 0000000000000000000000000000000000000000 26a5079efe4455002e65374e71fbc24cf5bf3633)
  echo "files changed: $files"

We are using the release-please plugin to push our DAGs to Prod on the back of a tag push. I will work around this for now with custom shell I guess. Would be good if you can fix.

dbsanfte commented 1 month ago

I patched the v0.6 version of the action with this on a local fork:

    - name: Get Deployment Type
      run: |
        cd ${{ inputs.root-folder }}
        branch=$(echo "${GITHUB_REF#refs/heads/}")
        echo "Our ref is: $branch"

        # DS: handle no `github.event.before` on tags push event:
        if [[ "$branch" == refs/tags/* ]]
        then
          dags_only=0
        else
          git fetch origin $branch
          files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
          echo "files changed: $files"
          dags_only=1

          for file in $files; do
            if [[ $file != *"dags/"* ]]; then
              echo $file is not a DAG, triggering a full image build
              dags_only=0
              break
            fi
          done
        fi

        if [[ ${{steps.dag-deploy-enabled.outputs.DAG_DEPLOY_ENABLED}} == false ]]; then
          dags_only=0
        fi

        if [[ ${{steps.deployment-preview.outputs.SKIP_DEPLOY}} == true ]]; then
          # skip all deploy steps
          dags_only=2
        fi

        if [[ ${{ inputs.deploy-image }} == true ]]; then
          # make sure image and DAGs deploys because deploy-image is true
          dags_only=0
        fi

        echo "DAGS_ONLY=$dags_only" >> $GITHUB_OUTPUT
      shell: bash
      id: deployment-type

In case anyone else needs a quick fix.

neel-astro commented 1 week ago

The fix for this has been included in v0.8.0 release, thanks for raising the issue and helping with identifying gaps in the project ❤ 🙇