mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-07-31 15:26:10 +08:00
Compare commits
57 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
5dd17c3b53 | ||
|
ebbf8e517a | ||
|
76f1ae2f1a | ||
|
b9c536534c | ||
|
68f0d95687 | ||
|
ccad85927e | ||
|
48d37c1ffb | ||
|
4c05e3d58e | ||
|
3053f48bdd | ||
|
cfd366418e | ||
|
be370eccae | ||
|
f4f9aedbee | ||
|
e610a5104b | ||
|
be7095c202 | ||
|
ae9ae1b5b8 | ||
|
e944668910 | ||
|
9bb0fd2324 | ||
|
175c2cd836 | ||
|
296e083b4c | ||
|
871ade1c45 | ||
|
75625df4f3 | ||
|
3870982ac5 | ||
|
268ec0c240 | ||
|
9abc4c41e5 | ||
|
1aee6e6b46 | ||
|
94941cff88 | ||
|
7507738fca | ||
|
53438d58ce | ||
|
8056699617 | ||
|
520c63c171 | ||
|
a6006229e0 | ||
|
40b55695d1 | ||
|
8f33b6cc31 | ||
|
c4ab3ecb7e | ||
|
350754fe3a | ||
|
75802d269e | ||
|
5b85132a3c | ||
|
292ae30da6 | ||
|
b53a2f8baf | ||
|
a9021d5359 | ||
|
fafea853e8 | ||
|
6576a06e26 | ||
|
b104287145 | ||
|
b8b8026fe4 | ||
|
fae0e424e9 | ||
|
a1604ef1d5 | ||
|
152b8c00c6 | ||
|
8edcd8b718 | ||
|
8f9132651a | ||
|
6c72ab7799 | ||
|
983b799941 | ||
|
bee2ad60b0 | ||
|
ac4585b8d5 | ||
|
4e7742676e | ||
|
2e61cc5f41 | ||
|
021e855056 | ||
|
7cec9acee6 |
31
.github/workflows/integration-tests.yml
vendored
31
.github/workflows/integration-tests.yml
vendored
@@ -1,31 +0,0 @@
|
||||
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
|
8
.github/workflows/tests.yml
vendored
8
.github/workflows/tests.yml
vendored
@@ -9,13 +9,7 @@ jobs:
|
||||
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
|
||||
- name: Install testing dependencies
|
||||
run: yarn install
|
||||
|
||||
- name: Run Tests
|
||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
tests/test_repo
|
||||
tests/tmpstubs
|
||||
tests/shellmock.*
|
||||
tests/test_fake_local_repository
|
||||
tests/test_fake_remote_repository
|
||||
tests/test_fake_temp_local_repository
|
||||
yarn.lock
|
||||
|
41
CHANGELOG.md
41
CHANGELOG.md
@@ -4,11 +4,50 @@ 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.7.2...HEAD)
|
||||
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...HEAD)
|
||||
|
||||
> TBD
|
||||
|
||||
|
||||
## [v4.11.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.10.0...v4.11.0) - 2021-05-03
|
||||
|
||||
### Added
|
||||
- Add `status_options` and `add_options` option [#156](https://github.com/stefanzweifel/git-auto-commit-action/pull/156)
|
||||
|
||||
|
||||
## [v4.10.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.9.2...v4.10.0) - 2021-04-12
|
||||
|
||||
### Added
|
||||
- Add `disable_globbing` option [#153](https://github.com/stefanzweifel/git-auto-commit-action/issues/153), [#154](https://github.com/stefanzweifel/git-auto-commit-action/pull/154)
|
||||
|
||||
|
||||
## [v4.9.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.9.1...v4.9.2) - 2021-03-04
|
||||
|
||||
### Fixes
|
||||
- Push created annotated tags to remote by using `--follow-tags` and `--atomic` instead of just `--tags` [#146](https://github.com/stefanzweifel/git-auto-commit-action/pull/146)
|
||||
|
||||
|
||||
## [v4.9.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.9.0...v4.9.1) - 2021-02-23
|
||||
|
||||
### Changed
|
||||
- Revert changes made in v4.9.0. A branch will no longer be automatically generated. [#144](https://github.com/stefanzweifel/git-auto-commit-action/pull/144)
|
||||
|
||||
|
||||
## [v4.9.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.8.0...v4.9.0) - 2021-02-20
|
||||
|
||||
### Changed
|
||||
- Automatically create branch if a branch with the given name does not exist [#140](https://github.com/stefanzweifel/git-auto-commit-action/pull/140)
|
||||
|
||||
|
||||
## [v4.8.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.2...v4.8.0) - 2020-12-15
|
||||
|
||||
### Added
|
||||
- Add `skip_fetch` option to skip the execution of `git-fetch` [#131](https://github.com/stefanzweifel/git-auto-commit-action/pull/131)
|
||||
|
||||
### Changed
|
||||
- Update `git fetch` to only fetch the latest commit from remote [#131](https://github.com/stefanzweifel/git-auto-commit-action/pull/131)
|
||||
|
||||
|
||||
## [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`.
|
||||
|
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Stefan Zweifel
|
||||
Copyright (c) 2021 Stefan Zweifel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
115
README.md
115
README.md
@@ -2,18 +2,15 @@
|
||||
|
||||
> The GitHub Action for committing files for the 80% use case.
|
||||
|
||||
<a href="https://github.com/search?o=desc&q=stefanzweifel%2Fgit-auto-commit-action+path%3A.github%2Fworkflows+language%3AYAML&s=&type=Code" target="_blank" title="Public workflows that use this action."><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fapi-git-master.endbug.vercel.app%2Fapi%2Fgithub-actions%2Fused-by%3Faction%3Dstefanzweifel%2Fgit-auto-commit-action%26badge%3Dtrue" alt="Public workflows that use this action."></a>
|
||||
<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>".
|
||||
A GitHub Action to detect changed files during a Workflow run and to commit and push them back to the GitHub repository.
|
||||
By default, the commit is made in the name of "GitHub Actions" and co-authored by the user that made the last commit.
|
||||
|
||||
This Action has been inspired and adapted from the [auto-commit](https://github.com/cds-snc/github-actions/tree/master/auto-commit
|
||||
)-Action of the Canadian Digital Service and this [commit](https://github.com/elstudio/actions-js-build/blob/41d604d6e73d632e22eac40df8cc69b5added04b/commit/entrypoint.sh)-Action by Eric Johnson.
|
||||
If you want to learn more how this Action works under the hood, check out [this article](https://michaelheap.com/git-auto-commit/) by Michael Heap.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -21,44 +18,69 @@ 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:
|
||||
# Optional but recommended, defaults to "Apply automatic changes"
|
||||
commit_message: Apply automatic changes
|
||||
```
|
||||
|
||||
# Optional branch to push to, defaults to the current branch
|
||||
The following is an extended example with all possible options available for this Action.
|
||||
|
||||
```yaml
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
# Optional, but recommended
|
||||
# Defaults to "Apply automatic changes"
|
||||
commit_message: Automated Change
|
||||
|
||||
# Optional branch name where commit should be pushed to.
|
||||
# Defaults to the current branch.
|
||||
branch: feature-123
|
||||
|
||||
# Optional options appended to `git-commit`
|
||||
# See https://git-scm.com/docs/git-commit for a list of available options
|
||||
# Optional. Used by `git-commit`.
|
||||
# See https://git-scm.com/docs/git-commit#_options
|
||||
commit_options: '--no-verify --signoff'
|
||||
|
||||
# Optional glob pattern of files which should be added to the commit
|
||||
# Defaults to all (.)
|
||||
# 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
|
||||
# Defaults to the root of the repository
|
||||
repository: .
|
||||
|
||||
# Optional commit user and author settings
|
||||
commit_user_name: My GitHub Actions Bot
|
||||
commit_user_email: my-github-actions-bot@example.org
|
||||
commit_author: Author <actions@github.com>
|
||||
commit_user_name: My GitHub Actions Bot # defaults to "GitHub Actions"
|
||||
commit_user_email: my-github-actions-bot@example.org # defaults to "actions@github.com"
|
||||
commit_author: Author <actions@github.com> # defaults to author of the commit that triggered the run
|
||||
|
||||
# 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
|
||||
# Optional. Used by `git-status`
|
||||
# See https://git-scm.com/docs/git-status#_options
|
||||
status_options: '--untracked-files=no'
|
||||
|
||||
# Optional. Used by `git-add`
|
||||
# See https://git-scm.com/docs/git-add#_options
|
||||
add_options: '-u'
|
||||
|
||||
# Optional. Used by `git-push`
|
||||
# See 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
|
||||
# Optional. Disable dirty check and always try to create a commit and push
|
||||
skip_dirty_check: true
|
||||
|
||||
# Optional. Skip internal call to `git fetch`
|
||||
skip_fetch: true
|
||||
|
||||
# Optional. Prevents the shell from expanding filenames.
|
||||
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
|
||||
disable_globbing: true
|
||||
```
|
||||
|
||||
## Example
|
||||
## Example Workflow
|
||||
|
||||
In this example, we're running `php-cs-fixer` in a PHP project to fix the codestyle automatically, then commit possible changed files back to the repository.
|
||||
|
||||
@@ -128,10 +150,10 @@ In non-`push` events, such as `pull_request`, make sure to specify the `ref` to
|
||||
|
||||
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
|
||||
### Commits made by this Action do not trigger new Workflow runs
|
||||
|
||||
The resulting commit **will not trigger** another GitHub Actions Workflow run.
|
||||
This is due to [limititations set by GitHub](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).
|
||||
This is due to [limitations set by GitHub](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).
|
||||
|
||||
> 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.
|
||||
|
||||
@@ -196,7 +218,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 run linters and fixers (like the example above) we recommend running them when a push happens on the `main`-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/).
|
||||
@@ -209,7 +231,7 @@ See [this announcement from GitHub](https://github.blog/2020-08-03-github-action
|
||||
|
||||
### 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
|
||||
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))
|
||||
|
||||
@@ -228,18 +250,9 @@ 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.
|
||||
If your repository uses [protected branches](https://help.github.com/en/github/administering-a-repository/configuring-protected-branches) you have to make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Acess Token needs to belong to an Administrator.
|
||||
|
||||
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),
|
||||
First, 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
|
||||
@@ -249,7 +262,17 @@ store the token as a secret in your repository and pass the new token to the [`a
|
||||
```
|
||||
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.
|
||||
**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.
|
||||
|
||||
|
||||
If you go the "force pushes" route, 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
|
||||
```
|
||||
|
||||
### No new workflows are triggered by the commit of this action
|
||||
|
||||
@@ -257,10 +280,18 @@ This is due to limitations set up by GitHub, [commits of this Action do not trig
|
||||
|
||||
## 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.
|
||||
The package has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`.
|
||||
|
||||
```shell
|
||||
npm install
|
||||
yarn
|
||||
```
|
||||
|
||||
You can run the test suite with `npm` or `yarn`.
|
||||
|
||||
```shell
|
||||
npm run test
|
||||
yarn test
|
||||
```
|
||||
|
||||
## Versioning
|
||||
@@ -270,6 +301,14 @@ We use [SemVer](http://semver.org/) for versioning. For the versions available,
|
||||
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).)
|
||||
|
||||
## Credits
|
||||
|
||||
* [Stefan Zweifel](https://github.com/stefanzweifel)
|
||||
* [All Contributors](https://github.com/stefanzweifel/git-auto-commit-action/graphs/contributors)
|
||||
|
||||
This Action has been inspired and adapted from the [auto-commit](https://github.com/cds-snc/github-actions/tree/master/auto-commit
|
||||
)-Action of the Canadian Digital Service and this [commit](https://github.com/elstudio/actions-js-build/blob/41d604d6e73d632e22eac40df8cc69b5added04b/commit/entrypoint.sh)-Action by Eric Johnson.
|
||||
|
||||
## 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.
|
||||
|
15
action.yml
15
action.yml
@@ -16,6 +16,14 @@ inputs:
|
||||
description: Commit options (eg. --no-verify)
|
||||
required: false
|
||||
default: ''
|
||||
add_options:
|
||||
description: Add options (eg. -u)
|
||||
required: false
|
||||
default: ''
|
||||
status_options:
|
||||
description: Status options (eg. --untracked-files=no)
|
||||
required: false
|
||||
default: ''
|
||||
file_pattern:
|
||||
description: File pattern used for `git add`. For example `src/\*.js`
|
||||
required: false
|
||||
@@ -48,6 +56,13 @@ inputs:
|
||||
description: Skip the check if the git repository is dirty and always try to create a commit.
|
||||
required: false
|
||||
default: false
|
||||
skip_fetch:
|
||||
description: Skip the call to git-fetch.
|
||||
required: false
|
||||
default: false
|
||||
disable_globbing:
|
||||
description: Stop the shell from expanding filenames (https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html)
|
||||
default: false
|
||||
|
||||
outputs:
|
||||
changes_detected:
|
||||
|
@@ -2,6 +2,10 @@
|
||||
|
||||
set -eu
|
||||
|
||||
if "$INPUT_DISABLE_GLOBBING"; then
|
||||
set -o noglob;
|
||||
fi
|
||||
|
||||
_main() {
|
||||
_switch_to_repository
|
||||
|
||||
@@ -33,15 +37,23 @@ _switch_to_repository() {
|
||||
}
|
||||
|
||||
_git_is_dirty() {
|
||||
echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}";
|
||||
echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}";
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
[ -n "$(git status -s -- $INPUT_FILE_PATTERN)" ]
|
||||
[ -n "$(git status -s $INPUT_STATUS_OPTIONS -- $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;
|
||||
|
||||
if "$INPUT_SKIP_FETCH"; then
|
||||
echo "::debug::git-fetch has not been executed";
|
||||
else
|
||||
git fetch --depth=1;
|
||||
fi
|
||||
|
||||
# Switch to branch from current Workflow run
|
||||
# shellcheck disable=SC2086
|
||||
@@ -49,10 +61,13 @@ _switch_to_branch() {
|
||||
}
|
||||
|
||||
_add_files() {
|
||||
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
|
||||
echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}";
|
||||
|
||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
git add ${INPUT_FILE_PATTERN};
|
||||
git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN};
|
||||
}
|
||||
|
||||
_local_commit() {
|
||||
@@ -62,6 +77,11 @@ _local_commit() {
|
||||
# shellcheck disable=SC2206
|
||||
INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS );
|
||||
|
||||
echo "INPUT_COMMIT_USER_NAME: ${INPUT_COMMIT_USER_NAME}";
|
||||
echo "INPUT_COMMIT_USER_EMAIL: ${INPUT_COMMIT_USER_EMAIL}";
|
||||
echo "INPUT_COMMIT_MESSAGE: ${INPUT_COMMIT_MESSAGE}";
|
||||
echo "INPUT_COMMIT_AUTHOR: ${INPUT_COMMIT_AUTHOR}";
|
||||
|
||||
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" \
|
||||
commit -m "$INPUT_COMMIT_MESSAGE" \
|
||||
--author="$INPUT_COMMIT_AUTHOR" \
|
||||
@@ -94,7 +114,7 @@ _push_to_github() {
|
||||
if [ -n "$INPUT_TAGGING_MESSAGE" ]
|
||||
then
|
||||
echo "::debug::git push origin --tags";
|
||||
git push origin --tags ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
else
|
||||
echo "::debug::git push origin";
|
||||
git push origin ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
@@ -102,7 +122,7 @@ _push_to_github() {
|
||||
|
||||
else
|
||||
echo "::debug::Push commit to remote branch $INPUT_BRANCH";
|
||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --tags ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
fi
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"bats": "^1.1.0"
|
||||
"bats": "^1.1.0",
|
||||
"bats-assert": "ztombol/bats-assert",
|
||||
"bats-support": "ztombol/bats-support"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "rm -rf tests/tmpstubs && rm -rf tests/shellmock.* && bats tests"
|
||||
"test": "bats tests"
|
||||
}
|
||||
}
|
||||
|
@@ -1,439 +0,0 @@
|
||||
#!/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" ]
|
||||
|
||||
}
|
476
tests/git-auto-commit.bats
Normal file
476
tests/git-auto-commit.bats
Normal file
@@ -0,0 +1,476 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load '../node_modules/bats-support/load'
|
||||
load '../node_modules/bats-assert/load'
|
||||
|
||||
setup() {
|
||||
# Define Paths for local repository used during tests
|
||||
export FAKE_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/tests_local_repository"
|
||||
export FAKE_REMOTE="${BATS_TEST_DIRNAME}/tests_remote_repository"
|
||||
export FAKE_TEMP_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/tests_clone_of_remote_repository"
|
||||
|
||||
# Set default INPUT variables used by the GitHub Action
|
||||
export INPUT_REPOSITORY="${FAKE_LOCAL_REPOSITORY}"
|
||||
export INPUT_COMMIT_MESSAGE="Commit Message"
|
||||
export INPUT_BRANCH="master"
|
||||
export INPUT_COMMIT_OPTIONS=""
|
||||
export INPUT_ADD_OPTIONS=""
|
||||
export INPUT_STATUS_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
|
||||
export INPUT_SKIP_FETCH=false
|
||||
export INPUT_DISABLE_GLOBBING=false
|
||||
|
||||
# Configure Git
|
||||
if [[ -z $(git config user.name) ]]; then
|
||||
git config --global user.name "Test Suite"
|
||||
git config --global user.email "test@github.com"
|
||||
fi
|
||||
|
||||
# Create and setup some fake repositories for testing
|
||||
_setup_fake_remote_repository
|
||||
_setup_local_repository
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf "${FAKE_LOCAL_REPOSITORY}"
|
||||
rm -rf "${FAKE_REMOTE}"
|
||||
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
|
||||
}
|
||||
|
||||
# Create a fake remote repository which tests can push against
|
||||
_setup_fake_remote_repository() {
|
||||
# Create the bare repository, which will act as our remote/origin
|
||||
rm -rf "${FAKE_REMOTE}";
|
||||
mkdir "${FAKE_REMOTE}";
|
||||
cd "${FAKE_REMOTE}";
|
||||
git init --bare;
|
||||
|
||||
# Clone the remote repository to a temporary location.
|
||||
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
|
||||
git clone "${FAKE_REMOTE}" "${FAKE_TEMP_LOCAL_REPOSITORY}"
|
||||
|
||||
# Create some files, commit them and push them to the remote repository
|
||||
touch "${FAKE_TEMP_LOCAL_REPOSITORY}"/remote-files{1,2,3}.txt
|
||||
cd "${FAKE_TEMP_LOCAL_REPOSITORY}";
|
||||
git add .;
|
||||
git commit --quiet -m "Init Remote Repository";
|
||||
git push origin master;
|
||||
}
|
||||
|
||||
# Clone our fake remote repository and set it up for testing
|
||||
_setup_local_repository() {
|
||||
# Clone remote repository. In this repository we will do our testing
|
||||
rm -rf "${FAKE_LOCAL_REPOSITORY}"
|
||||
git clone "${FAKE_REMOTE}" "${FAKE_LOCAL_REPOSITORY}"
|
||||
|
||||
cd "${FAKE_LOCAL_REPOSITORY}";
|
||||
}
|
||||
|
||||
# Run the main code related to this GitHub Action
|
||||
git_auto_commit() {
|
||||
bash "${BATS_TEST_DIRNAME}"/../entrypoint.sh
|
||||
}
|
||||
|
||||
@test "It detects changes, commits them and pushes them to the remote repository" {
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||
assert_line "::set-output name=changes_detected::true"
|
||||
assert_line "INPUT_BRANCH value: master"
|
||||
assert_line "INPUT_FILE_PATTERN: ."
|
||||
assert_line "INPUT_COMMIT_OPTIONS: "
|
||||
assert_line "::debug::Apply commit options "
|
||||
assert_line "INPUT_TAGGING_MESSAGE: "
|
||||
assert_line "No tagging message supplied. No tag will be added."
|
||||
assert_line "INPUT_PUSH_OPTIONS: "
|
||||
assert_line "::debug::Apply push options "
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
}
|
||||
|
||||
@test "It detects when files have been deleted, commits changes and pushes them to the remote repository" {
|
||||
rm -rf "${FAKE_LOCAL_REPOSITORY}"/remote-files1.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||
assert_line "::set-output name=changes_detected::true"
|
||||
assert_line "INPUT_BRANCH value: master"
|
||||
assert_line "INPUT_FILE_PATTERN: ."
|
||||
assert_line "INPUT_COMMIT_OPTIONS: "
|
||||
assert_line "::debug::Apply commit options "
|
||||
assert_line "INPUT_TAGGING_MESSAGE: "
|
||||
assert_line "No tagging message supplied. No tag will be added."
|
||||
assert_line "INPUT_PUSH_OPTIONS: "
|
||||
assert_line "::debug::Apply push options "
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
}
|
||||
|
||||
@test "It applies INPUT_STATUS_OPTIONS when running dirty check" {
|
||||
INPUT_STATUS_OPTIONS="--untracked-files=no"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||
assert_line "::set-output name=changes_detected::false"
|
||||
assert_line "Working tree clean. Nothing to commit."
|
||||
}
|
||||
|
||||
@test "It prints a 'Nothing to commit' message in a clean repository" {
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||
assert_line "::set-output name=changes_detected::false"
|
||||
assert_line "Working tree clean. Nothing to commit."
|
||||
}
|
||||
|
||||
@test "If SKIP_DIRTY_CHECK is set to true on a clean repo it fails to push" {
|
||||
INPUT_SKIP_DIRTY_CHECK=true
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_failure
|
||||
|
||||
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
|
||||
assert_line "::set-output name=changes_detected::true"
|
||||
|
||||
assert_line "::set-output name=changes_detected::true"
|
||||
assert_line "INPUT_BRANCH value: master"
|
||||
assert_line "INPUT_FILE_PATTERN: ."
|
||||
assert_line "INPUT_COMMIT_OPTIONS: "
|
||||
assert_line "::debug::Apply commit options "
|
||||
}
|
||||
|
||||
@test "It applies INPUT_ADD_OPTIONS when adding files" {
|
||||
INPUT_FILE_PATTERN=""
|
||||
INPUT_STATUS_OPTIONS="--untracked-files=no"
|
||||
INPUT_ADD_OPTIONS="-u"
|
||||
|
||||
date > "${FAKE_LOCAL_REPOSITORY}"/remote-files1.txt
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_STATUS_OPTIONS: --untracked-files=no"
|
||||
assert_line "INPUT_ADD_OPTIONS: -u"
|
||||
assert_line "INPUT_FILE_PATTERN: "
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
|
||||
# Assert that PHP files have not been added.
|
||||
run git status
|
||||
assert_output --partial 'new-file-1.php'
|
||||
}
|
||||
|
||||
@test "It applies INPUT_FILE_PATTERN when creating commit" {
|
||||
INPUT_FILE_PATTERN="*.txt *.html"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.html
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_FILE_PATTERN: *.txt *.html"
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
|
||||
# Assert that PHP files have not been added.
|
||||
run git status
|
||||
assert_output --partial 'new-file-1.php'
|
||||
}
|
||||
|
||||
@test "It applies INPUT_COMMIT_OPTIONS when creating commit" {
|
||||
INPUT_COMMIT_OPTIONS="--no-verify --signoff"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_COMMIT_OPTIONS: --no-verify --signoff"
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
|
||||
# Assert last commit was signed off
|
||||
run git log -n 1
|
||||
assert_output --partial "Signed-off-by:"
|
||||
}
|
||||
|
||||
@test "It applies commit user and author settings" {
|
||||
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 "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_COMMIT_USER_NAME: A Single Test";
|
||||
assert_line "INPUT_COMMIT_USER_EMAIL: single-test@github.com";
|
||||
assert_line "INPUT_COMMIT_AUTHOR: A Single Test <single@users.noreply.github.com>";
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
|
||||
# Asser last commit was made by the defined user/author
|
||||
run git log -1 --pretty=format:'%ae'
|
||||
assert_output --partial "single@users.noreply.github.com"
|
||||
|
||||
run git log -1 --pretty=format:'%an'
|
||||
assert_output --partial "A Single Test"
|
||||
|
||||
run git log -1 --pretty=format:'%cn'
|
||||
assert_output --partial "A Single Test"
|
||||
|
||||
run git log -1 --pretty=format:'%ce'
|
||||
assert_output --partial "single-test@github.com"
|
||||
}
|
||||
|
||||
@test "It creates a tag with the commit" {
|
||||
INPUT_TAGGING_MESSAGE="v1.0.0"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_TAGGING_MESSAGE: v1.0.0"
|
||||
assert_line "::debug::Create tag v1.0.0"
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
|
||||
# Assert a tag v1.0.0 has been created
|
||||
run git tag
|
||||
assert_output v1.0.0
|
||||
|
||||
run git ls-remote --tags --refs
|
||||
assert_output --partial refs/tags/v1.0.0
|
||||
|
||||
# Assert that the commit has been pushed with --force and
|
||||
# sha values are equal on local and remote
|
||||
current_sha="$(git rev-parse --verify --short master)"
|
||||
remote_sha="$(git rev-parse --verify --short origin/master)"
|
||||
|
||||
assert_equal $current_sha $remote_sha
|
||||
}
|
||||
|
||||
@test "It applies INPUT_PUSH_OPTIONS when pushing commit to remote" {
|
||||
|
||||
touch "${FAKE_TEMP_LOCAL_REPOSITORY}"/newer-remote-files{1,2,3}.txt
|
||||
cd "${FAKE_TEMP_LOCAL_REPOSITORY}";
|
||||
git add .;
|
||||
git commit --quiet -m "Add more remote files";
|
||||
git push origin master;
|
||||
|
||||
|
||||
INPUT_PUSH_OPTIONS="--force"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_PUSH_OPTIONS: --force"
|
||||
assert_line "::debug::Apply push options --force"
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
|
||||
# Assert that the commit has been pushed with --force and
|
||||
# sha values are equal on local and remote
|
||||
current_sha="$(git rev-parse --verify --short master)"
|
||||
remote_sha="$(git rev-parse --verify --short origin/master)"
|
||||
|
||||
assert_equal $current_sha $remote_sha
|
||||
}
|
||||
|
||||
@test "It can checkout a different branch" {
|
||||
# Create foo-branch and then immediately switch back to master
|
||||
git checkout -b foo
|
||||
git checkout master
|
||||
|
||||
INPUT_BRANCH="foo"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_BRANCH value: foo"
|
||||
assert_line "::debug::Push commit to remote branch foo"
|
||||
|
||||
# Assert a new branch "foo" exists on remote
|
||||
run git ls-remote --heads
|
||||
assert_output --partial refs/heads/foo
|
||||
}
|
||||
|
||||
@test "It uses existing branch name when pushing when INPUT_BRANCH is empty" {
|
||||
INPUT_BRANCH=""
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_BRANCH value: "
|
||||
assert_line --partial "::debug::git push origin"
|
||||
|
||||
# Assert that branch "master" was updated on remote
|
||||
current_sha="$(git rev-parse --verify --short master)"
|
||||
remote_sha="$(git rev-parse --verify --short origin/master)"
|
||||
|
||||
assert_equal $current_sha $remote_sha
|
||||
}
|
||||
|
||||
@test "It uses existing branch when INPUT_BRANCH is empty and INPUT_TAGGING_MESSAGE is set" {
|
||||
INPUT_BRANCH=""
|
||||
INPUT_TAGGING_MESSAGE="v2.0.0"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_TAGGING_MESSAGE: v2.0.0"
|
||||
assert_line "::debug::Create tag v2.0.0"
|
||||
assert_line "::debug::git push origin --tags"
|
||||
|
||||
# Assert a tag v2.0.0 has been created
|
||||
run git tag
|
||||
assert_output v2.0.0
|
||||
|
||||
# Assert tag v2.0.0 has been pushed to remote
|
||||
run git ls-remote --tags --refs
|
||||
assert_output --partial refs/tags/v2.0.0
|
||||
}
|
||||
|
||||
@test "If SKIP_FETCH is true git-fetch will not be called" {
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
INPUT_SKIP_FETCH=true
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "::debug::git-fetch has not been executed"
|
||||
}
|
||||
|
||||
@test "It pushes generated commit and tag to remote and actually updates the commit shas" {
|
||||
INPUT_BRANCH=""
|
||||
INPUT_TAGGING_MESSAGE="v2.0.0"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_TAGGING_MESSAGE: v2.0.0"
|
||||
assert_line "::debug::Create tag v2.0.0"
|
||||
assert_line "::debug::git push origin --tags"
|
||||
|
||||
# Assert a tag v2.0.0 has been created
|
||||
run git tag
|
||||
assert_output v2.0.0
|
||||
|
||||
# Assert tag v2.0.0 has been pushed to remote
|
||||
run git ls-remote --tags --refs
|
||||
assert_output --partial refs/tags/v2.0.0
|
||||
|
||||
# Assert that branch "master" was updated on remote
|
||||
current_sha="$(git rev-parse --verify --short master)"
|
||||
remote_sha="$(git rev-parse --verify --short origin/master)"
|
||||
|
||||
assert_equal $current_sha $remote_sha
|
||||
}
|
||||
|
||||
@test "It pushes generated commit and tag to remote branch and updates commit sha" {
|
||||
# Create "a-new-branch"-branch and then immediately switch back to master
|
||||
git checkout -b a-new-branch
|
||||
git checkout master
|
||||
|
||||
INPUT_BRANCH="a-new-branch"
|
||||
INPUT_TAGGING_MESSAGE="v2.0.0"
|
||||
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_TAGGING_MESSAGE: v2.0.0"
|
||||
assert_line "::debug::Create tag v2.0.0"
|
||||
assert_line "::debug::Push commit to remote branch a-new-branch"
|
||||
|
||||
# Assert a tag v2.0.0 has been created
|
||||
run git tag
|
||||
assert_output v2.0.0
|
||||
|
||||
# Assert tag v2.0.0 has been pushed to remote
|
||||
run git ls-remote --tags --refs
|
||||
assert_output --partial refs/tags/v2.0.0
|
||||
|
||||
# Assert that branch "a-new-branch" was updated on remote
|
||||
current_sha="$(git rev-parse --verify --short a-new-branch)"
|
||||
remote_sha="$(git rev-parse --verify --short origin/a-new-branch)"
|
||||
|
||||
assert_equal $current_sha $remote_sha
|
||||
}
|
||||
|
||||
@test "It does not expand wildcard glob when using INPUT_PATTERN and INPUT_DISABLE_GLOBBING in git-status and git-add" {
|
||||
|
||||
# Create additional files in a nested directory structure
|
||||
echo "Create Additional files";
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-a.py
|
||||
mkdir "${FAKE_LOCAL_REPOSITORY}"/nested
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py
|
||||
|
||||
# Commit changes
|
||||
echo "Commit changes before running git_auto_commit";
|
||||
cd "${FAKE_LOCAL_REPOSITORY}";
|
||||
git add . > /dev/null;
|
||||
git commit --quiet -m "Init Remote Repository";
|
||||
git push origin master > /dev/null;
|
||||
|
||||
# Make nested file dirty
|
||||
echo "foo-bar" > "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py;
|
||||
|
||||
# ---
|
||||
|
||||
INPUT_FILE_PATTERN="*.py"
|
||||
INPUT_DISABLE_GLOBBING=true
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_FILE_PATTERN: *.py"
|
||||
assert_line "::debug::Push commit to remote branch master"
|
||||
|
||||
# Assert that the updated py file has been commited.
|
||||
run git status
|
||||
refute_output --partial 'nested/new-file-b.py'
|
||||
}
|
@@ -2,6 +2,14 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
bats-assert@ztombol/bats-assert:
|
||||
version "0.3.0"
|
||||
resolved "https://codeload.github.com/ztombol/bats-assert/tar.gz/9f88b4207da750093baabc4e3f41bf68f0dd3630"
|
||||
|
||||
bats-support@ztombol/bats-support:
|
||||
version "0.3.0"
|
||||
resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee"
|
||||
|
||||
bats@^1.1.0:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/bats/-/bats-1.2.1.tgz#c15aecc3eb331aedf28678880fab2be0b73eba43"
|
||||
|
Reference in New Issue
Block a user