orhun / git-cliff-action

GitHub action to generate a changelog based on the Git history
https://github.com/orhun/git-cliff
Apache License 2.0
117 stars 14 forks source link

Action can't access `github.contributors`; works locally #17

Closed welpo closed 6 months ago

welpo commented 6 months ago

Hi!

Short version: when using the action git-cliff doesn't have access to github.contributors. It works locally.


I'm using the new GitHub integration (great job!). It works great locally, but when using this action (orhun/git-cliff-action@main), I get this in the logs:

+ git-cliff --config=cliff.toml --latest --strip all
 ERROR git_cliff > Template render error:
Variable `github.contributors` not found in context while rendering 'template'

My template uses github.contributors like this:

{%- if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 -%}
  {% raw %}\n{% endraw %}### 👥 New contributors
  {% raw -%}\n{% endraw -%}
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
  🫶 @{{ contributor.username }} made their first contribution
    {%- if contributor.pr_number %} in \
      [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
    {%- endif %}
{% endfor %}
{%- endif %}

I understand the issue could be bypassed by adding an extra if like:

{% if github.contributors %}
{# … the rest of the code above #}
{% endif %}

While no errors would be shown in this case, this would skip the contributors section entirely.

I have:

name: Continuous Deployment

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  deploy:
    name: Deploy and release
    runs-on: ubuntu-22.04
    permissions:
      contents: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Generate the changelog
        uses: orhun/git-cliff-action@main
        id: git-cliff
        with:
          config: cliff.toml
          args: --latest --strip all
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OUTPUT: CHANGES.md

      - name: Create GitHub release
        run: |
          gh release create ${{ github.ref_name }} \
            --title "Release ${{ github.ref_name }}" \
            --notes "${{ steps.git-cliff.outputs.content }}"
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
orhun commented 6 months ago

I realized I was building git-cliff with --no-default-features in the docker image and that's probably why the GitHub feature is not enabled. I will create a new release soon to fix this!

Thanks for reporting! 🐻

orhun commented 6 months ago

Just released a new version - can you try again and let me know?

welpo commented 6 months ago

It's fixed!

Thank you for the prompt fix and your amazing job with git-cliff~

orhun commented 6 months ago

Awesome! Thanks for confirming <3