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
569 stars 209 forks source link

Action is incompatible with `actions/checkout@v2` #13

Closed sean-krail closed 4 years ago

sean-krail commented 4 years ago

When running this action, it's checking for charts that have changed since the same commit. For instance the release workflow was triggered by commit da27374 and is checking for changes since the same commit da27374, which will always return no changes.

Source: https://github.com/jitterbit/charts/commit/da273746d48ce02e5c9e821a4e3d15da85c1755e/checks?check_suite_id=514791721#step:5:25

Logs:

> Run helm/chart-releaser-action@v1.0.0-alpha.2
  with:
    charts_dir: charts
  env:
    CR_TOKEN: ***
charts
Looking up latest tag...
Discovering changed charts since 'da273746d48ce02e5c9e821a4e3d15da85c1755e'...
Nothing to do. No chart changes detected.

Repo: https://github.com/jitterbit/charts

Workflow: https://github.com/jitterbit/charts/blob/master/.github/workflows/release.yml

sean-krail commented 4 years ago

I think I know what's going on. actions/checkout@v2 sets fetch-depth to 1 by default and git rev-list --max-parents=0 --first-parent HEAD is expecting the full git history for the branch. So anyone using v2 of the checkout action will have this issue (See https://github.com/jaegertracing/helm-charts/runs/490290185#step:6:8).

Instead of using the git cli to infer the repo's/branch's first commit, the tool should use the action's base commit provided by the github context: ${{ github.event.before }}

So to get changed files, the main.js script would need to pass context.payload.before into the bash scripts and then the get changed_files logic would be:

changed_files=$(git diff --find-renames --name-only "$base_commit" -- "$charts_dir")

Source: https://github.com/helm/chart-releaser-action/blob/master/cr.sh#L184

For now the workaround is to continue using actions/checkout@v1 ~I guess~ (worked after I also reverted back to Helm v2).

sean-krail commented 4 years ago

Related to https://github.com/helm/chart-testing-action/issues/20

Chart testing and chart releaser expect git commit history for the current HEAD but actions/checkout@v2 fetches with a depth of 1 (only the HEAD commit) by default. Like I said in the previous comment, these two actions need to take ${{ github.event.before }} (base commit SHA) and ${{ github.event.after }} (head commit SHA) into account and use the GitHub API for comparing two commits. At least that's what I did for my jitterbit/get-changed-files action.

unguiculus commented 4 years ago

actions/checkout@v2 does a shallow clone by default. This can be reconfigured:

- uses: actions/checkout@v2
  with:
    fetch-depth: "0"
unguiculus commented 4 years ago

Actually, this still doesn't seem to cut it. The following is working:

- name: Checkout
  uses: actions/checkout@v2

- name: Fetch history
  run: git fetch --prune --unshallow
devth commented 4 years ago

This is kind of a nasty gotcha. I'd rather CR fail (or at the very least warn) if it can't find any git history, rather than making it seem like everything is fine, e.g.

Run helm/chart-releaser-action@v1.0.0
yetibot-helm
Looking up latest tag...
Discovering changed charts since '5018edb0c13cd99925cbfc417f78433eb3fc26af'...
Nothing to do. No chart changes detected.

as in https://github.com/yetibot/yetibot-helm/runs/1353828038

It says "Looking up latest tag" but in reality it can't find any tags when fetch-depth is 1 (which is the default for actions/checkout@v2), so it's comparing HEAD to HEAD, finds no changes and skips release.

realshuting commented 3 years ago

Actually, this still doesn't seem to cut it. The following is working:

- name: Checkout
  uses: actions/checkout@v2

- name: Fetch history
  run: git fetch --prune --unshallow

I'm still seeing the same issue with the above configuration, any idea what could be missing?

Run helm/chart-releaser-action@v1.0.0
kyverno
Looking up latest tag...
Discovering changed charts since 'v1.3.0-rc6'...
Nothing to do. No chart changes detected.

It is used in GitHub Action, here's the log, see Run Chart-releaser on this page.

davidkarlsen commented 3 years ago

@realshuting Try adding fetch-depth: 0, see https://github.com/helm/charts-repo-actions-demo for working examples.

realshuting commented 3 years ago

Thanks @davidkarlsen!

Currently I published the Helm release manually, will modify the configuration and test it out.