Compare commits

...

37 Commits

Author SHA1 Message Date
Stefan Zweifel
0b007fbd11 Let Action fail if git binary can't be located (#261)
* Check if git binary exists

* Add Tests
2022-11-05 11:53:46 +01:00
dependabot[bot]
7106b2184a Bump github/super-linter from 3 to 4 (#258)
Bumps [github/super-linter](https://github.com/github/super-linter) from 3 to 4.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v3...v4)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:05:48 +02:00
dependabot[bot]
f166130208 Bump bats from 1.7.0 to 1.8.2 (#259)
Bumps [bats](https://github.com/bats-core/bats-core) from 1.7.0 to 1.8.2.
- [Release notes](https://github.com/bats-core/bats-core/releases)
- [Changelog](https://github.com/bats-core/bats-core/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bats-core/bats-core/compare/v1.7.0...v1.8.2)

---
updated-dependencies:
- dependency-name: bats
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:04:33 +02:00
dependabot[bot]
021a6363fa Bump actions/checkout from 2 to 3 (#257)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:03:57 +02:00
Stefan Zweifel
38864a638f Create dependabot.yml 2022-10-26 19:02:41 +02:00
stefanzweifel
393fea59ef Update CHANGELOG 2022-10-26 16:57:18 +00:00
Stefan Zweifel
0049e3fa40 Use deprecated set-output syntax if GITHUB_OUTPUT environment is not available (#255)
* Fallback to set-output if GITHUB_OUTPUT not available

* Add Tests to cover old syntax
2022-10-26 18:55:42 +02:00
stefanzweifel
f6f7a9c351 Update CHANGELOG 2022-10-22 09:19:59 +00:00
Andrew Monshizadeh
2fde6fc18d Replace set-output usage with GITHUB_OUTPUT (#252)
* GitHub has deprecated set-output and now needs to add the content to the GITHUB_OUTPUT file

* Update tests too

* Fix tests and shell-format changes

* Revert yarn.lock changes
2022-10-22 10:42:11 +02:00
Stefan Zweifel
faf78595b8 Update README.md 2022-10-21 09:28:08 +02:00
stefanzweifel
a0873a0795 Update CHANGELOG 2022-10-10 17:17:41 +00:00
Stefan Zweifel
fd157da78f Run Action on Node16 (#247)
closes #246
2022-10-10 19:15:24 +02:00
Stefan Zweifel
b208f78c10 Test that CRLF changes are not picked up
This PR adds a test to confirm, that changes to CRLF are not properly detected and that the message "Working tree clean. Nothing to commit." is displayed.

Setting `core.autocrlf` to `true` also has no effect here.

refs #241
2022-09-28 20:19:50 +02:00
stefanzweifel
cef08f2918 Update CHANGELOG 2022-09-24 08:53:51 +00:00
Stefan Zweifel
6c32682a40 Add bug label to new issues 2022-09-17 16:37:41 +02:00
Stefan Zweifel
a4a482b6c5 Update Issue Templates 2022-09-17 16:35:49 +02:00
Stefan Zweifel
18870f2286 Add note about line break detection 2022-09-17 16:02:44 +02:00
Stefan Zweifel
52eb0eedc8 Update README 2022-09-17 15:34:02 +02:00
Karol
03246c1cee Changed the extended example to correctly use quotes for strings (#196)
Co-authored-by: Stefan Zweifel <stefanzweifel@users.noreply.github.com>
2022-09-17 15:33:25 +02:00
Stefan Zweifel
4d00f10668 Expand file_pattern-input to an array (#205)
* Expand file_pattern input

* Expand file pattern array in git-status

* Add Failing Test

* Expand INPUT_FILE_PATTERN

* Fix Shellcheck Issues

* Add test to cover file expansion works when globbing is disabled

* Add explanation to README
2022-09-17 15:18:36 +02:00
Stefan Zweifel
4e7c0d67cd Assert throws error when force adding ignored files
See https://github.com/stefanzweifel/git-auto-commit-action/issues/204#issuecomment-1236880360
2022-09-06 21:04:34 +02:00
Stefan Zweifel
dce7e85096 Add Tests to Cover #233 2022-07-30 20:21:57 +02:00
Stefan Zweifel
9262405709 Fix Typo in Test 2022-07-30 20:14:41 +02:00
Stefan Zweifel
32807d4f18 Upgrade Bats 2022-07-30 20:14:29 +02:00
Derrick Lee
f5b5fefa06 docs: fix typos and grammer errors in readme.md (#235) 2022-07-27 08:23:35 +02:00
Marco
f33e764001 fix typo in readme (#230)
remote was misspelled
2022-07-11 15:25:38 +02:00
Stefan Zweifel
f0d72a04e7 Add note about pathspec error 2022-06-29 20:24:50 +02:00
Stefan Zweifel
571d6b78ed Add test to verify issue #227
This test confirms the problem mentioned in #227.

If `file_pattern` contains a pattern of, for example 2 file extensions, and only files for one extensions are dirty but not for the otherone, `git-add` will throw a fatal error.

It does not throw an error if the files for the pattern already exist but are not dirty.
2022-06-28 20:08:10 +02:00
Stefan Zweifel
f990bd0ed1 Add Note about .gitignore 2022-06-27 20:56:36 +02:00
Eric Cornelissen
789f58e41a Add missing links in the CHANGELOG (#223)
* Update CHANGELOG

Add missing references to Pull Requests.

* Link to PRs and Authors in upcoming release notes

Co-authored-by: Stefan Zweifel <hello@stefanzweifel.io>
2022-06-06 07:36:31 +02:00
Stefan Zweifel
79ae6eea95 Update README concerning pull_request_target trigger
Closes #211
2022-04-15 20:06:11 +02:00
stefanzweifel
488db3d503 Update CHANGELOG 2022-04-12 18:43:36 +00:00
Stefan Zweifel
49620cd3ed Update README.md 2022-04-12 20:33:36 +02:00
Jonas L
73f17337ef Use github-actions[bot] user as commit user (#213)
Fixes #212
2022-04-12 20:30:34 +02:00
Geoff
30fd9f94bc Update README.md (#206) 2022-03-23 08:14:36 +01:00
Stefan Zweifel
d0487b9fa3 Update README.md 2022-03-19 07:46:33 +01:00
stefanzweifel
2719df73cd Update CHANGELOG 2022-03-18 19:29:58 +00:00
17 changed files with 643 additions and 203 deletions

64
.github/ISSUE_TEMPLATE/bug.yaml vendored Normal file
View File

@@ -0,0 +1,64 @@
name: Bug Report
description: If you've already asked for help with a problem and confirmed something is broken with git-auto-commit itself, create a bug report.
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
Before opening a bug report, please search for the behaviour in the existing issues.
---
Thank you for taking the time to file a bug report!
- type: input
id: git-auto-commit-version
attributes:
label: git-auto-commit Version
description: "Which exact version of git-auto-commit are you using in your Workflow?"
placeholder: "v4.14.0"
validations:
required: true
- type: dropdown
id: machine
attributes:
label: Machine Type
description: On which type of machine is your workflow running?
options:
- Ubuntu (eg. ubuntu-latest)
- macOS (eg. macos-latest)
- Windows (Not supported!)
validations:
required: true
- type: textarea
id: bug-description
attributes:
label: Bug description
description: What exactly happened?
validations:
required: true
- type: textarea
id: steps
attributes:
label: Steps to reproduce
description: Which steps do we need to take to reproduce this error?
validations:
required: true
- type: textarea
id: tried-solutions
attributes:
label: Tried solutions
description: Have you tried solving the issue by adapting your Workflow? What steps did you take?
- type: textarea
id: example-workflow
attributes:
label: Example Workflow
description: Please share your GitHub Actions workflow which causes the bug. We use this to reproduce the error. No need for backticks here.
render: yaml
validations:
required: true
- type: textarea
id: logs
attributes:
label: Relevant log output
description: If applicable, provide relevant log output. No need for backticks here.
render: shell

View File

@@ -1,38 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
<!-- Before opening an issue, have you tried solving your problem by explicitly setting the `branch`-value in your workflow? -->
**Version of the Action**
`v4.x.x`
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Used Workflow**
```yaml
# Paste the Workflow you've used here
```
**Additional context**
Add any other context about the problem here.

8
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Get Help
url: https://github.com/stefanzweifel/git-auto-commit-action/discussions/new?category=help
about: If you can't get something to work the way you expect, open a question in our discussion forums.
- name: Feature Request
url: https://github.com/tailwindlabs/tailwindcss/discussions/new?category=ideas
about: 'Suggest any ideas you have using our discussion forums.'

View File

@@ -1,20 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

10
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

View File

@@ -1,7 +1,7 @@
ame-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
change-template: '- $TITLE ([#$NUMBER](https://github.com/stefanzweifel/git-auto-commit-action/pull/$NUMBER)) [@$AUTHOR](https://github.com/@$AUTHOR)'
template: |
# What's Changed
$CHANGES
categories:
- title: Added

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use git-auto-commit-action
id: "auto-commit-action"

View File

@@ -9,10 +9,10 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Lint Code Base
uses: github/super-linter@v3
uses: github/super-linter@v4
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: false

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install testing dependencies
run: yarn install

View File

@@ -10,7 +10,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: master

View File

@@ -5,25 +5,77 @@ 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.13.1...HEAD)
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.3...HEAD)
> TBD
## [v4.15.3](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.2...v4.15.3) - 2022-10-26
### Changed
- Use deprecated set-output syntax if GITHUB_OUTPUT environment is not available ([#255](https://github.com/stefanzweifel/git-auto-commit-action/pull/255)) [@stefanzweifel](https://github.com/@stefanzweifel)
## [v4.15.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.1...v4.15.2) - 2022-10-22
### Changed
- Replace set-output usage with GITHUB_OUTPUT ([#252](https://github.com/stefanzweifel/git-auto-commit-action/pull/252)) [@amonshiz](https://github.com/amonshiz)
## [v4.15.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.0...v4.15.1) - 2022-10-10
### Fixed
- Run Action on Node16 ([#247](https://github.com/stefanzweifel/git-auto-commit-action/pull/247)) [@stefanzweifel](https://github.com/@stefanzweifel)
## [v4.15.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.1...v4.15.0) - 2022-09-24
### Changed
- Expand `file_pattern`-input to an array ([#205](https://github.com/stefanzweifel/git-auto-commit-action/pull/205)) [@stefanzweifel](https://github.com/@stefanzweifel)
### Fixed
- String values in README.md extended example are now correct ([#196](https://github.com/stefanzweifel/git-auto-commit-action/pull/196)) [@karolswdev](https://github.com/@karolswdev)
- Fix Typos and grammer Errors in README ([#235](https://github.com/stefanzweifel/git-auto-commit-action/pull/235)) [@derrickleemy](https://github.com/@derrickleemy)
- Fix Typo in README ([#230](https://github.com/stefanzweifel/git-auto-commit-action/pull/230)) [@fty4](https://github.com/@fty4)
- Add missing links in the CHANGELOG ([#223](https://github.com/stefanzweifel/git-auto-commit-action/pull/223)) [@ericcornelissen](https://github.com/@ericcornelissen)
## [v4.14.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.0...v4.14.1) - 2022-04-12
## Changed
- Change Commit User Name from "GitHub Actions" to "github-actions[bot]" ([#213](https://github.com/stefanzweifel/git-auto-commit-action/pull/213)) @jooola
- Change Commit User Email from "actions@github.com" to "github-actions[bot]@users.noreply.github.com" ([#213](https://github.com/stefanzweifel/git-auto-commit-action/pull/213)) @jooola
## Fixed
- Update doc link to GITHUB_TOKEN not triggering new workflow runs ([#206](https://github.com/stefanzweifel/git-auto-commit-action/pull/206)) @gapple
## [v4.14.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...v4.14.0) - 2022-03-18
## Added
- Add `create_branch` option to force create a new branch ([#203](https://github.com/stefanzweifel/git-auto-commit-action/pull/203)) @stefanzweifel
## Fixed
- README.md: Updates hyperlink to GH docs ([#200](https://github.com/stefanzweifel/git-auto-commit-action/pull/200)) @funkyfuture
## [v4.13.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...v4.13.1) - 2022-01-13
## Fixed
- Properly disambiguate between branch or file checkout (#199) @kenodegard
- Properly disambiguate between branch or file checkout ([#199](https://github.com/stefanzweifel/git-auto-commit-action/pull/199)) @kenodegard
## [v4.13.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...v4.13.0) - 2022-01-10
## Added
- Add `skip_checkout` option (#197) @cmbuckley
- Add `skip_checkout` option ([#197](https://github.com/stefanzweifel/git-auto-commit-action/pull/197)) @cmbuckley
## Changed
- Add note on minimum permissions to the docs (#180) @ericcornelissen
- Add note on minimum permissions to the docs ([#180](https://github.com/stefanzweifel/git-auto-commit-action/pull/180)) @ericcornelissen
## [v4.12.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...v4.12.0) - 2021-09-10

106
README.md
View File

@@ -2,7 +2,6 @@
> 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>
@@ -20,10 +19,10 @@ Add the following step at the end of your job, after other steps that might add
- uses: stefanzweifel/git-auto-commit-action@v4
```
Note that the Action has to be used in a Job that runs on a UNIX system (eg. `ubuntu-latest`).
Note that the Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`).
If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the `contents: write` permission.
The following is an extended example with all possible options available for this Action.
The following is an extended example with all available options.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
@@ -46,19 +45,19 @@ The following is an extended example with all possible options available for thi
# 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
file_pattern: '*.php src/*.js tests/*.js'
# 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 # defaults to "GitHub Actions"
commit_user_email: my-github-actions-bot@example.org # defaults to "actions@github.com"
commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]"
commit_user_email: my-github-actions-bot@example.org # defaults to "github-actions[bot]@users.noreply.github.com"
commit_author: Author <actions@github.com> # defaults to author of the commit that triggered the run
# Optional. Tag name being created in the local repository and
# pushed to remtoe repository and defined branch.
# pushed to remote repository and defined branch.
tagging_message: 'v1.0.0'
# Optional. Option used by `git-status` to determine if the repository is
@@ -87,7 +86,6 @@ The following is an extended example with all possible options available for thi
disable_globbing: true
# Optional. Create given branch name in local and remote repository.
# (Not released yet, available when @master is used)
create_branch: true
```
@@ -151,16 +149,18 @@ You can use these outputs to trigger other Actions in your Workflow run based on
## Limitations & Gotchas
The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore you might run into issues if your Workflow falls into the not supported 20% portion.
The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore, you might run into issues if your Workflow falls into the not supported 20% portion.
The following is a list of edge cases the Action knowingly does not support:
**No `git pull` when the repository is out of the date with remote.** The Action will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs.
**No `git pull` when the repository is out of date with remote.** The Action will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs.
**No support for running the Action in build matrices**. If your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a `git pull` for you, you have to do that yourself.
**No support for `git rebase` or `git merge`**. There are many strategies on how to integrate remote upstream changes to a local repository. `git-auto-commit` does not want to be responsible for doing that.
**No support for detecting line break changes between CR (Carriage Return) and LF (Line Feed)**. This is a low level issue, you have to resolve differently in your project. Sorry.
If this Action doesn't work for your workflow, check out [EndBug/add-and-commit](https://github.com/EndBug/add-and-commit).
### Checkout the correct branch
@@ -179,7 +179,7 @@ Do this to avoid checking out the repository in a detached state.
### 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 [limitations set by GitHub](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#triggering-a-workflow-from-a-workflow).
This is due to [limitations set by GitHub](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow).
> 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,6 +196,10 @@ If you create a personal access token, apply the `repo` and `workflow` scopes.
If you work in an organization and don't want to create a PAT from your personal account, we recommend using a [robot account](https://docs.github.com/en/github/getting-started-with-github/types-of-github-accounts) for the token.
### Change to file is not detected
Does your workflow change a file but "git-auto-commit" does not detect the change? Check the `.gitignore` that applies to the respective file. You might have accidentally marked the file to be ignored by git.
## Advanced Uses
<details>
@@ -206,9 +210,45 @@ If you use this Action in combination with a linter/fixer, it's easier if you ru
---
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.)
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.)
However, there are a couple of ways to use this Actions in Workflows that should be triggered by forked repositories.
If you want that a Workflow using this Action runs on Pull Requests opened by forks, 2 things have to be changed:
### Workflow should run in **base** repository
The workflow below runs whenever a commit is pushed to the `main`-branch or when activity on a pull request happens, by listening to the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event.
If the workflow is triggered by the `pull_request_target`-event, the workflow will run in the context of the base of the pull request, rather than in the context of the merge commit, as the `pull_request` event does.
In other words, this will allow your workflow to be run in the repository where the pull request is opened to and will push changes back to the fork.
Check out the discussion in [#211](https://github.com/stefanzweifel/git-auto-commit-action/issues/211) for more information on this.
```yaml
name: Format PHP
on:
push:
branches:
- main
pull_request_target:
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
```
### Workflow should run in **forked** repository
If the workflow should run in the forked repository, follow these steps:
1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target).
2. GitHub Action has to be enabled on the forked repository. \
@@ -241,7 +281,7 @@ jobs:
commit_message: Apply php-cs-fixer changes
```
Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the the forked repository and will push commits to the same branch.
Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the **forked** repository and will push commits to the same branch.
Here's how the Pull Request will look like:
@@ -269,7 +309,7 @@ See [this announcement from GitHub](https://github.blog/2020-08-03-github-action
Signing Commits & Other Git Command Line Options
</summary>
Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regulary.
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 regularly.
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
@@ -305,7 +345,7 @@ The steps in your workflow might look like this:
- name: Get last commit message
id: last-commit-message
run: |
echo "::set-output name=msg::$(git log -1 --pretty=%s)"
echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
- uses: stefanzweifel/git-auto-commit-action@v4
with:
@@ -333,7 +373,7 @@ 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 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.
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 Access Token needs to belong to an Administrator.
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.
@@ -345,7 +385,7 @@ 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.
@@ -361,6 +401,34 @@ If you go the "force pushes" route, you have to enable force pushes to a protect
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).
### Pathspec 'x' did not match any files
If you're using the Action with a custom `file_pattern` and the Action throws a fatal error with the message "Pathspec 'file-pattern' did not match any files", the problem is probably that no file for the pattern exists in the repository.
`file_pattern` is used both for `git-status` and `git-add` in this Action. `git-add` will throw a fatal error, if for example, you use a file pattern like `*.js *.ts` but no `*.ts` files exist in your projects' repository.
See [Issue #227](https://github.com/stefanzweifel/git-auto-commit-action/issues/227) for details.
### Custom `file_pattern`, changed files but seeing "Working tree clean. Nothing to commit." in the logs
If you're using a custom `file_pattern` and the Action does not detect the changes made in your worfklow, you're probably running into a globbing issue.
Let's imagine you use `file_pattern: '*.md'` to detect and commit changes to all Markdown files in your repository.
If your Workflow now only updates `.md`-files in a subdirectory, but you have an untouched `.md`-file in the root of the repository, the git-auto-commit Action will display "Working tree clean. Nothing to commit." in the Workflow log.
This is due to the fact, that the `*.md`-glob is expanded before sending it to `git-status`. `git-status` will receive the filename of your untouched `.md`-file in the root of the repository and won't detect any changes; and therefore the Action does nothing.
To fix this add `disable_globbing: true` to your Workflow.
```yaml
- uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: '*.md'
disable_globbing: true
```
See [Issue #239](https://github.com/stefanzweifel/git-auto-commit-action/issues/239) for details.
## Running the tests
The Action 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`.
@@ -381,7 +449,7 @@ yarn test
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags).
We also provide major version tags to make it easier to always use the latest release of a major version. For example you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version.
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

View File

@@ -35,11 +35,11 @@ inputs:
commit_user_name:
description: Name used for the commit user
required: false
default: GitHub Actions
default: github-actions[bot]
commit_user_email:
description: Email address used for the commit user
required: false
default: actions@github.com
default: github-actions[bot]@users.noreply.github.com
commit_author:
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
required: false
@@ -70,6 +70,9 @@ inputs:
create_branch:
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
default: false
internal_git_binary:
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
default: git
outputs:
changes_detected:
@@ -78,7 +81,7 @@ outputs:
description: Full hash of the created commit. Only present if the "changes_detected" output is "true".
runs:
using: 'node12'
using: 'node16'
main: 'index.js'
branding:

View File

@@ -7,11 +7,19 @@ if "$INPUT_DISABLE_GLOBBING"; then
fi
_main() {
_check_if_git_is_available
_switch_to_repository
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
echo "::set-output name=changes_detected::true";
# Check if $GITHUB_OUTPUT is available
# (Feature detection will be removed in late December 2022)
if [ -z ${GITHUB_OUTPUT+x} ]; then
echo "::set-output name=changes_detected::true";
else
echo "changes_detected=true" >> $GITHUB_OUTPUT;
fi
_switch_to_branch
@@ -24,12 +32,26 @@ _main() {
_push_to_github
else
echo "::set-output name=changes_detected::false";
# Check if $GITHUB_OUTPUT is available
# (Feature detection will be removed in late December 2022)
if [ -z ${GITHUB_OUTPUT+x} ]; then
echo "::set-output name=changes_detected::false";
else
echo "changes_detected=false" >> $GITHUB_OUTPUT;
fi
echo "Working tree clean. Nothing to commit.";
fi
}
_check_if_git_is_available() {
if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then
echo "::debug::git binary found.";
else
echo "::error ::git-auto-commit could not find git binary. Please make sure git is available."
exit 1;
fi
}
_switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
@@ -40,8 +62,11 @@ _git_is_dirty() {
echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}";
echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}";
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN";
# shellcheck disable=SC2086
[ -n "$(git status -s $INPUT_STATUS_OPTIONS -- $INPUT_FILE_PATTERN)" ]
[ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ]
}
_switch_to_branch() {
@@ -75,9 +100,10 @@ _add_files() {
echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}";
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN";
# shellcheck disable=SC2086
git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN};
git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN:+"${INPUT_FILE_PATTERN_EXPANDED[@]}"};
}
_local_commit() {
@@ -97,7 +123,14 @@ _local_commit() {
--author="$INPUT_COMMIT_AUTHOR" \
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};
echo "::set-output name=commit_hash::$(git rev-parse HEAD)";
# Check if $GITHUB_OUTPUT is available
# (Feature detection will be removed in late December 2022)
if [ -z ${GITHUB_OUTPUT+x} ]; then
echo "::set-output name=commit_hash::$(git rev-parse HEAD)";
else
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT;
fi
}
_tag_commit() {

View File

@@ -1,6 +1,6 @@
{
"devDependencies": {
"bats": "^1.1.0",
"bats": "^1.8.2",
"bats-assert": "ztombol/bats-assert",
"bats-support": "ztombol/bats-support"
},

View File

@@ -9,10 +9,20 @@ setup() {
export FAKE_REMOTE="${BATS_TEST_DIRNAME}/tests_remote_repository"
export FAKE_TEMP_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/tests_clone_of_remote_repository"
# While it is likely the GitHub hosted runners will use master as the default branch,
# locally anyone may change that. So for tests lets grab whatever is currently set
# globally. This should also ensure that changes to the GitHub hosted runners'
# config do not break tests in the future.
if [[ -z $(git config init.defaultBranch) ]]; then
git config --global init.defaultBranch "main"
fi
export FAKE_DEFAULT_BRANCH=$(git config init.defaultBranch)
# 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_BRANCH="${FAKE_DEFAULT_BRANCH}"
export INPUT_COMMIT_OPTIONS=""
export INPUT_ADD_OPTIONS=""
export INPUT_STATUS_OPTIONS=""
@@ -27,6 +37,11 @@ setup() {
export INPUT_SKIP_CHECKOUT=false
export INPUT_DISABLE_GLOBBING=false
export INPUT_CREATE_BRANCH=false
export INPUT_INTERNAL_GIT_BINARY=git
# Set GitHub environment variables used by the GitHub Action
temp_github_output_file=$(mktemp -t github_output_test.XXXXX)
export GITHUB_OUTPUT="${temp_github_output_file}"
# Configure Git
if [[ -z $(git config user.name) ]]; then
@@ -43,15 +58,21 @@ teardown() {
rm -rf "${FAKE_LOCAL_REPOSITORY}"
rm -rf "${FAKE_REMOTE}"
rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}"
if [ -z ${GITHUB_OUTPUT+x} ]; then
echo "GITHUB_OUTPUT is not set"
else
rm "${GITHUB_OUTPUT}"
fi
}
# 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;
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}"
@@ -59,10 +80,10 @@ _setup_fake_remote_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;
cd "${FAKE_TEMP_LOCAL_REPOSITORY}"
git add .
git commit --quiet -m "Init Remote Repository"
git push origin "${FAKE_DEFAULT_BRANCH}"
}
# Clone our fake remote repository and set it up for testing
@@ -71,7 +92,7 @@ _setup_local_repository() {
rm -rf "${FAKE_LOCAL_REPOSITORY}"
git clone "${FAKE_REMOTE}" "${FAKE_LOCAL_REPOSITORY}"
cd "${FAKE_LOCAL_REPOSITORY}";
cd "${FAKE_LOCAL_REPOSITORY}"
}
# Run the main code related to this GitHub Action
@@ -79,6 +100,12 @@ git_auto_commit() {
bash "${BATS_TEST_DIRNAME}"/../entrypoint.sh
}
cat_github_output() {
# Be sure to dump anything we spit out to the environment file is
# also available for asserting
cat "${GITHUB_OUTPUT}"
}
@test "It detects changes, commits them and pushes them to the remote repository" {
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
@@ -87,9 +114,7 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_BRANCH value: ${FAKE_DEFAULT_BRANCH}"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
assert_line "::debug::Apply commit options "
@@ -97,7 +122,11 @@ git_auto_commit() {
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"
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
run cat_github_output
assert_line "changes_detected=true"
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "It detects when files have been deleted, commits changes and pushes them to the remote repository" {
@@ -108,9 +137,7 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_BRANCH value: ${FAKE_DEFAULT_BRANCH}"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
assert_line "::debug::Apply commit options "
@@ -118,7 +145,11 @@ git_auto_commit() {
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"
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
run cat_github_output
assert_line "changes_detected=true"
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "It applies INPUT_STATUS_OPTIONS when running dirty check" {
@@ -131,9 +162,11 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "Working tree clean. Nothing to commit."
run cat_github_output
assert_line "changes_detected=false"
refute_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "It prints a 'Nothing to commit' message in a clean repository" {
@@ -142,9 +175,11 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "Working tree clean. Nothing to commit."
run cat_github_output
assert_line "changes_detected=false"
refute_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "If SKIP_DIRTY_CHECK is set to true on a clean repo it fails to push" {
@@ -155,20 +190,21 @@ git_auto_commit() {
assert_failure
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_BRANCH value: ${FAKE_DEFAULT_BRANCH}"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
assert_line "::debug::Apply commit options "
run cat_github_output
assert_line "changes_detected=true"
refute_line -e "commit_hash=[0-9a-f]{40}$"
}
@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
date >"${FAKE_LOCAL_REPOSITORY}"/remote-files1.txt
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
run git_auto_commit
@@ -177,8 +213,7 @@ git_auto_commit() {
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_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
# Assert that PHP files have not been added.
run git status
@@ -188,8 +223,8 @@ git_auto_commit() {
@test "It applies INPUT_FILE_PATTERN when creating commit" {
INPUT_FILE_PATTERN="src/*.js *.txt *.html"
mkdir src;
touch src/new-file-{1,2}.js;
mkdir src
touch src/new-file-{1,2}.js
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.php
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2}.html
@@ -199,7 +234,7 @@ git_auto_commit() {
assert_success
assert_line "INPUT_FILE_PATTERN: src/*.js *.txt *.html"
assert_line "::debug::Push commit to remote branch master"
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
# Assert that PHP files have not been added.
run git status
@@ -216,7 +251,7 @@ git_auto_commit() {
assert_success
assert_line "INPUT_COMMIT_OPTIONS: --no-verify --signoff"
assert_line "::debug::Push commit to remote branch master"
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
# Assert last commit was signed off
run git log -n 1
@@ -234,10 +269,10 @@ 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"
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 ${FAKE_DEFAULT_BRANCH}"
# Asser last commit was made by the defined user/author
run git log -1 --pretty=format:'%ae'
@@ -264,7 +299,7 @@ git_auto_commit() {
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_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
# Assert a tag v1.0.0 has been created
run git tag
@@ -275,8 +310,8 @@ git_auto_commit() {
# 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)"
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
assert_equal $current_sha $remote_sha
}
@@ -284,11 +319,10 @@ git_auto_commit() {
@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;
cd "${FAKE_TEMP_LOCAL_REPOSITORY}"
git add .
git commit --quiet -m "Add more remote files"
git push origin ${FAKE_DEFAULT_BRANCH}
INPUT_PUSH_OPTIONS="--force"
@@ -300,20 +334,20 @@ git_auto_commit() {
assert_line "INPUT_PUSH_OPTIONS: --force"
assert_line "::debug::Apply push options --force"
assert_line "::debug::Push commit to remote branch master"
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
# 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)"
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
assert_equal $current_sha $remote_sha
}
@test "It can checkout a different branch" {
# Create foo-branch and then immediately switch back to master
# Create foo-branch and then immediately switch back to ${FAKE_DEFAULT_BRANCH}
git checkout -b foo
git checkout master
git checkout ${FAKE_DEFAULT_BRANCH}
INPUT_BRANCH="foo"
@@ -343,9 +377,9 @@ git_auto_commit() {
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 that branch "${FAKE_DEFAULT_BRANCH}" was updated on remote
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
assert_equal $current_sha $remote_sha
}
@@ -421,17 +455,17 @@ git_auto_commit() {
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 that branch "${FAKE_DEFAULT_BRANCH}" was updated on remote
current_sha="$(git rev-parse --verify --short ${FAKE_DEFAULT_BRANCH})"
remote_sha="$(git rev-parse --verify --short origin/${FAKE_DEFAULT_BRANCH})"
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
# Create "a-new-branch"-branch and then immediately switch back to ${FAKE_DEFAULT_BRANCH}
git checkout -b a-new-branch
git checkout master
git checkout ${FAKE_DEFAULT_BRANCH}
INPUT_BRANCH="a-new-branch"
INPUT_TAGGING_MESSAGE="v2.0.0"
@@ -464,20 +498,20 @@ git_auto_commit() {
@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";
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;
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 ${FAKE_DEFAULT_BRANCH} >/dev/null
# Make nested file dirty
echo "foo-bar" > "${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py;
echo "foo-bar" >"${FAKE_LOCAL_REPOSITORY}"/nested/new-file-b.py
# ---
@@ -489,7 +523,7 @@ git_auto_commit() {
assert_success
assert_line "INPUT_FILE_PATTERN: *.py"
assert_line "::debug::Push commit to remote branch master"
assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}"
# Assert that the updated py file has been commited.
run git status
@@ -506,22 +540,24 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::false"
run git status
assert_output --partial 'nothing to commit, working tree clean'
run cat_github_output
assert_line "changes_detected=false"
}
@test "It does not throw an error if branch is checked out with same name as a file or folder in the repo" {
# Add File called dev and commit/push
echo "Create dev file";
cd "${FAKE_LOCAL_REPOSITORY}";
echo this is a file named dev > dev
echo "Create dev file"
cd "${FAKE_LOCAL_REPOSITORY}"
echo this is a file named dev >dev
git add dev
git commit -m 'add file named dev'
git update-ref refs/remotes/origin/master master
git update-ref refs/remotes/origin/dev master
git update-ref refs/remotes/origin/${FAKE_DEFAULT_BRANCH} ${FAKE_DEFAULT_BRANCH}
git update-ref refs/remotes/origin/dev ${FAKE_DEFAULT_BRANCH}
# ---
@@ -534,8 +570,10 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line "::debug::Push commit to remote branch dev"
run cat_github_output
assert_line "changes_detected=true"
}
@test "script fails to push commit to new branch that does not exist yet" {
@@ -555,7 +593,6 @@ git_auto_commit() {
assert_failure
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line "INPUT_BRANCH value: not-existend-branch"
assert_line "fatal: invalid reference: not-existend-branch"
@@ -564,6 +601,9 @@ git_auto_commit() {
run git branch -r
refute_line --partial "origin/not-existend-branch"
run cat_github_output
assert_line "changes_detected=true"
}
@test "It creates new local branch and pushes the new branch to remote" {
@@ -583,8 +623,6 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: not-existend-branch"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
@@ -600,12 +638,16 @@ git_auto_commit() {
run git branch -r
assert_line --partial "origin/not-existend-branch"
run cat_github_output
assert_line "changes_detected=true"
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "it does not create new local branch if local branch already exists" {
git checkout -b not-existend-remote-branch
git checkout master
git checkout ${FAKE_DEFAULT_BRANCH}
INPUT_BRANCH="not-existend-remote-branch"
INPUT_CREATE_BRANCH=true
@@ -623,8 +665,6 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: not-existend-remote-branch"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
@@ -640,24 +680,28 @@ git_auto_commit() {
run git branch -r
assert_line --partial "origin/not-existend-remote-branch"
run cat_github_output
assert_line "changes_detected=true"
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "it creates new local branch and pushes branch to remote even if the remote branch already exists" {
# Create `existing-remote-branch` on remote with changes the local repository does not yet have
cd $FAKE_TEMP_LOCAL_REPOSITORY;
cd $FAKE_TEMP_LOCAL_REPOSITORY
git checkout -b "existing-remote-branch"
touch new-branch-file.txt
git add new-branch-file.txt
git commit -m "Add additional file";
git push origin existing-remote-branch;
git commit -m "Add additional file"
git push origin existing-remote-branch
run git branch;
run git branch
assert_line --partial "existing-remote-branch"
# ---------
# Switch to our regular local repository and run `git-auto-commit`
cd $FAKE_LOCAL_REPOSITORY;
cd $FAKE_LOCAL_REPOSITORY
INPUT_BRANCH="existing-remote-branch"
INPUT_CREATE_BRANCH=true
@@ -665,9 +709,9 @@ git_auto_commit() {
run git branch
refute_line --partial "existing-remote-branch"
run git fetch --all;
run git pull origin existing-remote-branch;
run git branch -r;
run git fetch --all
run git pull origin existing-remote-branch
run git branch -r
assert_line --partial "origin/existing-remote-branch"
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
@@ -677,8 +721,6 @@ git_auto_commit() {
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
assert_line "INPUT_BRANCH value: existing-remote-branch"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
@@ -699,24 +741,28 @@ git_auto_commit() {
current_sha="$(git rev-parse --verify --short existing-remote-branch)"
remote_sha="$(git rev-parse --verify --short origin/existing-remote-branch)"
assert_equal $current_sha $remote_sha;
assert_equal $current_sha $remote_sha
run cat_github_output
assert_line "changes_detected=true"
assert_line -e "commit_hash=[0-9a-f]{40}$"
}
@test "script fails if new local branch is checked out and push fails as remote has newer commits than local" {
# Create `existing-remote-branch` on remote with changes the local repository does not yet have
cd $FAKE_TEMP_LOCAL_REPOSITORY;
cd $FAKE_TEMP_LOCAL_REPOSITORY
git checkout -b "existing-remote-branch"
touch new-branch-file.txt
git add new-branch-file.txt
git commit -m "Add additional file";
git push origin existing-remote-branch;
git commit -m "Add additional file"
git push origin existing-remote-branch
run git branch;
run git branch
assert_line --partial "existing-remote-branch"
# ---------
# Switch to our regular local repository and run `git-auto-commit`
cd $FAKE_LOCAL_REPOSITORY;
cd $FAKE_LOCAL_REPOSITORY
INPUT_BRANCH="existing-remote-branch"
INPUT_CREATE_BRANCH=true
@@ -724,8 +770,8 @@ git_auto_commit() {
run git branch
refute_line --partial "existing-remote-branch"
run git fetch --all;
run git branch -r;
run git fetch --all
run git branch -r
assert_line --partial "origin/existing-remote-branch"
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
@@ -747,26 +793,26 @@ git_auto_commit() {
current_sha="$(git rev-parse --verify --short existing-remote-branch)"
remote_sha="$(git rev-parse --verify --short origin/existing-remote-branch)"
refute [assert_equal $current_sha $remote_sha];
refute [assert_equal $current_sha $remote_sha]
}
@test "It pushes commit to remote if branch already exists and local repo is behind its remote counterpart" {
# Create `new-branch` on remote with changes the local repository does not yet have
cd $FAKE_TEMP_LOCAL_REPOSITORY;
cd $FAKE_TEMP_LOCAL_REPOSITORY
git checkout -b "new-branch"
touch new-branch-file.txt
git add new-branch-file.txt
git commit --quiet -m "Add additional file";
git push origin new-branch;
git commit --quiet -m "Add additional file"
git push origin new-branch
run git branch -r
assert_line --partial "origin/new-branch"
# ---------
# Switch to our regular local repository and run `git-auto-commit`
cd $FAKE_LOCAL_REPOSITORY;
cd $FAKE_LOCAL_REPOSITORY
INPUT_BRANCH="new-branch"
@@ -791,5 +837,219 @@ git_auto_commit() {
current_sha="$(git rev-parse --verify --short new-branch)"
remote_sha="$(git rev-parse --verify --short origin/new-branch)"
assert_equal $current_sha $remote_sha;
assert_equal $current_sha $remote_sha
}
@test "throws fatal error if file pattern includes files that do not exist" {
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo
INPUT_FILE_PATTERN="*.foo *.bar"
run git_auto_commit
assert_failure
assert_line --partial "fatal: pathspec '*.bar' did not match any files"
}
@test "does not throw fatal error if files for file pattern exist but only one is dirty" {
# Add some .foo and .bar files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.bar
INPUT_FILE_PATTERN="*.foo *.bar"
run git_auto_commit
# Add more .foo files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{4,5,6}.foo
INPUT_FILE_PATTERN="*.foo *.bar"
run git_auto_commit
assert_success
}
@test "detects and commits changed files based on pattern in root and subfolders" {
# Add some .neon files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.neon
mkdir foo
touch "${FAKE_LOCAL_REPOSITORY}"/foo/new-file-2.neon
INPUT_FILE_PATTERN="**/*.neon *.neon"
run git_auto_commit
assert_success
assert_line --partial "new-file-1.neon"
assert_line --partial "foo/new-file-2.neon"
}
@test "throws error if tries to force add ignored files which do not have any changes" {
# Create 2 files which will later will be added to .gitignore
touch "${FAKE_LOCAL_REPOSITORY}"/ignored-file.txt
touch "${FAKE_LOCAL_REPOSITORY}"/another-ignored-file.txt
# Commit the 2 new files
run git_auto_commit
# Add our txt files to gitignore
echo "ignored-file.txt" >>"${FAKE_LOCAL_REPOSITORY}"/.gitignore
echo "another-ignored-file.txt" >>"${FAKE_LOCAL_REPOSITORY}"/.gitignore
# Commit & push .gitignore changes
run git_auto_commit
# Sanity check that txt files are ignored
run cat "${FAKE_LOCAL_REPOSITORY}"/.gitignore
assert_output --partial "ignored-file.txt"
assert_output --partial "another-ignored-file.txt"
# Configure git-auto-commit
INPUT_SKIP_DIRTY_CHECK=true
INPUT_ADD_OPTIONS="-f"
INPUT_FILE_PATTERN="ignored-file.txt another-ignored-file.txt"
# Run git-auto-commit with special configuration
run git_auto_commit
assert_output --partial "nothing to commit, working tree clean"
assert_failure
}
@test "expands file patterns correctly and commits all changed files" {
# Add more .txt files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.txt
mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/
touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar
INPUT_FILE_PATTERN="*.txt *.bar"
run git_auto_commit
assert_success
assert_line --partial "new-file-1.txt"
assert_line --partial "subdirectory/new-file-2.txt"
assert_line --partial "new-file-3.bar"
}
@test "expands file patterns correctly and commits all changed files when globbing is disabled" {
# Add more .txt files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.txt
mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/
touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar
INPUT_FILE_PATTERN="*.txt *.bar"
INPUT_DISABLE_GLOBBING=true
run git_auto_commit
assert_success
assert_line --partial "new-file-1.txt"
assert_line --partial "subdirectory/new-file-2.txt"
assert_line --partial "new-file-3.bar"
}
@test "expands file patterns correctly and commits all changed files if dirty files are only in subdirectory" {
# Add more .txt files
mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/
touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt
mkdir "${FAKE_LOCAL_REPOSITORY}"/another-subdirectory/
touch "${FAKE_LOCAL_REPOSITORY}"/another-subdirectory/new-file-3.txt
INPUT_FILE_PATTERN="*.txt"
INPUT_DISABLE_GLOBBING=true
run git_auto_commit
assert_success
assert_line --partial "subdirectory/new-file-2.txt"
assert_line --partial "another-subdirectory/new-file-3.txt"
}
@test "fails to detect crlf change in files and does not detect change or commit changes" {
# Set autocrlf to true
cd "${FAKE_LOCAL_REPOSITORY}"
git config core.autocrlf true
run git config --get-all core.autocrlf
assert_line "true"
# Add more .txt files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to add new files to repository
run git_auto_commit
# Change control characters in files
sed 's/^M$//' "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
sed 's/$/^M/' "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to commit the 2 changes files
run git_auto_commit
assert_success
# Changes are not detected
assert_line --partial "Working tree clean. Nothing to commit."
refute_line --partial "new-file-2.txt"
refute_line --partial "new-file-3.txt"
}
@test "It uses old set-output syntax if GITHUB_OUTPUT environment is not available when changes are committed" {
unset GITHUB_OUTPUT
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 "INPUT_BRANCH value: ${FAKE_DEFAULT_BRANCH}"
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 ${FAKE_DEFAULT_BRANCH}"
assert_line "::set-output name=changes_detected::true"
assert_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
}
@test "It uses old set-output syntax if GITHUB_OUTPUT environment is not available when no changes have been detected" {
unset GITHUB_OUTPUT
run git_auto_commit
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "Working tree clean. Nothing to commit."
assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
}
@test "It fails hard if git is not available" {
INPUT_INTERNAL_GIT_BINARY=binary-does-not-exist
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
run git_auto_commit
assert_failure;
assert_line "::error ::git-auto-commit could not find git binary. Please make sure git is available."
}

View File

@@ -10,7 +10,7 @@ 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"
integrity sha512-2fcPDRQa/Kvh6j1IcCqsHpT5b9ObMzRzw6abC7Bg298PX8Qdh9VRkvO2WJUEhdyfjq2rLBCOAWdcv0tS4+xTUA==
bats@^1.8.2:
version "1.8.2"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.8.2.tgz#bdbaa7690a18f04291b35144a8ce5435cffb8dc5"
integrity sha512-KLUIaPYuIMjqui8MbZmK84+CiwhjFVFAhFy5PXP0prLbkovc5faVzc+Qaowbz76F97zP573JrF31ODFAH7vzhg==