Compare commits

...

109 Commits

Author SHA1 Message Date
Stefan Zweifel
9b7c21583c Release v4.7.1 2020-10-22 07:37:21 +02:00
Stefan Zweifel
4cc90c7784 Fix Linter Errors 2020-10-22 07:37:16 +02:00
Stefan Zweifel
367938329d Merge pull request #120 from stefanzweifel/revert-115-feature/checkout-options
Revert "Feature: Checkout Options"
2020-10-22 07:35:11 +02:00
Stefan Zweifel
25cac34d8d Revert "Feature: Checkout Options" 2020-10-22 07:33:38 +02:00
Stefan Zweifel
30cd17bff0 Merge branch 'master' of github.com:stefanzweifel/git-auto-commit-action 2020-10-21 20:45:48 +02:00
Stefan Zweifel
8f5b58c89c Tag v4.7.0 2020-10-21 20:45:37 +02:00
Stefan Zweifel
65928d2898 Merge pull request #118 from stefanzweifel/tests-on-github-actions
Test Action through GitHub Actions ♾️
2020-10-17 14:59:06 +02:00
Stefan Zweifel
6b4ef1444c Add Badge 2020-10-17 14:52:58 +02:00
Stefan Zweifel
55291ea168 Rename Step 2020-10-17 14:51:58 +02:00
Stefan Zweifel
2b5c86365b Delete Remote Branch 2020-10-17 14:46:50 +02:00
Stefan Zweifel
ff28943460 Add Integration Tests 2020-10-17 14:29:42 +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
Stefan Zweifel
5c9bfe7477 Tag v4.6.0 2020-10-11 20:34:17 +02:00
Stefan Zweifel
814219db13 Merge pull request #110 from Aebrathia/patch-1
Make commit_message optional #103
2020-10-11 20:16:25 +02:00
Stefan Zweifel
a204abce16 Update action.yml 2020-10-11 20:14:15 +02:00
Andréa Maugars
fc18df1417 Make commit_message optional 2020-10-11 15:32:07 +02:00
Stefan Zweifel
8f243393e7 Link Tests Badge 2020-10-11 11:47:09 +02:00
Stefan Zweifel
fc5b9bf8cf Merge pull request #109 from stefanzweifel/improve-testsuite
Expand existing BATS Test Suite to cover every feature
2020-10-11 11:44:48 +02:00
Stefan Zweifel
a818c89e49 Add can-work-with-empty-branch-name-and-tags test 2020-10-11 11:24:53 +02:00
Stefan Zweifel
8bf1b5695a Add can-work-with-empty-branch-name test 2020-10-11 11:21:16 +02:00
Stefan Zweifel
ea30556d53 Add can-checkout-different-branch test 2020-10-11 11:21:06 +02:00
Stefan Zweifel
cd7c7f1a8a Add git-push-options-are-applied test 2020-10-11 11:20:51 +02:00
Stefan Zweifel
4e16840be4 Add can-create-tag test 2020-10-11 11:20:12 +02:00
Stefan Zweifel
b0295737db Add commit-user-and-author-settings-are-applied test 2020-10-11 11:20:01 +02:00
Stefan Zweifel
0d6d4a4b22 Add git-commit-options-are-applied 2020-10-11 11:19:49 +02:00
Stefan Zweifel
091b400419 Add git-add-file-pattern-is-applied test 2020-10-11 11:19:38 +02:00
Stefan Zweifel
f7e362220d WIP 2020-10-11 11:19:22 +02:00
Stefan Zweifel
df97d6fbd8 Make testing a single test easier 2020-10-11 10:40:59 +02:00
Stefan Zweifel
4f0fc14d0c Add shellmock_clean to setup method 2020-10-11 10:40:48 +02:00
Stefan Zweifel
cdf7b74cbf Fix remaining TODO test 2020-10-11 10:40:40 +02:00
Stefan Zweifel
862aa0e1e1 Update Changelog 2020-10-10 19:22:22 +02:00
Stefan Zweifel
a9d1ac4f06 Merge pull request #108 from stefanzweifel/fetch-repo-before-checkout
Better support branches with special characters in them
2020-10-10 19:19:48 +02:00
Stefan Zweifel
ebf8a401ee Fix Tests 2020-10-10 18:06:55 +02:00
Stefan Zweifel
4b8393320b Fetch Repo before git checkout 2020-10-10 17:54:11 +02:00
Stefan Zweifel
60c96d8c0d Merge pull request #107 from docwhat/pr/superlinter
Use SuperLinter instead of only shellcheck
2020-10-10 16:18:15 +02:00
Stefan Zweifel
16d2bf88fd Remove Comments from Workflow 2020-10-10 16:17:58 +02:00
Christian Holtje
54d78531cc Use SuperLinter instead of only shellcheck 2020-10-10 01:12:48 -04:00
Stefan Zweifel
f922a52bf1 Use "main" as branch name in example 2020-10-06 09:13:19 +02:00
Stefan Zweifel
0bf17c328a Fix Example using changes_detected output 2020-10-06 09:11:36 +02:00
Stefan Zweifel
240b9ad1fd Add Example on how to use Outputs 2020-10-05 19:47:23 +02:00
Stefan Zweifel
57054d8e7e Merge pull request #101 from OskarStark/patch-1
Typo
2020-09-23 15:59:12 +02:00
Oskar Stark
613ea337db Revert 2020-09-23 12:43:44 +02:00
Oskar Stark
686020fb2a Typo 2020-09-23 12:43:18 +02:00
Stefan Zweifel
90b474f549 Remove unused Steps in GitHub Workflow 2020-09-13 14:21:10 +02:00
Stefan Zweifel
8c26230a11 Update git config if not set yet 2020-09-13 14:18:41 +02:00
Stefan Zweifel
961d68003e Add yarn.lock to .gitignore 2020-09-13 14:15:28 +02:00
Stefan Zweifel
cbc3d50cea Add Badge 2020-09-13 14:11:23 +02:00
Stefan Zweifel
9e4e2e76fa Add very basic test suite with bats and shellmock (#100)
* Add bats
* Write commits tests
* Add Workflow
* Add .gitignore
* Update Test Suite
* Disable test
* Disable failing test for now
2020-09-13 14:07:14 +02:00
Stefan Zweifel
09aaf2d8fa Update Changelog 2020-09-11 11:22:22 +02:00
Stefan Zweifel
c7ad0bdb15 Release v4.5.1 2020-09-11 11:20:33 +02:00
Stefan Zweifel
9cb711878d Merge pull request #98 from stefanzweifel/revert-95-master
Revert "Creating orphan branch"
2020-09-11 11:19:07 +02:00
Stefan Zweifel
b3fc6f8a17 Revert "Creating orphan branch" 2020-09-11 11:18:24 +02:00
Stefan Zweifel
d51384f592 Revert "Update Workflow"
This reverts commit 4e7ddef1e0.
2020-09-10 19:54:30 +02:00
Stefan Zweifel
4e7ddef1e0 Update Workflow 2020-09-10 19:51:32 +02:00
Stefan Zweifel
cc7755497c Release v4.5.0 2020-09-10 19:48:26 +02:00
Stefan Zweifel
5c3c72f20e Merge pull request #95 from StrongMonkey/master
Creating orphan branch
2020-09-10 19:44:31 +02:00
Daishan
505389d146 Creating orphan branch 2020-09-01 18:12:58 -07:00
Stefan Zweifel
303ce37181 Merge pull request #93 from stefanzweifel/add-note-about-forks
Update README with instructions for forks
2020-08-22 14:45:20 +02:00
Stefan Zweifel
13efc066dd Small little improvements 2020-08-22 14:42:29 +02:00
Stefan Zweifel
3c204cdee3 Update README.md 2020-08-22 14:21:01 +02:00
Stefan Zweifel
0429047166 Update README with instructions for forks
GitHub recently introduced ways for Actions to run on forks.

This update now finally allows repository maintainers to write Workflows to run code linters and fixers which can also work on the forks.
2020-08-22 14:13:11 +02:00
Stefan Zweifel
09d3315401 Update Versioning Workflow 2020-08-16 20:05:44 +02:00
Stefan Zweifel
1f4914882d Release v4.4.1 2020-08-16 20:03:54 +02:00
Stefan Zweifel
b5320678c1 Merge pull request #91 from HarrisonGrodin/patch-1
Only check status of files matching file_pattern
2020-08-16 19:31:45 +02:00
Harrison Grodin
01ffd8c6f6 Only check status of files matching file_pattern 2020-08-15 22:11:45 -04:00
Stefan Zweifel
5222c758dd Add FUNDING.yml 2020-07-29 13:22:07 +02:00
Stefan Zweifel
bbcb72b1e9 Update README 2020-07-26 12:53:22 +02:00
Stefan Zweifel
142eb9509a Update README 2020-07-24 21:11:32 +02:00
Stefan Zweifel
0233fee872 Update Protected Branch Section in README 2020-07-24 20:59:16 +02:00
Stefan Zweifel
808edcd96b Add links to pathspec documentation 2020-07-24 20:44:56 +02:00
Stefan Zweifel
1b1d53f462 Move Inputs and Outputs 2020-07-24 20:24:23 +02:00
Stefan Zweifel
ee93725e66 Merge pull request #86 from TGTGamer/master
Docs: #85 Add small information about command line options
2020-07-18 13:50:16 +02:00
Jonathan S
36304edfd2 Update README.md 2020-07-18 12:42:58 +01:00
Stefan Zweifel
ff97e958aa Update README.md 2020-07-16 11:03:50 +02:00
Stefan Zweifel
90282bf5e2 Release v4.4.0 2020-06-26 21:07:28 +02:00
Stefan Zweifel
c9eb2132b2 Merge pull request #84 from stefanzweifel/feature/skip-dirty-check
Add a "Skip Dirty Check" Option
2020-06-26 21:02:58 +02:00
Stefan Zweifel
c8ded2885e Simplify IF Condition 2020-06-26 21:00:48 +02:00
Stefan Zweifel
f120678ed1 WIP 2020-06-25 20:40:31 +02:00
Stefan Zweifel
4183594932 WIP 2020-06-25 20:38:28 +02:00
Stefan Zweifel
49e28abb3f WIP 2020-06-25 20:31:48 +02:00
Stefan Zweifel
4ebfe28af0 Add skip_dirty_check option 2020-06-25 20:18:20 +02:00
Stefan Zweifel
984a26d893 Update link to versioning info in README 2020-05-17 10:20:34 +02:00
Stefan Zweifel
3804c79d2e Add Versioning GitHub Actions 2020-05-17 10:08:37 +02:00
Stefan Zweifel
69a12041a1 Release v4.3.0 2020-05-16 13:47:17 +02:00
Stefan Zweifel
91b7d20ead Merge pull request #78 from stefanzweifel/feature/push-options
Feature: Push Options
2020-05-16 13:30:24 +02:00
Stefan Zweifel
044b6b777c Fix Typo 2020-05-16 13:26:59 +02:00
Stefan Zweifel
9aab2f8a5c Add example for protected branches 2020-05-16 13:22:34 +02:00
Stefan Zweifel
0280d2ccee Add push_options to README 2020-05-16 13:17:00 +02:00
Stefan Zweifel
b0b5ed34dd Update entrypoint to handle push_options 2020-05-16 11:42:40 +02:00
Stefan Zweifel
ae38c94802 Add push_options to action.yml 2020-05-16 11:42:24 +02:00
Stefan Zweifel
3aae7bb63f Remove continous-deployment.yml 2020-05-16 11:24:57 +02:00
15 changed files with 778 additions and 73 deletions

2
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,2 @@
github: stefanzweifel
custom: ["https://buymeacoff.ee/3oQ64YW"]

View File

@@ -1,31 +0,0 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
name: "Continuous Deployment"
on:
push:
tags:
- "**"
jobs:
release:
name: "Release"
runs-on: "ubuntu-latest"
steps:
- name: "Determine tag"
id: "determine-tag"
run: "echo \"::set-output name=tag::${GITHUB_REF#refs/tags/}\""
- name: "Create release"
uses: "actions/create-release@v1.0.0"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
draft: false
prerelease: false
body: |
See [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) for details.
release_name: "${{ steps.determine-tag.outputs.tag }}"
tag_name: "${{ steps.determine-tag.outputs.tag }}"

26
.github/workflows/integration-tests.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Integration Tests
on: push
jobs:
test-commit-works:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Add Files
run: touch {a,b,c}.txt
- name: Run git-auto-commit
id: "auto-commit-action"
uses: ./
with:
branch: ci-test
commit_message: Message
checkout_options: -b
- name: Delete Branch
run: git push -d origin ci-test

19
.github/workflows/linter.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Lint Code Base
on: push
jobs:
build:
name: Lint Code Base
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Lint Code Base
uses: github/super-linter@v3
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: false
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,12 +0,0 @@
name: Shellcheck
on: push
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: shellcheck
uses: ludeeus/action-shellcheck@0.1.0

23
.github/workflows/tests.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: tests
on: push
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Shell Mock
run: |
git clone https://github.com/capitalone/bash_shell_mock
cd bash_shell_mock
sudo ./install.sh /usr/local
- name: Install BATS
run: yarn install
- name: Run Tests
run: yarn test

15
.github/workflows/versioning.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
name: Keep the versions up-to-date
on:
release:
types: [published, edited]
jobs:
actions-tagger:
runs-on: windows-latest
steps:
- uses: Actions-R-Us/actions-tagger@latest
env:
GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}"
with:
publish_latest_tag: true

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
tests/test_repo
tests/tmpstubs
tests/shellmock.*
yarn.lock

View File

@@ -4,14 +4,65 @@ 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.2.0...HEAD)
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.1...HEAD)
> TBD
## [v4.7.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.0...v4.7.1) - 2020-10-12
### Removed
- Remove `checkout_options` as it broke everything [#120](https://github.com/stefanzweifel/git-auto-commit-action/pull/120/)
## [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
### 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
- Better support for branch names with special characters in them [#108](https://github.com/stefanzweifel/git-auto-commit-action/pull/108)
## [v4.5.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.5.0...v4.5.1) - 2020-09-11
### Removed
- Remove orphan branch feature added in #95 which broke stuff [#98](https://github.com/stefanzweifel/git-auto-commit-action/pull/98)
## [v4.5.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.4.1...v4.5.0) - 2020-09-10
### Added
- Create orphan branch if branch name does not exist [#95](https://github.com/stefanzweifel/git-auto-commit-action/pull/95)
## [v4.4.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.4.0...v4.4.1) - 2020-08-16
### Changed
- Include given `file_pattern` in git dirty check [#91](https://github.com/stefanzweifel/git-auto-commit-action/pull/91)
## [v4.4.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.3.0...v4.4.0) - 2020-06-26
### Added
- Add option to skipt the dirty check and always try to create and push a commit [#82](https://github.com/stefanzweifel/git-auto-commit-action/issues/82), [#84](https://github.com/stefanzweifel/git-auto-commit-action/pull/84)
## [v4.3.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.2.0...v4.3.0) - 2020-05-16
Note: Since v4.3.0 we provide major version tags. You can now use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of a major version. See [#77](https://github.com/stefanzweifel/git-auto-commit-action/issues/77) for details.
### Added
- Add new `push_options`-input. This feature makes it easier for you to force-push commits to a repository. [#78](https://github.com/stefanzweifel/git-auto-commit-action/pull/78), [#72](https://github.com/stefanzweifel/git-auto-commit-action/issues/72)
## [v4.2.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.6...v4.2.0) - 2020-05-10
### Changed
### Changed
- Use `${{ github.head_ref }}` as default branch value. Therefore, the branch name when listening for `pull_request`-events is optional. [#75](https://github.com/stefanzweifel/git-auto-commit-action/pull/75), [#73](https://github.com/stefanzweifel/git-auto-commit-action/pull/73)
@@ -70,7 +121,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Add `commit_user_name`, `commit_user_email` and `commit_author` input options for full customzation on how the commit is being created [#39](https://github.com/stefanzweifel/git-auto-commit-action/pull/39)
### Changed
### Changed
- Make the `branch` input option optional [#41](https://github.com/stefanzweifel/git-auto-commit-action/pull/41)
### Removed

166
README.md
View File

@@ -2,6 +2,13 @@
> The GitHub Action for committing files for the 80% use case.
<a href="https://github.com/stefanzweifel/git-auto-commit-action/actions?query=workflow%3Atests">
<img src="https://github.com/stefanzweifel/git-auto-commit-action/workflows/tests/badge.svg" alt="">
</a>
<a href="https://github.com/stefanzweifel/git-auto-commit-action/actions?query=workflow%3A%22Integration+Tests%22">
<img src="https://github.com/stefanzweifel/git-auto-commit-action/workflows/Integration%20Tests/badge.svg" alt="">
</a>
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the commit back to GitHub.
The default committer is "GitHub Actions <actions@github.com>", and the default author of the commit is "Your GitHub Username <github_username@users.noreply.github.com>".
@@ -13,19 +20,23 @@ This Action has been inspired and adapted from the [auto-commit](https://github.
Add the following step at the end of your job, after other steps that might add or change files.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4.2.0
- uses: stefanzweifel/git-auto-commit-action@v4
with:
# Required
# Optional but recommended, defaults to "Apply automatic changes"
commit_message: Apply automatic changes
# Optional branch to push to, defaults to the current branch
branch: feature-123
# Optional git params
# Optional options appended to `git-commit`
# See https://git-scm.com/docs/git-commit for a list of available options
commit_options: '--no-verify --signoff'
# Optional glob pattern of files which should be added to the commit
file_pattern: src/*.js tests/*.js
# See the `pathspec`-documentation for git
# - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203
# - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
file_pattern: src/*.js tests/*.js *.php
# Optional local file path to the repository
repository: .
@@ -38,6 +49,13 @@ Add the following step at the end of your job, after other steps that might add
# Optional tag message
# Action will create and push a new tag to the remote repository and the defined branch
tagging_message: 'v1.0.0'
# Optional options appended to `git-push`
# See git-push documentation for details: https://git-scm.com/docs/git-push#_options
push_options: '--force'
# Optional: Disable dirty check and always try to create a commit and push
skip_dirty_check: true
```
## Example
@@ -54,7 +72,7 @@ on:
pull_request:
push:
branches:
- "master"
- "main"
jobs:
php-cs-fixer:
@@ -68,11 +86,33 @@ jobs:
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4.2.0
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes
```
## Inputs
Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml) for a full list of supported inputs.
## Outputs
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.
### Example
```yaml
- name: "Run if changes have been detected"
if: steps.auto-commit-action.outputs.changes_detected == 'true'
run: echo "Changes!"
- name: "Run if no changes have been detected"
if: steps.auto-commit-action.outputs.changes_detected == 'false'
run: echo "No Changes!"
```
## Limitations & Gotchas
### Checkout the correct branch
@@ -86,7 +126,7 @@ In non-`push` events, such as `pull_request`, make sure to specify the `ref` to
ref: ${{ github.head_ref }}
```
You have to do this do avoid that the `checkout`-Action clones your repository in a detached state.
You have to do this to avoid that the `checkout`-Action clones your repository in a detached state.
### Commits of this Action do not trigger new Workflow runs
@@ -96,31 +136,85 @@ This is due to [limititations set by GitHub](https://help.github.com/en/actions/
> When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.
You can change this by creating a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new),
storing the token as a secret in your repository and then passing the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action.
storing the token as a secret in your repository and then passing the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
```yaml
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT_TOKEN }}
token: ${{ secrets.PAT }}
```
### Unable to commit into PRs from forks
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.
GitHub currently prohibits Actions to push commits to forks, even when they created a PR and allow edits.
See [issue #25](https://github.com/stefanzweifel/git-auto-commit-action/issues/25) for more information.
## Inputs
### Using the Action in forks from public repositories
Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml) for a full list of supported inputs.
**☝️ 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.
## Outputs
---
You can use these outputs to trigger other Actions in your Workflow run based on the result of `git-auto-commit-action`.
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:
1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target).
2. GitHub Action has to be enabled on the forked repository. \
For security reasons, GitHub does not automatically enable GitHub Actions on forks. The user has to explicitly enable GitHub Actions in the "Actions"-tab of the forked repository. (Mention this in your projects README or CONTRIBUTING.md!)
After you have added the `pull_request_target` to your desired Workflow and the forked repository has enabled Actions and a new Pull Request is opened, the Workflow will run **on the forked repository**.
Due to the fact that the Workflow is not run on the repository the Pull Request is opened in, you won't see any status indicators inside the Pull Request.
#### Example
The following workflow runs `php-cs-fixer` (a code linter and fixer for PHP) when a `pull_request` is opened. We've added the `pull_request_target`-trigger too, to make it work for forks.
```yaml
name: Format PHP
on: [push, pull_request, pull_request_target]
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes
```
Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the the forked repository and will push commits to the same branch.
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.**
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
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
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))
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
## Troubleshooting
### Action does not push commit to repository
Make sure to [checkout the correct branch](#checkout-the-correct-branch).
@@ -132,14 +226,50 @@ please update your Workflow configuration and usage of [`actions/checkout`](http
Updating the `token` value with a Personal Access Token should fix your issues.
### Push to protected branches
If your repository uses [protected branches](https://help.github.com/en/github/administering-a-repository/configuring-protected-branches) you have to do the following changes to your Workflow for the Action to work properly.
You have to enable force pushes to a protected branch (See [documentation](https://help.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)) and update your Workflow to use force push like this.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes
push_options: --force
```
In addition, you have to create a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new),
store the token as a secret in your repository and pass the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
```yaml
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
```
You can learn more about Personal Access Token in the [GitHub documentation](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
Note: If you're working in an organisation and you don't want to create the PAT from your personal account, we recommend using a bot-account for such tokens.
### No new workflows are triggered by the commit of this action
This is due to limitations set up by GitHub, [commits of this Action do not trigger new Workflow runs](#commits-of-this-action-do-not-trigger-new-workflow-runs).
## Running the tests
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 test
```
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags).
We also provide major version tags to make it easier to always use the latest release of a major version. For example you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version.
(More information about this [here](https://help.github.com/en/actions/building-actions/about-actions#versioning-your-action).)
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/LICENSE) file for details.

View File

@@ -6,7 +6,8 @@ author: Stefan Zweifel <hello@stefanzweifel.io>
inputs:
commit_message:
description: Commit message
required: true
required: false
default: Apply automatic changes
branch:
description: Git branch name, where changes should be pushed too. Required if Action is used on the `pull_request` event
required: false
@@ -39,6 +40,14 @@ inputs:
description: Message used to create a new git tag with the commit. Keep this empty, if no tag should be created.
required: false
default: ''
push_options:
description: Push options (eg. --force)
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
default: false
outputs:
changes_detected:

View File

@@ -5,7 +5,7 @@ set -eu
_main() {
_switch_to_repository
if _git_is_dirty; then
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
echo "::set-output name=changes_detected::true";
@@ -29,22 +29,28 @@ _main() {
_switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
cd $INPUT_REPOSITORY;
cd "$INPUT_REPOSITORY";
}
_git_is_dirty() {
[ -n "$(git status -s)" ]
# shellcheck disable=SC2086
[ -n "$(git status -s -- $INPUT_FILE_PATTERN)" ]
}
_switch_to_branch() {
echo "INPUT_BRANCH value: $INPUT_BRANCH";
# Fetch remote to make sure that repo can be switched to the right branch.
git fetch;
# Switch to branch from current Workflow run
git checkout $INPUT_BRANCH;
git checkout "$INPUT_BRANCH" --;
}
_add_files() {
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
# shellcheck disable=SC2086
git add ${INPUT_FILE_PATTERN};
}
@@ -52,6 +58,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" \
@@ -68,26 +75,33 @@ _tag_commit() {
echo "::debug::Create tag $INPUT_TAGGING_MESSAGE";
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE";
else
echo " No tagging message supplied. No tag will be added.";
echo "No tagging message supplied. No tag will be added.";
fi
}
_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" ]
then
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
if [ -n "$INPUT_TAGGING_MESSAGE" ]
then
echo "::debug::git push origin --tags";
git push origin --tags;
git push origin --tags ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
else
echo "::debug::git push origin";
git push origin;
git push origin ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
fi
else
echo "::debug::Push commit to remote branch $INPUT_BRANCH";
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --tags;
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --tags ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
fi
}

8
package.json Normal file
View File

@@ -0,0 +1,8 @@
{
"devDependencies": {
"bats": "^1.1.0"
},
"scripts": {
"test": "rm -rf tests/tmpstubs && rm -rf tests/shellmock.* && bats tests"
}
}

View File

@@ -0,0 +1,439 @@
#!/usr/bin/env bats
setup() {
. shellmock
# Build World
export test_repository="${BATS_TEST_DIRNAME}/test_repo"
rm -rf "${test_repository}"
mkdir "${test_repository}"
touch "${test_repository}"/{a,b,c}.txt
cd "${test_repository}"
git init --quiet
git add . > /dev/null 2>&1
if [[ -z $(git config user.name) ]]; then
git config --global user.email "test@github.com"
git config --global user.name "Test Suite"
fi
git commit --quiet -m "Init Repo"
# Set default INPUT variables
export INPUT_REPOSITORY="${BATS_TEST_DIRNAME}/test_repo"
export INPUT_COMMIT_MESSAGE="Commit Message"
export INPUT_BRANCH="master"
export INPUT_COMMIT_OPTIONS=""
export INPUT_FILE_PATTERN="."
export INPUT_COMMIT_USER_NAME="Test Suite"
export INPUT_COMMIT_USER_EMAIL="test@github.com"
export INPUT_COMMIT_AUTHOR="Test Suite <test@users.noreply.github.com>"
export INPUT_TAGGING_MESSAGE=""
export INPUT_PUSH_OPTIONS=""
export INPUT_SKIP_DIRTY_CHECK=false
skipIfNot "$BATS_TEST_DESCRIPTION"
if [ -z "$TEST_FUNCTION" ]; then
shellmock_clean
fi
}
teardown() {
if [ -z "$TEST_FUNCTION" ]; then
shellmock_clean
fi
rm -rf "${test_repository}"
}
main() {
bash "${BATS_TEST_DIRNAME}"/../entrypoint.sh
}
@test "clean-repo-prints-nothing-to-commit-message" {
run main
[ "$status" -eq 0 ]
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
[ "${lines[1]}" = "::set-output name=changes_detected::false" ]
[ "${lines[2]}" = "Working tree clean. Nothing to commit." ]
}
@test "commit-changed-files-and-push-to-remote" {
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 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[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
[ "${lines[2]}" = "INPUT_BRANCH value: master" ]
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
[ "${lines[5]}" = "::debug::Apply commit options " ]
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: " ]
[ "${lines[7]}" = "No tagging message supplied. No tag will be added." ]
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
[ "${lines[9]}" = "::debug::Apply push options " ]
[ "${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 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 "skip-dirty-on-clean-repo-failure" {
INPUT_SKIP_DIRTY_CHECK=true
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 "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push origin'
run main
echo "$output"
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${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" ]
# Failed Exit Code
[ "$status" -ne 0 ]
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
[ "${lines[2]}" = "INPUT_BRANCH value: master" ]
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
[ "${lines[5]}" = "::debug::Apply commit options " ]
}
@test "git-add-file-pattern-is-applied" {
INPUT_FILE_PATTERN="*.txt *.html"
touch "${test_repository}"/new-file-{1,2}.php
touch "${test_repository}"/new-file-{1,2}.html
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 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[3]}" = "INPUT_FILE_PATTERN: *.txt *.html" ]
[ "${lines[10]}" = "::debug::Push commit to remote branch master" ]
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[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" ]
}
@test "git-commit-options-are-applied" {
INPUT_COMMIT_OPTIONS="--no-verify --signoff"
touch "${test_repository}"/new-file-{1,2}.txt
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 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[4]}" = "INPUT_COMMIT_OPTIONS: --no-verify --signoff" ]
[ "${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 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" ]
}
@test "commit-user-and-author-settings-are-applied" {
INPUT_COMMIT_USER_NAME="A Single Test"
INPUT_COMMIT_USER_EMAIL="single-test@github.com"
INPUT_COMMIT_AUTHOR="A Single Test <single@users.noreply.github.com>"
touch "${test_repository}"/new-file-{1,2}.txt
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 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 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" ]
}
@test "can-create-tag" {
INPUT_TAGGING_MESSAGE="v1.0.0"
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 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[6]}" = "INPUT_TAGGING_MESSAGE: v1.0.0" ]
[ "${lines[7]}" = "::debug::Create tag v1.0.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 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" ]
[ "${capture[6]}" = "git-stub push --set-upstream origin HEAD:master --tags" ]
}
@test "git-push-options-are-applied" {
INPUT_PUSH_OPTIONS="--force"
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 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[8]}" = "INPUT_PUSH_OPTIONS: --force" ]
[ "${lines[9]}" = "::debug::Apply push options --force" ]
[ "${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 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 "can-checkout-different-branch" {
INPUT_BRANCH="foo"
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 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'
run main
echo "$output"
# Success Exit Code
[ "$status" = 0 ]
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
[ "${lines[2]}" = "INPUT_BRANCH value: foo" ]
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
[ "${lines[5]}" = "::debug::Apply commit options " ]
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: " ]
[ "${lines[7]}" = "No tagging message supplied. No tag will be added." ]
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
[ "${lines[9]}" = "::debug::Apply push options " ]
[ "${lines[10]}" = "::debug::Push commit to remote branch foo" ]
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${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" ]
}
@test "can-work-with-empty-branch-name" {
INPUT_BRANCH=""
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 --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push origin'
run main
echo "$output"
# Success Exit Code
[ "$status" = 0 ]
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
[ "${lines[2]}" = "INPUT_BRANCH value: " ]
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
[ "${lines[5]}" = "::debug::Apply commit options " ]
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: " ]
[ "${lines[7]}" = "No tagging message supplied. No tag will be added." ]
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
[ "${lines[9]}" = "::debug::Apply push options " ]
[ "${lines[10]}" = "::debug::git push origin" ]
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${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" ]
}
@test "can-work-with-empty-branch-name-and-tags" {
INPUT_BRANCH=""
INPUT_TAGGING_MESSAGE="v2.0.0"
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 --"
shellmock_expect git --type partial --match "add ."
shellmock_expect git --type partial --match '-c'
shellmock_expect git --type partial --match 'push origin'
run main
echo "$output"
# Success Exit Code
[ "$status" = 0 ]
[ "${lines[0]}" = "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}" ]
[ "${lines[1]}" = "::set-output name=changes_detected::true" ]
[ "${lines[2]}" = "INPUT_BRANCH value: " ]
[ "${lines[3]}" = "INPUT_FILE_PATTERN: ." ]
[ "${lines[4]}" = "INPUT_COMMIT_OPTIONS: " ]
[ "${lines[5]}" = "::debug::Apply commit options " ]
[ "${lines[6]}" = "INPUT_TAGGING_MESSAGE: v2.0.0" ]
[ "${lines[7]}" = "::debug::Create tag v2.0.0" ]
[ "${lines[8]}" = "INPUT_PUSH_OPTIONS: " ]
[ "${lines[9]}" = "::debug::Apply push options " ]
[ "${lines[10]}" = "::debug::git push origin --tags" ]
shellmock_verify
[ "${capture[0]}" = "git-stub status -s -- ." ]
[ "${capture[1]}" = "git-stub fetch" ]
[ "${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" ]
[ "${capture[6]}" = "git-stub push origin --tags" ]
}

8
yarn.lock Normal file
View File

@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
bats@^1.1.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.2.1.tgz#c15aecc3eb331aedf28678880fab2be0b73eba43"
integrity sha512-2fcPDRQa/Kvh6j1IcCqsHpT5b9ObMzRzw6abC7Bg298PX8Qdh9VRkvO2WJUEhdyfjq2rLBCOAWdcv0tS4+xTUA==