Compare commits

...

14 Commits

Author SHA1 Message Date
Stefan Zweifel
abd87b7d94 Release v4.12.0 2021-09-10 19:47:39 +02:00
Stefan Zweifel
54cc2186d1 Remove unwanted chars from tests 2021-09-10 19:47:01 +02:00
Stefan Zweifel
216b25a401 Merge pull request #172 from webignition/issue-171
Output hash of created commit
2021-09-10 19:41:23 +02:00
Jon Cram
05aea7e2d9 Add commit_hash output description to readme 2021-09-10 14:37:45 +01:00
Jon Cram
68fd92dd9c Output hash of created commit 2021-09-10 14:37:45 +01:00
Stefan Zweifel
0426839718 Merge pull request #173 from webignition/run-checks-on-pull-request
Run git-auto-commit, linter and tests checks on pull requests
2021-09-10 15:32:18 +02:00
Stefan Zweifel
97badfaf41 Revert Linter to only run on push event 2021-09-10 15:31:37 +02:00
Jon Cram
10257e2994 Run git-auto-commit, linter and tests checks on pull requests 2021-09-10 13:49:19 +01:00
Stefan Zweifel
e107e28c4e Update README.md 2021-08-19 08:37:15 +02:00
Stefan Zweifel
6834afe239 Update README.md 2021-08-18 20:49:52 +02:00
Stefan Zweifel
27ac2f0a7b Update README 2021-08-18 20:43:30 +02:00
Stefan Zweifel
3568db7bbc Add note about bash dependency 2021-07-13 20:18:17 +02:00
Stefan Zweifel
053f356774 Improve amend section in README
refs #159
2021-05-22 11:34:55 +02:00
Stefan Zweifel
46af2f08b3 Add Example for —amend to README
refs #159
2021-05-20 20:30:05 +02:00
8 changed files with 111 additions and 20 deletions

View File

@@ -1,6 +1,10 @@
name: git-auto-commit
on: push
on:
push:
branches:
- master
pull_request:
jobs:
git-auto-commit:

View File

@@ -1,4 +1,5 @@
name: Lint Code Base
on: push
jobs:

View File

@@ -1,6 +1,10 @@
name: tests
on: push
on:
push:
branches:
- master
pull_request:
jobs:
tests:
@@ -14,4 +18,3 @@ jobs:
- name: Run Tests
run: yarn test

View File

@@ -4,11 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...HEAD)
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...HEAD)
> TBD
## [v4.12.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...v4.12.0) - 2021-09-10
### Added
- Add `commit_hash` output [#172](https://github.com/stefanzweifel/git-auto-commit-action/pull/172)
## [v4.11.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.10.0...v4.11.0) - 2021-05-03
### Added

View File

@@ -34,10 +34,10 @@ The following is an extended example with all possible options available for thi
branch: feature-123
# Optional. Used by `git-commit`.
# See https://git-scm.com/docs/git-commit#_options
# See https://git-scm.com/docs/git-commit#_options
commit_options: '--no-verify --signoff'
# Optional glob pattern of files which should be added to the commit
# Optional glob pattern of files which should be added to the commit
# Defaults to all (.)
# See the `pathspec`-documentation for git
# - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203
@@ -57,8 +57,8 @@ The following is an extended example with all possible options available for thi
# Action will create and push a new tag to the remote repository and the defined branch
tagging_message: 'v1.0.0'
# Optional. Used by `git-status`
# See https://git-scm.com/docs/git-status#_options
# Optional. Used by `git-status`
# See https://git-scm.com/docs/git-status#_options
status_options: '--untracked-files=no'
# Optional. Used by `git-add`
@@ -80,6 +80,8 @@ The following is an extended example with all possible options available for thi
disable_globbing: true
```
Please note that the Action depends on `bash`. If you're using the Action in a job in combination with a custom Docker container, make sure that `bash` is installed.
## Example Workflow
In this example, we're running `php-cs-fixer` in a PHP project to fix the codestyle automatically, then commit possible changed files back to the repository.
@@ -122,6 +124,7 @@ Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/
You can use these outputs to trigger other Actions in your Workflow run based on the result of `git-auto-commit-action`.
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
- `commit_hash`: Returns the full hash of the commit if one was created.
### Example
@@ -137,6 +140,18 @@ You can use these outputs to trigger other Actions in your Workflow run based on
## Limitations & Gotchas
The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore you might run into issues if your Workflow falls into the not supported 20% portion.
The following is a list of edge cases the Action knowingly does not support:
**No `git pull` when the repository is out of the date with remote.** The will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs.
**No support for running the Action in build matrices**. For example, if your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a `git pull` for you, you have to do that yourself.
**No support for `git rebase` or `git merge`**. There are many strategies on how to integrate remote upstream changes to a local repository. `git-auto-commit` does not want to be responsible for doing that.
If this Action doesn't work for your workflow, check out [EndBug/add-and-commit](https://github.com/EndBug/add-and-commit).
### Checkout the correct branch
You must use `action/checkout@v2` or later versions to checkout the repository.
@@ -168,8 +183,10 @@ storing the token as a secret in your repository and then passing the new token
If you work in an organization and don't want to create a PAT from your personal account, we recommend using a [robot account](https://docs.github.com/en/github/getting-started-with-github/types-of-github-accounts) for the token.
## Advanced Uses
### Using the Action in forks from public repositories
<details>
<summary>Use in forks from public repositories</summary>
**☝️ Important Notice**: This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\
If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch.
@@ -223,18 +240,71 @@ As you can see, your contributors have to go through hoops to make this work. **
For more information about running Actions on forks, see [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/).
### Push to forks from private repositories
</details>
<details>
<summary>Push to forks from private repositories</summary>
By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings.
See [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) or the [GitHub docs](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) for details.
### Signing Commits & Other Git Command Line Options
</details>
<details>
<summary>
Signing Commits & Other Git Command Line Options
</summary>
Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regulary.
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
</details>
<details>
<summary>
Using `--amend` and `--no-edit` as commit options
</summary>
If you would like to use this Action to create a commit using [`--amend`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend) and [`--no-edit`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-edit) you need to make some adjustments.
**☝️ Important Notice:** You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase)
First, you need to extract the previous commit message by using `git log -1 --pretty=%s`.
Then you need to provide this last commit message to the Action through the `commit_message` input option.
Finally, you have to use `push_options: '--force'` to overwrite the git history on the GitHub remote repository. (git-auto-commit will not do a `git-rebase` for you!)
The steps in your workflow might look like this:
```yaml
- uses: actions/checkout@master
with:
# Fetch the last 2 commits instead of just 1. (Fetching just 1 commit would overwrite the whole history)
fetch-depth: 2
# Other steps in your workflow to trigger a changed file
- name: Get last commit message
id: last-commit-message
run: |
echo "::set-output name=msg::$(git log -1 --pretty=%s)"
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: ${{ steps.last-commit-message.outputs.msg }}
commit_options: '--amend --no-edit'
push_options: '--force'
skip_fetch: true
```
See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details.
</details>
## Troubleshooting
### Action does not push commit to repository

View File

@@ -67,6 +67,8 @@ inputs:
outputs:
changes_detected:
description: Value is "true", if the repository was dirty and file changes have been detected. Value is "false", if no changes have been detected.
commit_hash:
description: Full hash of the created commit. Only present if the "changes_detected" output is "true".
runs:
using: 'node12'

View File

@@ -86,6 +86,8 @@ _local_commit() {
commit -m "$INPUT_COMMIT_MESSAGE" \
--author="$INPUT_COMMIT_AUTHOR" \
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};
echo "::set-output name=commit_hash::$(git rev-parse HEAD)";
}
_tag_commit() {

View File

@@ -26,7 +26,7 @@ setup() {
export INPUT_SKIP_FETCH=false
export INPUT_DISABLE_GLOBBING=false
# Configure Git
# Configure Git
if [[ -z $(git config user.name) ]]; then
git config --global user.name "Test Suite"
git config --global user.email "test@github.com"
@@ -43,7 +43,7 @@ teardown() {
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
}
# Create a fake remote repository which tests can push against
# Create a fake remote repository which tests can push against
_setup_fake_remote_repository() {
# Create the bare repository, which will act as our remote/origin
rm -rf "${FAKE_REMOTE}";
@@ -72,7 +72,7 @@ _setup_local_repository() {
cd "${FAKE_LOCAL_REPOSITORY}";
}
# Run the main code related to this GitHub Action
# Run the main code related to this GitHub Action
git_auto_commit() {
bash "${BATS_TEST_DIRNAME}"/../entrypoint.sh
}
@@ -86,6 +86,7 @@ git_auto_commit() {
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
@@ -106,6 +107,7 @@ git_auto_commit() {
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
@@ -128,6 +130,7 @@ git_auto_commit() {
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "Working tree clean. Nothing to commit."
}
@@ -138,6 +141,7 @@ git_auto_commit() {
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "Working tree clean. Nothing to commit."
}
@@ -150,8 +154,7 @@ git_auto_commit() {
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line "::set-output name=changes_detected::true"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
@@ -303,7 +306,7 @@ git_auto_commit() {
}
@test "It can checkout a different branch" {
# Create foo-branch and then immediately switch back to master
# Create foo-branch and then immediately switch back to master
git checkout -b foo
git checkout master
@@ -318,7 +321,7 @@ git_auto_commit() {
assert_line "INPUT_BRANCH value: foo"
assert_line "::debug::Push commit to remote branch foo"
# Assert a new branch "foo" exists on remote
# Assert a new branch "foo" exists on remote
run git ls-remote --heads
assert_output --partial refs/heads/foo
}
@@ -408,7 +411,7 @@ git_auto_commit() {
}
@test "It pushes generated commit and tag to remote branch and updates commit sha" {
# Create "a-new-branch"-branch and then immediately switch back to master
# Create "a-new-branch"-branch and then immediately switch back to master
git checkout -b a-new-branch
git checkout master
@@ -448,7 +451,7 @@ git_auto_commit() {
mkdir "${FAKE_LOCAL_REPOSITORY}"/nested
touch "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py
# Commit changes
# Commit changes
echo "Commit changes before running git_auto_commit";
cd "${FAKE_LOCAL_REPOSITORY}";
git add . > /dev/null;