Compare commits

...

20 Commits

Author SHA1 Message Date
Stefan Zweifel
8f5b58c89c Tag v4.7.0 2020-10-21 20:45:37 +02:00
Stefan Zweifel
e3610414be Update README 2020-10-17 14:15:18 +02:00
Stefan Zweifel
042c3265d5 Update README 2020-10-17 14:14:28 +02:00
Stefan Zweifel
90cedba8bc Upgrade bats to v1.2.1 2020-10-16 19:26:44 +02:00
Stefan Zweifel
b833fe0e9d Update Code Example for pull_request_target trigger 2020-10-16 09:18:41 +02:00
Stefan Zweifel
653ea719ea Update Changelog 2020-10-15 21:15:41 +02:00
Stefan Zweifel
47c724214a Merge pull request #115 from stefanzweifel/feature/checkout-options
Feature: Checkout Options
2020-10-15 20:36:06 +02:00
Stefan Zweifel
1ba48c6d7f Fix Linter Errors in entrypoint.sh 2020-10-15 20:30:26 +02:00
Stefan Zweifel
b9e4cea0ef Disable Markdown Linter 2020-10-15 20:30:19 +02:00
Stefan Zweifel
cfdb7e609e Add checkout_options to README 2020-10-15 20:26:03 +02:00
Stefan Zweifel
849613a3ad Add test to cover checkout-options 2020-10-15 20:23:04 +02:00
Stefan Zweifel
0ee9fb7263 Add checkout_options 2020-10-15 20:21:08 +02:00
Stefan Zweifel
6456430b6b Ignore shellchecks 2020-10-15 20:15:31 +02:00
Stefan Zweifel
7f67b0b49b Rename Test 2020-10-14 20:28:01 +02:00
Stefan Zweifel
8700c3bc1c Merge pull request #113 from docwhat/pr/complex-branches-2
Fix checking out branch names with / chars
2020-10-12 16:34:53 +02:00
Stefan Zweifel
872d72f1ae Update Tests 2020-10-12 16:33:12 +02:00
Christian Höltje
f905f00706 Fix checking out branch names with / chars
If git can't automatically figure out if the argument is a branch or
a path, it will need to be told explicitly by using `--`:

    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'

Fixes: #106
2020-10-12 10:17:25 -04:00
Stefan Zweifel
9c1e5d1c6a Merge pull request #111 from francescobianco/patch-1
Update README.md
2020-10-12 08:18:24 +02:00
Francesco Bianco
18a94e4f78 Update README.md 2020-10-11 22:35:28 +02:00
Stefan Zweifel
44aeb24da7 Fix Typo in Changelog 2020-10-11 20:36:41 +02:00
7 changed files with 90 additions and 32 deletions

View File

@@ -14,5 +14,6 @@ jobs:
uses: github/super-linter@v3
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: false
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -9,10 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
> TBD
## [v4.7.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.6.0...v4.7.0) - 2020-10-11
### Added
- Add `checkout_options` [#115](https://github.com/stefanzweifel/git-auto-commit-action/pull/115)
## [v4.6.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.5.1...v4.6.0) - 2020-10-11
### Changes
### Changed
- Make "commit_message" optional and set default commit message to "Apply automatic changes" [#103](https://github.com/stefanzweifel/git-auto-commit-action/issues/103), [#110](https://github.com/stefanzweifel/git-auto-commit-action/pull/110)
### Fixes

View File

@@ -53,6 +53,9 @@ Add the following step at the end of your job, after other steps that might add
# Optional: Disable dirty check and always try to create a commit and push
skip_dirty_check: true
# Optional: Allows you to update how the repo is checked out
checkout_options: '-q --force -b'
```
## Example
@@ -146,6 +149,11 @@ If you work in an organization and don't want to create a PAT from your personal
### Using the Action in forks from public repositories
**☝️ 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.
---
By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.)
If you want that a Workflow using this Action runs on Pull Requests opened by forks, 2 things have to be changed:
@@ -165,15 +173,13 @@ The following workflow runs `php-cs-fixer` (a code linter and fixer for PHP) whe
```yaml
name: Format PHP
on: [pull_request, pull_request_target]
on: [push, pull_request, pull_request_target]
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
@@ -190,7 +196,7 @@ Here's how the Pull Request will look like:
![Screenshot of a Pull Request from a Fork](https://user-images.githubusercontent.com/1080923/90955964-9c74c080-e482-11ea-8097-aa7f5161f50e.png)
As you can see, your contributors have to go through hoops to make this work. For Workflows which runter linters and fixers (like the example above) we recommend running them when a push happens on the `master`-branch.
As you can see, your contributors have to go through hoops to make this work. **For Workflows which runter linters and fixers (like the example above) we recommend running them when a push happens on the `master`-branch.**
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/).
@@ -254,7 +260,7 @@ This is due to limitations set up by GitHub, [commits of this Action do not trig
The package has tests written in [bats](https://github.com/bats-core/bats-core). You can run them with the following command.
```shell
npm run tests
npm run test
```
## Versioning

View File

@@ -44,6 +44,10 @@ inputs:
description: Push options (eg. --force)
required: false
default: ''
checkout_options:
description: Checkout options (eg. --branch)
required: false
default: ''
skip_dirty_check:
description: Skip the check if the git repository is dirty and always try to create a commit.
required: false

View File

@@ -29,10 +29,11 @@ _main() {
_switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
cd $INPUT_REPOSITORY;
cd "$INPUT_REPOSITORY";
}
_git_is_dirty() {
# shellcheck disable=SC2086
[ -n "$(git status -s -- $INPUT_FILE_PATTERN)" ]
}
@@ -42,12 +43,17 @@ _switch_to_branch() {
# Fetch remote to make sure that repo can be switched to the right branch.
git fetch;
# shellcheck disable=SC2206
INPUT_CHECKOUT_OPTIONS_ARRAY=( $INPUT_CHECKOUT_OPTIONS );
# Switch to branch from current Workflow run
git checkout $INPUT_BRANCH;
git checkout ${INPUT_CHECKOUT_OPTIONS:+"${INPUT_CHECKOUT_OPTIONS_ARRAY[@]}"} "$INPUT_BRANCH" --;
}
_add_files() {
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
# shellcheck disable=SC2086
git add ${INPUT_FILE_PATTERN};
}
@@ -55,6 +61,7 @@ _local_commit() {
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}";
echo "::debug::Apply commit options ${INPUT_COMMIT_OPTIONS}";
# shellcheck disable=SC2206
INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS );
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" \
@@ -80,6 +87,7 @@ _push_to_github() {
echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS}";
echo "::debug::Apply push options ${INPUT_PUSH_OPTIONS}";
# shellcheck disable=SC2206
INPUT_PUSH_OPTIONS_ARRAY=( $INPUT_PUSH_OPTIONS );
if [ -z "$INPUT_BRANCH" ]

View File

@@ -32,6 +32,7 @@ setup() {
export INPUT_COMMIT_AUTHOR="Test Suite <test@users.noreply.github.com>"
export INPUT_TAGGING_MESSAGE=""
export INPUT_PUSH_OPTIONS=""
export INPUT_CHECKOUT_OPTIONS=""
export INPUT_SKIP_DIRTY_CHECK=false
skipIfNot "$BATS_TEST_DESCRIPTION"
@@ -71,7 +72,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout master"
shellmock_expect git --type exact --match "checkout master --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
@@ -99,7 +100,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout master" ]
[ "${capture[2]}" = "git-stub checkout master --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
@@ -111,7 +112,7 @@ main() {
shellmock_expect git --type exact --match "status -s ."
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout master"
shellmock_expect git --type exact --match "checkout master --"
shellmock_expect git --type exact --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push origin'
@@ -123,7 +124,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout master" ]
[ "${capture[2]}" = "git-stub checkout master --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
@@ -148,7 +149,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.html M new-file-2.html" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout master"
shellmock_expect git --type exact --match "checkout master --"
shellmock_expect git --type partial --match "add"
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
@@ -167,7 +168,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- a.txt b.txt c.txt new-file-1.html new-file-2.html" ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout master" ]
[ "${capture[2]}" = "git-stub checkout master --" ]
[ "${capture[3]}" = "git-stub add a.txt b.txt c.txt new-file-1.html new-file-2.html" ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
@@ -181,7 +182,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout master"
shellmock_expect git --type exact --match "checkout master --"
shellmock_expect git --type partial --match "add"
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
@@ -198,7 +199,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout master" ]
[ "${capture[2]}" = "git-stub checkout master --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com> --no-verify --signoff" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
@@ -214,7 +215,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout master"
shellmock_expect git --type exact --match "checkout master --"
shellmock_expect git --type partial --match "add"
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
@@ -231,7 +232,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout master" ]
[ "${capture[2]}" = "git-stub checkout master --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=A Single Test -c user.email=single-test@github.com commit -m Commit Message --author=A Single Test <single@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
@@ -245,7 +246,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout master"
shellmock_expect git --type exact --match "checkout master --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
@@ -265,7 +266,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout master" ]
[ "${capture[2]}" = "git-stub checkout master --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com tag -a v1.0.0 -m v1.0.0" ]
@@ -281,7 +282,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout master"
shellmock_expect git --type exact --match "checkout master --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
@@ -301,13 +302,46 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout master" ]
[ "${capture[2]}" = "git-stub checkout master --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags --force" ]
}
@test "git-checkout-options-are-applied" {
INPUT_CHECKOUT_OPTIONS="-b --progress"
touch "${test_repository}"/new-file-{1,2,3}.txt
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout -b --progress master --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
run main
echo "$output"
# Success Exit Code
[ "$status" = 0 ]
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout -b --progress master --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
}
@test "can-checkout-different-branch" {
INPUT_BRANCH="foo"
@@ -316,7 +350,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout foo"
shellmock_expect git --type exact --match "checkout foo --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push --set-upstream origin'
@@ -344,7 +378,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout foo" ]
[ "${capture[2]}" = "git-stub checkout foo --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push --set-upstream origin HEAD:foo --tags" ]
@@ -359,7 +393,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout"
shellmock_expect git --type exact --match "checkout --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push origin'
@@ -387,7 +421,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout" ]
[ "${capture[2]}" = "git-stub checkout --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub push origin" ]
@@ -402,7 +436,7 @@ main() {
shellmock_expect git --type partial --output " M new-file-1.txt M new-file-2.txt M new-file-3.txt" --match "status"
shellmock_expect git --type exact --match "fetch"
shellmock_expect git --type exact --match "checkout"
shellmock_expect git --type exact --match "checkout --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push origin'
@@ -430,7 +464,7 @@ main() {
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${capture[2]}" = "git-stub checkout" ]
[ "${capture[2]}" = "git-stub checkout --" ]
[ "${capture[3]}" = "git-stub add ." ]
[ "${capture[4]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com commit -m Commit Message --author=Test Suite <test@users.noreply.github.com>" ]
[ "${capture[5]}" = "git-stub -c user.name=Test Suite -c user.email=test@github.com tag -a v2.0.0 -m v2.0.0" ]

View File

@@ -3,6 +3,6 @@
bats@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.1.0.tgz#6fc44f283ed4e7af2b6ffac93ec5026a1acbdc66"
integrity sha512-1pA29OhDByrUtAXX+nmqZxgRgx2y8PvuZzbLJVjd2dpEDVDvz0MjcBMdmIPNq5lC+tG53G+RbeRsbIlv3vw7tg==
version "1.2.1"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.2.1.tgz#c15aecc3eb331aedf28678880fab2be0b73eba43"
integrity sha512-2fcPDRQa/Kvh6j1IcCqsHpT5b9ObMzRzw6abC7Bg298PX8Qdh9VRkvO2WJUEhdyfjq2rLBCOAWdcv0tS4+xTUA==