chart-releaser-action icon indicating copy to clipboard operation
chart-releaser-action copied to clipboard

cr.sh: line 109: latest_tag: unbound variable

Open na-jakobs opened this issue 9 months ago • 8 comments

cr.sh will fail if there are no tags in the repository.

Steps to recreate:

  • Create an empty branch (git checkout --orphan gh-pages) and push to repo
Pushing to branch "gh-pages"
warning: not sending a push certificate since the receiving end does not support --signed push
To https://github.com/<org>/<repo>
   298a8e3..218a1fc  HEAD -> gh-pages
/__w/_actions/helm/chart-releaser-action/main/cr.sh: line 109: latest_tag: unbound variable
Error: Process completed with exit code 1.

I am using the latest version of the action (main branch).

na-jakobs avatar Oct 26 '23 16:10 na-jakobs

Steps to create an empty branch:

git checkout --orphan gh-pages
rm -rf .
git commit -m "gh-pages initial commit" --allow-empty
git push

na-jakobs avatar Oct 26 '23 16:10 na-jakobs

Just ran into this too when upgrading from v1.5 to v1.6. The code only sets the latest_tag variable when skip_packaging is false, but it still attempts to read the variable when skip_packaging is true:

  if [[ -z "$skip_packaging" ]]; then
    echo 'Looking up latest tag...'
    local latest_tag
    latest_tag=$(lookup_latest_tag)
...
  else
    install_chart_releaser
    rm -rf .cr-index
    mkdir -p .cr-index
    release_charts
    update_index
  fi

  echo "chart_version=${latest_tag}" >chart_version.txt

Looks like the bug was introduced in #130 by @n-oden. Hopefully a simple fix?

IGx89 avatar Nov 06 '23 20:11 IGx89

This error might have two causes, no tags in repo and skip_packaging set to false -- I'm still getting it in the latter scenario even with tags present.

IGx89 avatar Nov 06 '23 20:11 IGx89

Looks like the bug was introduced in #130 by @n-oden. Hopefully a simple fix?

On a quick glance, #96 is more likely to be the source of this issue than #130 (which doesn't change lookup_latest_tag's logic at all)

korenyoni avatar Dec 07 '23 16:12 korenyoni

@korenyoni thanks for taking a look, but lookup_latest_tag isn't even called in my scenario's code path (skip_packaging = false).

Take a look at this code added in #130 (abridged to make the bug more obvious):

  if [[ -z "$skip_packaging" ]]; then
    echo 'Looking up latest tag...'
    local latest_tag
    latest_tag=$(lookup_latest_tag)
...
  fi

  echo "chart_version=${latest_tag}" >chart_version.txt

See how latest_tag is declared a local variable and then is accessed outside of its scope. If this was C# the compiler would throw an error :p.

IGx89 avatar Dec 07 '23 21:12 IGx89

@IGx89

Cool yeah — I only took a quick look. In this case #130 definitely looks like the source of the regression.

korenyoni avatar Dec 11 '23 14:12 korenyoni

Also facing this. Is there a workaround?

hegerdes avatar Jan 12 '24 15:01 hegerdes

@davidkarlsen I see you seem to be a maintainer of this repo. Sorry to bother you, but would you be able to take a look at this? Quite a few of us have had to downgrade back to v1.5 due to this bug. I'd love to use some of the new functionality from 1.6 but currently can't. If you have time to review/merge PRs but not create them, let us know and maybe we can contribute a fix for this regression. I see 9 open PRs so I'm hesitant to spend time on that myself without knowing someone would look at it.

IGx89 avatar Mar 27 '24 14:03 IGx89