Skip to content

delegate git responsability to other github actions #151

Open
@gmeligio

Description

@gmeligio

What problem are you facing?

My use case is when I use a separate git action to manage git changes, like pushes, creating a new pull request, etc. When running terraform-docs/gh-actions, it will always configure git and stage the changes even when I don't use push or fail. Sometimes those git changes that I didn't need to happen, since I didn't want a push or a faill on diff, change the git setup for the workflow and are incompatible with the next steps I would like to use, like not taking into account a generated Github token, checking out the branch.

For example, for git setup with token, user, and email configuration, I could use the inputs of actions/checkout. Depending on whether my use case is a Github organization, etc, the git setup can change, and it wouldn't be feasible to cover all the git setup scenarios in git_setup .

git_setup() {
# When the runner maps the $GITHUB_WORKSPACE mount, it is owned by the runner
# user while the created folders are owned by the container user, causing this
# error. Issue description here: https://github.com/actions/checkout/issues/766
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
git config --global user.name "${INPUT_GIT_PUSH_USER_NAME}"
git config --global user.email "${INPUT_GIT_PUSH_USER_EMAIL}"
git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
}

For committing changes, there are some actions, like stefanzweifel/git-auto-commit-action, with logic for different commit use cases.

git_commit() {
if [ "$(git_status)" -eq 0 ]; then
echo "::debug No files changed, skipping commit"
exit 0
fi
echo "::debug Following files will be committed"
git status -s
local args=(
-m "${INPUT_GIT_COMMIT_MESSAGE}"
)
if [ "${INPUT_GIT_PUSH_SIGN_OFF}" = "true" ]; then
args+=("-s")
fi
git commit "${args[@]}"
}

For failing on diff, a small bash script like git add -A && git diff --exit-code HEAD can be used and there are also actions like nickcharlton/diff-check that cover more use cases.

git_status() {
git status --porcelain | grep -c -E '([MA]\W).+' || true
}

This use case of pull requests is not covered today in terraform-docs/gh-actions but just as another example. For handling new or existing pull requests, the action peter-evans/create-pull-request can be used.

How could terraform-docs help solve your problem?

Essentially, my request is to reduce the maintenance and increase stability of this action by narrowing its scope to terraform-docs, which it does very well today. So I think deprecating the git features, like setup, staging, and diff, could help multiple people use or contribute to this project.

  • Solve my use case by using other actions for git changes.
  • Remove confusion for other users who have new git use cases.
  • Reduce work for this action's mantainers who do not have to support git features and can focus more on terraform-docs use cases.

For example, it could potentially solve the following issues I found related to git features:

Alternatives Explored

I couldn't make it work with this action after multiple attempts trying to disable or reset git staging index and configuration, so the next workflow steps can find the git configuration as it was before running terraform-docs/gh-actions, except for the changes in the working tree. So I ended up installing the release with

- name: Install terraform-docs
  uses: jaxxstorm/action-install-gh-release@4304621e8c48d66093a8a214af5d5b5bc3b3d943 # v2.0.0
  with:
    repo: terraform-docs/terraform-docs
    tag: v0.19.0

- name: Generate documentation files
  run: |-
    terraform-docs .

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions