diff --git a/commit/action.yml b/commit/action.yml index 52c811a..a9f63af 100644 --- a/commit/action.yml +++ b/commit/action.yml @@ -4,7 +4,7 @@ author: 'elstudio' branding: icon: 'git-commit' color: 'green' -inputs: +inputs: wdPath: description: 'Working directory path' required: false @@ -13,14 +13,24 @@ inputs: description: 'Print script debugging info' required: false default: 'false' - commitMessage: + commitMessage: description: 'Message to log for this commit' required: false default: 'Regenerate build artifacts.' + amend: + description: '--amend the previous commit, instead of adding a new one' + required: false + default: false + force: + description: 'do a force push (only useful with `amend`' + required: false + default: false runs: using: 'docker' image: 'Dockerfile' env: DEBUG: ${{ inputs.debug }} WD_PATH: ${{ inputs.wdPath }} - COMMIT_MESSAGE: ${{ inputs.commitMessage }} + COMMIT_MESSAGE: ${{ inputs.commitMessage }} + AMEND: ${{ inputs.amend }} + FORCE: ${{ inputs.force }} diff --git a/commit/entrypoint.sh b/commit/entrypoint.sh index a65e8db..d9702e5 100755 --- a/commit/entrypoint.sh +++ b/commit/entrypoint.sh @@ -1,9 +1,9 @@ #!/bin/sh -## This GitHub Action for git commits any changed files and pushes +## This GitHub Action for git commits any changed files and pushes ## those changes back to the origin repository. ## ## Required environment variable: -## - $GITHUB_TOKEN: The token to use for authentication with GitHub +## - $GITHUB_TOKEN: The token to use for authentication with GitHub ## to commit and push changes back to the origin repository. ## ## Optional environment variables: @@ -38,11 +38,19 @@ git_setup ( ) { # This section only runs if there have been file changes echo "Checking for uncommitted changes in the git working tree." if expr $(git status --porcelain | wc -l) \> 0 -then +then git_setup git add . - git commit -m "$COMMIT_MESSAGE" - git push -else + if [ "${AMEND-}" = true ]; then + git commit --amend --no-edit + else + git commit -m "$COMMIT_MESSAGE" + fi + if [ "${FORCE-}" = true ]; then + git push --force-with-lease + else + git push + fi +else echo "Working tree clean. Nothing to commit." fi