cocogitto / cocogitto-action

A github action to ensure your current gitlog respect the conventional commit specification
22 stars 17 forks source link

[BUG] Fails to check from latest tag #13

Closed robo9k closed 10 months ago

robo9k commented 1 year ago

Describe the bug check-latest-tag-only does not seem to work under certain conditions. Trying to use the action in a repository that has non-compliant commits until including the latest tag results in it actually checking the wrong i.e. almost-all revisions.

To Reproduce

$ cd $(mktemp -d)
$ git init
$ git commit --allow-empty -m 'Non-compliant 1'
$ git commit --allow-empty -m 'Non-compliant 2'
$ git tag -a tag -m 'tag'
$ git checkout -b branch
$ git commit --allow-empty -m 'chore: Compliant 1'
$ git checkout --force $(git rev-parse HEAD)
$ git rev-list --max-parents=0 HEAD
xyz
$ git rev-parse HEAD^1
abc
$ git log --oneline
def (HEAD, branch) chore: Compliant 1
abc (tag: tag, main) Non-compliant 2
xyz Non-compliant 1
$ cog check --from-latest-tag
Found 1 non compliant commits in xyz..HEAD

Errored commit: abc <robot9001>
        Commit message: 'Non-compliant 2'
$ cog check tag..HEAD
No errored commits

Action log:

Checking commits from tag
Error: 
Found 1 non compliant commits in xyz..HEAD:

Errored commit: abc <robot9001>
    Commit message: 'Non-compliant 2'

Expected behavior I expected the action to successfully check the single compliant commit after the latest tag. I also expected the action / the cog CLI binary to (debug) log the revisions it is actually using.

I'm filing this issue against the action instead of the binary, since the action's cog.sh seems to log a revision range (tag..HEAD) that the binary does not actually (log and) use (xyz..HEAD), so both likely need to be fixed.

Additional context

permissions:
    contents: read

on:
    pull_request:
        branches: [ main ]

jobs:
    check-commits:
        # https://github.com/cocogitto/cocogitto-action
        runs-on: ubuntu-latest
        name: check conventional commit compliance
        steps:
            - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
              with:
                fetch-depth: 0
                # pick the pr HEAD instead of the merge commit
                ref: ${{ github.event.pull_request.head.sha }}

            - name: Conventional commits check
              uses: oknozor/cocogitto-action@ac6260150ee57e3164cd95b47fc84cdee9e3444c # v3.5
              with:
                check-latest-tag-only: true
$ cog --version
cog 5.5.0

$ git --version
git version 2.25.1
Djaytan commented 10 months ago

I have the same issue on my side: https://github.com/Djaytan/mc-jobs-reborn-patch-place-break/actions/runs/6854752375/job/18638344508?pr=347

Found 667 non compliant commits in d7f8a3..HEAD:

Where d7f8a3 is the first repository commit whereas I would expect the range 7bb0c37..HEAD containing only one commit.

Djaytan commented 10 months ago

Issue filled on binary side: https://github.com/cocogitto/cocogitto/issues/341

oknozor commented 10 months ago

This is the intended behavior, git tag -a tag -m 'tag' does not produce a valid semver tag and which is not picked by cocogitto. Please see https://github.com/cocogitto/cocogitto/issues/341#issuecomment-1835547787

dfranco commented 8 months ago

This is the intended behavior, git tag -a tag -m 'tag' does not produce a valid semver tag and which is not picked by cocogitto. Please see cocogitto/cocogitto#341 (comment)

@oknozor: The instructions from mentioned comment worked well for my repo, thanks a lot.