mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-07-31 15:26:10 +08:00
Compare commits
78 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bbd291750d | ||
|
114a5e6044 | ||
|
4a75a2e723 | ||
|
1e826be61c | ||
|
4bab898d25 | ||
|
45872c3c23 | ||
|
9b7c21583c | ||
|
4cc90c7784 | ||
|
367938329d | ||
|
25cac34d8d | ||
|
30cd17bff0 | ||
|
8f5b58c89c | ||
|
65928d2898 | ||
|
6b4ef1444c | ||
|
55291ea168 | ||
|
2b5c86365b | ||
|
ff28943460 | ||
|
e3610414be | ||
|
042c3265d5 | ||
|
90cedba8bc | ||
|
b833fe0e9d | ||
|
653ea719ea | ||
|
47c724214a | ||
|
1ba48c6d7f | ||
|
b9e4cea0ef | ||
|
cfdb7e609e | ||
|
849613a3ad | ||
|
0ee9fb7263 | ||
|
6456430b6b | ||
|
7f67b0b49b | ||
|
8700c3bc1c | ||
|
872d72f1ae | ||
|
f905f00706 | ||
|
9c1e5d1c6a | ||
|
18a94e4f78 | ||
|
44aeb24da7 | ||
|
5c9bfe7477 | ||
|
814219db13 | ||
|
a204abce16 | ||
|
fc18df1417 | ||
|
8f243393e7 | ||
|
fc5b9bf8cf | ||
|
a818c89e49 | ||
|
8bf1b5695a | ||
|
ea30556d53 | ||
|
cd7c7f1a8a | ||
|
4e16840be4 | ||
|
b0295737db | ||
|
0d6d4a4b22 | ||
|
091b400419 | ||
|
f7e362220d | ||
|
df97d6fbd8 | ||
|
4f0fc14d0c | ||
|
cdf7b74cbf | ||
|
862aa0e1e1 | ||
|
a9d1ac4f06 | ||
|
ebf8a401ee | ||
|
4b8393320b | ||
|
60c96d8c0d | ||
|
16d2bf88fd | ||
|
54d78531cc | ||
|
f922a52bf1 | ||
|
0bf17c328a | ||
|
240b9ad1fd | ||
|
57054d8e7e | ||
|
613ea337db | ||
|
686020fb2a | ||
|
90b474f549 | ||
|
8c26230a11 | ||
|
961d68003e | ||
|
cbc3d50cea | ||
|
9e4e2e76fa | ||
|
09aaf2d8fa | ||
|
c7ad0bdb15 | ||
|
9cb711878d | ||
|
b3fc6f8a17 | ||
|
d51384f592 | ||
|
4e7ddef1e0 |
31
.github/workflows/integration-tests.yml
vendored
Normal file
31
.github/workflows/integration-tests.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Integration Tests
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
test-commit-works:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: master
|
||||
|
||||
- name: Create Remote Branch
|
||||
run: |
|
||||
git checkout -b ci-test
|
||||
git push origin ci-test
|
||||
git checkout 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
|
||||
|
||||
- name: Delete Branch
|
||||
run: git push -d origin ci-test
|
19
.github/workflows/linter.yml
vendored
Normal file
19
.github/workflows/linter.yml
vendored
Normal 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 }}
|
12
.github/workflows/shellcheck.yml
vendored
12
.github/workflows/shellcheck.yml
vendored
@@ -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
23
.github/workflows/tests.yml
vendored
Normal 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
|
||||
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
tests/test_repo
|
||||
tests/tmpstubs
|
||||
tests/shellmock.*
|
||||
yarn.lock
|
36
CHANGELOG.md
36
CHANGELOG.md
@@ -4,11 +4,45 @@ 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.5.0...HEAD)
|
||||
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.2...HEAD)
|
||||
|
||||
> TBD
|
||||
|
||||
|
||||
## [v4.7.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.1...v4.7.2) - 2020-10-24
|
||||
|
||||
This release basically reverts the Action to the state of `v4.6.0`.
|
||||
|
||||
### Changed
|
||||
- Revert change to fix git-checkout with special characters in branch names [#122](https://github.com/stefanzweifel/git-auto-commit-action/pull/122)
|
||||
|
||||
|
||||
## [v4.7.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.0...v4.7.1) - 2020-10-22
|
||||
|
||||
### 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-21
|
||||
|
||||
### 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
|
||||
|
44
README.md
44
README.md
@@ -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>".
|
||||
|
||||
@@ -15,7 +22,7 @@ Add the following step at the end of your job, after other steps that might add
|
||||
```yaml
|
||||
- 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
|
||||
@@ -65,7 +72,7 @@ on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
php-cs-fixer:
|
||||
@@ -94,6 +101,18 @@ You can use these outputs to trigger other Actions in your Workflow run based on
|
||||
|
||||
- `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
|
||||
@@ -107,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
|
||||
|
||||
@@ -130,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:
|
||||
@@ -149,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
|
||||
@@ -174,7 +196,7 @@ Here's how the Pull Request will look like:
|
||||

|
||||
|
||||
|
||||
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/).
|
||||
@@ -233,6 +255,14 @@ Note: If you're working in an organisation and you don't want to create the PAT
|
||||
|
||||
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).
|
||||
|
@@ -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
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
set -x
|
||||
|
||||
_main() {
|
||||
_switch_to_repository
|
||||
@@ -30,27 +29,29 @@ _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)" ]
|
||||
}
|
||||
|
||||
_switch_to_branch() {
|
||||
echo "INPUT_BRANCH value: $INPUT_BRANCH";
|
||||
|
||||
if git show-ref --verify --quiet refs/heads/$INPUT_BRANCH; then
|
||||
# Switch to branch from current Workflow run
|
||||
git checkout $INPUT_BRANCH;
|
||||
else
|
||||
git checkout --orphan $INPUT_BRANCH
|
||||
git rm -rf .
|
||||
fi
|
||||
# Fetch remote to make sure that repo can be switched to the right branch.
|
||||
git fetch;
|
||||
|
||||
# Switch to branch from current Workflow run
|
||||
# shellcheck disable=SC2086
|
||||
git checkout $INPUT_BRANCH;
|
||||
}
|
||||
|
||||
_add_files() {
|
||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
git add ${INPUT_FILE_PATTERN};
|
||||
}
|
||||
|
||||
@@ -58,6 +59,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" \
|
||||
@@ -74,7 +76,7 @@ _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
|
||||
}
|
||||
|
||||
@@ -83,6 +85,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" ]
|
||||
|
8
package.json
Normal file
8
package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"bats": "^1.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "rm -rf tests/tmpstubs && rm -rf tests/shellmock.* && bats tests"
|
||||
}
|
||||
}
|
439
tests/git-auto-commit-mocked.bats
Normal file
439
tests/git-auto-commit-mocked.bats
Normal 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
8
yarn.lock
Normal 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==
|
Reference in New Issue
Block a user