helm / chart-releaser-action

A GitHub Action to turn a GitHub project into a self-hosted Helm chart repo, using helm/chart-releaser CLI tool
https://github.com/helm/chart-releaser
Apache License 2.0
559 stars 206 forks source link

cr.sh: line 109: latest_tag: unbound variable #171

Open na-jakobs opened 11 months ago

na-jakobs commented 11 months ago

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

Steps to recreate:

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 commented 11 months ago

Steps to create an empty branch:

git checkout --orphan gh-pages
rm -rf .
git commit -m "gh-pages initial commit" --allow-empty
git push
IGx89 commented 11 months ago

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 commented 11 months ago

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.

korenyoni commented 10 months ago

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)

IGx89 commented 10 months ago

@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.

korenyoni commented 9 months ago

@IGx89

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

hegerdes commented 8 months ago

Also facing this. Is there a workaround?

IGx89 commented 6 months ago

@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.

bhperry commented 1 week ago

seems like everything works fine, it just fails right at the end. Would be nice to get this fixed though.