shini4i / helm-charts-updater

A tool that will update helm charts in a given repository
MIT License
6 stars 0 forks source link

ci throws git.exc.InvalidGitRepositoryError #19

Open yalattas opened 9 months ago

yalattas commented 9 months ago

I am experiencing this error even though my setup is almost the same with your documentation

trace

Traceback (most recent call last):
  File "/usr/local/bin/helm-charts-updater", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/helm_charts_updater/main.py", line 8, in main
    repo = GitRepository()
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/helm_charts_updater/git.py", line 23, in __init__
    self.local_repo = Repo(self.repo_path)
                      ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/git/repo/base.py", line 276, in __init__
    raise InvalidGitRepositoryError(epath)
git.exc.InvalidGitRepositoryError: /github/workspace/charts

usage

- name: Update helm chart
        uses: shini4i/helm-charts-updater@v1
        with:
          github_token: ${{ secrets.GIT_ACTION_TOKEN }}
          gh_user: CompanyExample
          gh_repo: helm-charts
          chart_name: ${{ matrix.changed-chart }} # this will return chart name for example `nginx/` which is a folder inside `charts` folder
          charts_path: charts  # -> lives at the root of the repo
          app_version: ${{ github.ref_name }}
          commit_author: CompanyCI
          commit_email: Company.ci@users.noreply.github.com
          generate_docs: true
          update_readme: true

repo structure

|
|- charts/
|-------- nginx/
|---------------- Chart.yaml/
|-------- app1/
|---------------- Chart.yaml/
| README.md

matrix usage

Before executing your action, I have a job that will compare changes and return changed charts only. Following that next job that will deploy the chart.

deploy job will run via matrix, so assume that I have 20 charts and in this PR, I have 5 changed charts.

Therefore, deploy will be triggered against 5 Charts that I need to update their version and deploy them. Hence, having matrix

shini4i commented 9 months ago

Hi @yalattas!

Are you triggering the mentioned actions from the same repository you are trying to update?

If so, the problem is most likely that automation is cloning the target repo (which, in your case, is the same repo you already use) to the charts/ directory while this directory already exists in the workspace.

Could you please describe your use case a bit more?

yalattas commented 9 months ago

Indeed I am access the same repo that's running the CI

Basically, something/someone has to adjust the helm chart, my ci will determine which Chart has been updated and adjust the version accordingly.

Once PR is raised, its considered beta and version will adjust respecting this fact.

Then, when PR is merge to default branch. Version will be bumped up via CI as well.

In case of feature branch OR PR. Version should be as follows -> v1.0.0-pr-x where x is PR number

In case merging to default branch then bumping is the only required thing

Honestly, I wrote a script to resolve this issue already. Yet, explaining to you to enhance the tools for others and us in the future.

Really appreciate your contribution

shini4i commented 9 months ago

That's an interesting use case. I did not expect it, and honestly, I'm not entirely sure it will work reliably with this project.

I've fixed the immediate problem by introducing a new argument clone_path.

By default, it now uses charts-repo instead of charts.

Technically, it can be set to different values in each of the matrix jobs, but if those jobs are running concurrently, you most likely will hit git conflicts.

I will think over the weekend if a more complex logic fits into this project.