Skip to content

[feature] cz action to output commit sha #98

Open
@reinthal

Description

@reinthal

Feature:

Commitizen gh action outputs the sha of the commit as an output to be used for downstream builds

   steps:
      - uses: actions/checkout@v4
        with:
          ref: ${steps.cz.outputs.sha}

Background

We want to display the current build to the user in the UI of an api we are making with fastapi. To do this, we use the version in the pyproject.toml. However, Github actions does not checkout the latest commit on checkout, only the commit that triggered the gh workflow. Thus, when we add the version information before building the container, the latest commit from commitizen action is not added to the checked out code that builds the container. To solve this, we can add the following to our workflow:

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: main

according to this issue in gh checkout action actions/checkout#439. However, this this is sub-optimal for larger codebase where someone could merge to main between the commitizen bump and the gh action checkout operation. This would result in subsequent build of the wrong codebase. Suggested solution is to output the sha in the commitizen action when a commit is made so the sha can be used for subsequent checkouts.

   steps:
      - uses: actions/checkout@v4
        with:
          ref: ${steps.cz.outputs.sha}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions