mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-08-02 00:16:10 +08:00
Compare commits
40 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8756aa072e | ||
|
17a44b07bf | ||
|
43818d5044 | ||
|
10944650cd | ||
|
3d1b5e078a | ||
|
47a8ad5f38 | ||
|
77a7b3fb3c | ||
|
9cc0a1f55d | ||
|
0b5f8a5333 | ||
|
3a446b74f0 | ||
|
8e108d701f | ||
|
c8254de74f | ||
|
6436584fbb | ||
|
6656e54255 | ||
|
f0b35f0a73 | ||
|
ccd4d054a5 | ||
|
94d6bf9d22 | ||
|
f44d1cd002 | ||
|
92b3981e0b | ||
|
3b94e3d017 | ||
|
3663a6fa3e | ||
|
fe00d25867 | ||
|
86fb2e11b2 | ||
|
aeb1802648 | ||
|
925bbcaef3 | ||
|
3ea6ae190b | ||
|
976f22029f | ||
|
ebb5756042 | ||
|
3dce995a13 | ||
|
0b007fbd11 | ||
|
7106b2184a | ||
|
f166130208 | ||
|
021a6363fa | ||
|
38864a638f | ||
|
393fea59ef | ||
|
0049e3fa40 | ||
|
f6f7a9c351 | ||
|
2fde6fc18d | ||
|
faf78595b8 | ||
|
a0873a0795 |
10
.github/dependabot.yml
vendored
Normal file
10
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
2
.github/release-drafter.yml
vendored
2
.github/release-drafter.yml
vendored
@@ -12,7 +12,7 @@ categories:
|
||||
- 'changelog:changed'
|
||||
- title: Deprecated
|
||||
labels:
|
||||
- 'changelog:deprecated '
|
||||
- 'changelog:deprecated'
|
||||
- title: Removed
|
||||
labels:
|
||||
- 'changelog:removed'
|
||||
|
11
.github/workflows/git-auto-commit.yml
vendored
11
.github/workflows/git-auto-commit.yml
vendored
@@ -10,17 +10,22 @@ jobs:
|
||||
git-auto-commit:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
# Give the default GITHUB_TOKEN write permission.
|
||||
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Use git-auto-commit-action
|
||||
id: "auto-commit-action"
|
||||
uses: ./
|
||||
|
||||
- name: "no changes detected"
|
||||
if: steps.auto-commit-action.outputs.changes_detected == false
|
||||
if: steps.auto-commit-action.outputs.changes_detected == 'false'
|
||||
run: "echo \"No changes detected\""
|
||||
|
||||
- name: "changes detected"
|
||||
if: steps.auto-commit-action.outputs.changes_detected == true
|
||||
if: steps.auto-commit-action.outputs.changes_detected == 'true'
|
||||
run: "echo \"Changes detected\""
|
||||
|
4
.github/workflows/linter.yml
vendored
4
.github/workflows/linter.yml
vendored
@@ -9,10 +9,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Lint Code Base
|
||||
uses: github/super-linter@v3
|
||||
uses: github/super-linter@v5
|
||||
env:
|
||||
VALIDATE_ALL_CODEBASE: false
|
||||
VALIDATE_MARKDOWN: false
|
||||
|
6
.github/workflows/release-drafter.yml
vendored
6
.github/workflows/release-drafter.yml
vendored
@@ -8,6 +8,12 @@ on:
|
||||
jobs:
|
||||
update_release_draft:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
# Give the default GITHUB_TOKEN write permission.
|
||||
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: release-drafter/release-drafter@v5
|
||||
env:
|
||||
|
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install testing dependencies
|
||||
run: yarn install
|
||||
|
8
.github/workflows/update-changelog.yaml
vendored
8
.github/workflows/update-changelog.yaml
vendored
@@ -8,9 +8,15 @@ jobs:
|
||||
update:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
# Give the default GITHUB_TOKEN write permission to commit and push the
|
||||
# updated CHANGELOG back to the repository.
|
||||
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
|
||||
|
6
.github/workflows/versioning.yml
vendored
6
.github/workflows/versioning.yml
vendored
@@ -7,6 +7,12 @@ on:
|
||||
jobs:
|
||||
actions-tagger:
|
||||
runs-on: windows-latest
|
||||
|
||||
permissions:
|
||||
# Give the default GITHUB_TOKEN write permission.
|
||||
# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: Actions-R-Us/actions-tagger@latest
|
||||
env:
|
||||
|
43
CHANGELOG.md
43
CHANGELOG.md
@@ -5,10 +5,51 @@ 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.15.0...HEAD)
|
||||
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.16.0...HEAD)
|
||||
|
||||
> TBD
|
||||
|
||||
## [v4.16.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.4...v4.16.0) - 2022-12-02
|
||||
|
||||
### Changed
|
||||
|
||||
- Don't commit files when only LF/CRLF changes ([#265](https://github.com/stefanzweifel/git-auto-commit-action/pull/265)) [@ZeroRin](https://github.com/@ZeroRin)
|
||||
- Update default email address of github-actions[bot] ([#264](https://github.com/stefanzweifel/git-auto-commit-action/pull/264)) [@Teko012](https://github.com/@Teko012)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix link and text for workflow limitation ([#263](https://github.com/stefanzweifel/git-auto-commit-action/pull/263)) [@Teko012](https://github.com/@Teko012)
|
||||
|
||||
## [v4.15.4](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.3...v4.15.4) - 2022-11-05
|
||||
|
||||
### Fixed
|
||||
|
||||
- Let Action fail if git binary can't be located ([#261](https://github.com/stefanzweifel/git-auto-commit-action/pull/261)) [@stefanzweifel](https://github.com/@stefanzweifel)
|
||||
|
||||
### Dependency Updates
|
||||
|
||||
- Bump github/super-linter from 3 to 4 ([#258](https://github.com/stefanzweifel/git-auto-commit-action/pull/258)) [@dependabot](https://github.com/@dependabot)
|
||||
- Bump bats from 1.7.0 to 1.8.2 ([#259](https://github.com/stefanzweifel/git-auto-commit-action/pull/259)) [@dependabot](https://github.com/@dependabot)
|
||||
- Bump actions/checkout from 2 to 3 ([#257](https://github.com/stefanzweifel/git-auto-commit-action/pull/257)) [@dependabot](https://github.com/@dependabot)
|
||||
|
||||
## [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
|
||||
|
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at hello@stefanzweifel.io. All
|
||||
reported by contacting the project team at stefan@stefanzweifel.dev. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
|
166
README.md
166
README.md
@@ -13,14 +13,42 @@ If you want to learn more how this Action works under the hood, check out [this
|
||||
|
||||
## Usage
|
||||
|
||||
Add the following step at the end of your job, after other steps that might add or change files.
|
||||
Adding git-auto-commit to your Workflow only takes a couple lines of code.
|
||||
|
||||
1. Set the `contents`-permission of the default GITHUB_TOKEN to `true`. (Required to push new commits to the repository)
|
||||
2. Add the following step at the end of your job, after other steps that might add or change files.
|
||||
|
||||
```yaml
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
```
|
||||
|
||||
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.
|
||||
Your Workflow should look similar to this example.
|
||||
|
||||
```yaml
|
||||
name: Format
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
format-code:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
# Give the default GITHUB_TOKEN write permission to commit and push the
|
||||
# added or changed files to the repository.
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Other steps that change files in the repository
|
||||
|
||||
# Commit all changed files back to the repository
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
```
|
||||
|
||||
> **Note**
|
||||
> The Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`).
|
||||
|
||||
The following is an extended example with all available options.
|
||||
|
||||
@@ -53,7 +81,7 @@ The following is an extended example with all available options.
|
||||
|
||||
# Optional commit user and author settings
|
||||
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_user_email: my-github-actions-bot@example.org # defaults to "41898282+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
|
||||
@@ -111,8 +139,12 @@ jobs:
|
||||
php-cs-fixer:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
|
||||
@@ -159,7 +191,7 @@ The following is a list of edge cases the Action knowingly does not support:
|
||||
|
||||
**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 lovel level issue, you have to resolve differently in your project. Sorry.
|
||||
**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).
|
||||
|
||||
@@ -169,7 +201,7 @@ You must use `action/checkout@v2` or later versions to check out the repository.
|
||||
In non-`push` events, such as `pull_request`, make sure to specify the `ref` to check out:
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
```
|
||||
@@ -187,7 +219,7 @@ You can change this by creating a new [Personal Access Token (PAT)](https://gith
|
||||
storing the token as a secret in your repository and then passing the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
```
|
||||
@@ -198,17 +230,66 @@ If you work in an organization and don't want to create a PAT from your personal
|
||||
|
||||
### 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.
|
||||
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
|
||||
|
||||
### Multiline Commit Messages
|
||||
|
||||
If your commit message should span multiple lines, you have to create a separate step to generate the string.
|
||||
|
||||
The example below can be used as a starting point to generate a multiline commit meesage. Learn more how multiline strings in GitHub Actions work in the [GitHub documentation](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings).
|
||||
|
||||
```yaml
|
||||
# Building a multiline commit message
|
||||
# Adjust to your liking
|
||||
- run: echo "Commit Message 1" >> commitmessage.txt
|
||||
- run: echo "Commit Message 2" >> commitmessage.txt
|
||||
- run: echo "Commit Message 3" >> commitmessage.txt
|
||||
|
||||
# Create a multiline string to be used by the git-auto-commit Action
|
||||
- name: Set commit message
|
||||
id: commit_message_step
|
||||
run: |
|
||||
echo 'commit_message<<EOF' >> $GITHUB_OUTPUT
|
||||
cat commitmessage.txt >> $GITHUB_OUTPUT
|
||||
echo 'EOF' >> $GITHUB_OUTPUT
|
||||
|
||||
# Quick and dirty step to get rid of the temporary file holding the commit message
|
||||
- run: rm -rf commitmessage.txt
|
||||
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||
id: commit
|
||||
with:
|
||||
commit_message: ${{ steps.commit_message_step.outputs.commit_message }}
|
||||
```
|
||||
|
||||
### 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 regularly.
|
||||
|
||||
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
|
||||
|
||||
### Push to forks from private repositories
|
||||
|
||||
By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings.
|
||||
|
||||
See [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) or the [GitHub docs](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) for details.
|
||||
|
||||
|
||||
### Use in forks from public repositories
|
||||
|
||||
<details>
|
||||
<summary>Use in forks from public repositories</summary>
|
||||
<summary>Expand to learn more</summary>
|
||||
|
||||
**☝️ Important Notice**: This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\
|
||||
If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch.
|
||||
> **Note**
|
||||
> This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\
|
||||
> Ensure your contributors enable "Allow edits by maintainers" when opening a pull request. ([Learn more](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)) \
|
||||
> \
|
||||
> **If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch.**
|
||||
|
||||
---
|
||||
> **Warning**
|
||||
> Due to limitations of GitHub, this Action currently can't push commits to a base repository, if the fork _lives_ under an organisation. See [github/community#6634](https://github.com/orgs/community/discussions/5634) and [this comment](https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1428849944) for details.
|
||||
|
||||
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.
|
||||
@@ -234,10 +315,19 @@ on:
|
||||
jobs:
|
||||
php-cs-fixer:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
# Checkout the fork/head-repository and push changes to the fork.
|
||||
# If you skip this, the base repository will be checked out and changes
|
||||
# will be committed to the base repository!
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
|
||||
# Checkout the branch made in the fork. Will automatically push changes
|
||||
# back to this branch.
|
||||
ref: ${{ github.head_ref }}
|
||||
|
||||
- name: Run php-cs-fixer
|
||||
@@ -248,6 +338,11 @@ jobs:
|
||||
|
||||
### Workflow should run in **forked** repository
|
||||
|
||||
> **Warning**
|
||||
> **This part of the documentation is outdated.**
|
||||
> We were not able to configure a GitHub Action workflow for forks, that the workflow would run in the fork / head repository.
|
||||
> Please let us know in the [discussions](https://github.com/stefanzweifel/git-auto-commit-action/discussions)-area, if and how you achieved that.
|
||||
|
||||
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).
|
||||
@@ -271,7 +366,7 @@ jobs:
|
||||
php-cs-fixer:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run php-cs-fixer
|
||||
uses: docker://oskarstark/php-cs-fixer-ga
|
||||
@@ -295,37 +390,15 @@ For more information about running Actions on forks, see [this announcement from
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Push to forks from private repositories</summary>
|
||||
|
||||
By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings.
|
||||
|
||||
See [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) or the [GitHub docs](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) for details.
|
||||
|
||||
</details>
|
||||
### Using `--amend` and `--no-edit` as commit options
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
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 regularly.
|
||||
|
||||
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
Using `--amend` and `--no-edit` as commit options
|
||||
</summary>
|
||||
|
||||
|
||||
|
||||
<summary>Expand to learn more</summary>
|
||||
|
||||
If you would like to use this Action to create a commit using [`--amend`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---amend) and [`--no-edit`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-edit) you need to make some adjustments.
|
||||
|
||||
**☝️ Important Notice:** You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase)
|
||||
> **Warning**
|
||||
> You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase).
|
||||
|
||||
First, you need to extract the previous commit message by using `git log -1 --pretty=%s`.
|
||||
Then you need to provide this last commit message to the Action through the `commit_message` input option.
|
||||
@@ -335,7 +408,7 @@ Finally, you have to use `push_options: '--force'` to overwrite the git history
|
||||
The steps in your workflow might look like this:
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@4
|
||||
with:
|
||||
# Fetch the last 2 commits instead of just 1. (Fetching just 1 commit would overwrite the whole history)
|
||||
fetch-depth: 2
|
||||
@@ -345,7 +418,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:
|
||||
@@ -379,13 +452,14 @@ First, you have to create a new [Personal Access Token (PAT)](https://github.com
|
||||
store the token as a secret in your repository and pass the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
```
|
||||
You can learn more about Personal Access Token in the [GitHub documentation](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token).
|
||||
|
||||
**Note:** If you're working in an organisation, and you don't want to create the PAT from your personal account, we recommend using a bot-account for such tokens.
|
||||
> **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.
|
||||
@@ -399,7 +473,7 @@ If you go the "force pushes" route, you have to enable force pushes to a protect
|
||||
|
||||
### No new workflows are triggered by the commit of this action
|
||||
|
||||
This is due to limitations set up by GitHub, [commits of this Action do not trigger new Workflow runs](#commits-of-this-action-do-not-trigger-new-workflow-runs).
|
||||
This is due to limitations set up by GitHub, [commits made by this Action do not trigger new Workflow runs](#commits-made-by-this-action-do-not-trigger-new-workflow-runs).
|
||||
|
||||
### Pathspec 'x' did not match any files
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
name: Git Auto Commit
|
||||
description: 'Automatically commits files which have been changed during the workflow run and push changes back to remote repository.'
|
||||
|
||||
author: Stefan Zweifel <hello@stefanzweifel.io>
|
||||
author: Stefan Zweifel <stefan@stefanzweifel.dev>
|
||||
|
||||
inputs:
|
||||
commit_message:
|
||||
@@ -39,7 +39,7 @@ inputs:
|
||||
commit_user_email:
|
||||
description: Email address used for the commit user
|
||||
required: false
|
||||
default: github-actions[bot]@users.noreply.github.com
|
||||
default: 41898282+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: 'node16'
|
||||
using: 'node20'
|
||||
main: 'index.js'
|
||||
|
||||
branding:
|
||||
|
@@ -6,30 +6,69 @@ if "$INPUT_DISABLE_GLOBBING"; then
|
||||
set -o noglob;
|
||||
fi
|
||||
|
||||
_set_github_output() {
|
||||
local name=${1}
|
||||
local value=${2}
|
||||
|
||||
# Check if $GITHUB_OUTPUT is available
|
||||
# (Feature detection will be removed in spring 2023)
|
||||
if [ -z ${GITHUB_OUTPUT+x} ]; then
|
||||
echo "::set-output name=$name::$value";
|
||||
else
|
||||
echo "$name=$value" >> $GITHUB_OUTPUT;
|
||||
fi
|
||||
}
|
||||
|
||||
_log() {
|
||||
local level=${1}
|
||||
local message=${2}
|
||||
|
||||
echo "::$level::$message";
|
||||
}
|
||||
|
||||
_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";
|
||||
_set_github_output "changes_detected" "true"
|
||||
|
||||
_switch_to_branch
|
||||
|
||||
_add_files
|
||||
|
||||
_local_commit
|
||||
# Check dirty state of repo again using git-diff.
|
||||
# (git-diff detects better if CRLF of files changes and does NOT
|
||||
# proceed, if only CRLF changes are detected. See #241 and #265
|
||||
# for more details.)
|
||||
if [ -n "$(git diff --staged)" ] || "$INPUT_SKIP_DIRTY_CHECK"; then
|
||||
_local_commit
|
||||
|
||||
_tag_commit
|
||||
_tag_commit
|
||||
|
||||
_push_to_github
|
||||
_push_to_github
|
||||
else
|
||||
_set_github_output "changes_detected" "false"
|
||||
|
||||
echo "Working tree clean. Nothing to commit.";
|
||||
fi
|
||||
else
|
||||
|
||||
echo "::set-output name=changes_detected::false";
|
||||
_set_github_output "changes_detected" "false"
|
||||
|
||||
echo "Working tree clean. Nothing to commit.";
|
||||
fi
|
||||
}
|
||||
|
||||
_check_if_git_is_available() {
|
||||
if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then
|
||||
_log "debug" "git binary found.";
|
||||
else
|
||||
_log "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";
|
||||
@@ -38,7 +77,7 @@ _switch_to_repository() {
|
||||
|
||||
_git_is_dirty() {
|
||||
echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}";
|
||||
echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}";
|
||||
_log "debug" "Apply status options ${INPUT_STATUS_OPTIONS}";
|
||||
|
||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
|
||||
read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN";
|
||||
@@ -52,14 +91,14 @@ _switch_to_branch() {
|
||||
|
||||
# Fetch remote to make sure that repo can be switched to the right branch.
|
||||
if "$INPUT_SKIP_FETCH"; then
|
||||
echo "::debug::git-fetch has not been executed";
|
||||
_log "debug" "git-fetch will not be executed.";
|
||||
else
|
||||
git fetch --depth=1;
|
||||
fi
|
||||
|
||||
# If `skip_checkout`-input is true, skip the entire checkout step.
|
||||
if "$INPUT_SKIP_CHECKOUT"; then
|
||||
echo "::debug::git-checkout has not been executed";
|
||||
_log "debug" "git-checkout will not be executed.";
|
||||
else
|
||||
# Create new local branch if `create_branch`-input is true
|
||||
if "$INPUT_CREATE_BRANCH"; then
|
||||
@@ -75,7 +114,7 @@ _switch_to_branch() {
|
||||
|
||||
_add_files() {
|
||||
echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}";
|
||||
echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}";
|
||||
_log "debug" "Apply add options ${INPUT_ADD_OPTIONS}";
|
||||
|
||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}";
|
||||
read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN";
|
||||
@@ -86,7 +125,7 @@ _add_files() {
|
||||
|
||||
_local_commit() {
|
||||
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}";
|
||||
echo "::debug::Apply commit options ${INPUT_COMMIT_OPTIONS}";
|
||||
_log "debug" "Apply commit options ${INPUT_COMMIT_OPTIONS}";
|
||||
|
||||
# shellcheck disable=SC2206
|
||||
INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS );
|
||||
@@ -101,7 +140,7 @@ _local_commit() {
|
||||
--author="$INPUT_COMMIT_AUTHOR" \
|
||||
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};
|
||||
|
||||
echo "::set-output name=commit_hash::$(git rev-parse HEAD)";
|
||||
_set_github_output "commit_hash" $(git rev-parse HEAD)
|
||||
}
|
||||
|
||||
_tag_commit() {
|
||||
@@ -109,7 +148,7 @@ _tag_commit() {
|
||||
|
||||
if [ -n "$INPUT_TAGGING_MESSAGE" ]
|
||||
then
|
||||
echo "::debug::Create tag $INPUT_TAGGING_MESSAGE";
|
||||
_log "debug" "Create tag $INPUT_TAGGING_MESSAGE";
|
||||
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE";
|
||||
else
|
||||
echo "No tagging message supplied. No tag will be added.";
|
||||
@@ -119,7 +158,7 @@ _tag_commit() {
|
||||
_push_to_github() {
|
||||
|
||||
echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS}";
|
||||
echo "::debug::Apply push options ${INPUT_PUSH_OPTIONS}";
|
||||
_log "debug" "Apply push options ${INPUT_PUSH_OPTIONS}";
|
||||
|
||||
# shellcheck disable=SC2206
|
||||
INPUT_PUSH_OPTIONS_ARRAY=( $INPUT_PUSH_OPTIONS );
|
||||
@@ -129,15 +168,15 @@ _push_to_github() {
|
||||
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
|
||||
if [ -n "$INPUT_TAGGING_MESSAGE" ]
|
||||
then
|
||||
echo "::debug::git push origin --tags";
|
||||
_log "debug" "git push origin --tags";
|
||||
git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
else
|
||||
echo "::debug::git push origin";
|
||||
_log "debug" "git push origin";
|
||||
git push origin ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
fi
|
||||
|
||||
else
|
||||
echo "::debug::Push commit to remote branch $INPUT_BRANCH";
|
||||
_log "debug" "Push commit to remote branch $INPUT_BRANCH";
|
||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"};
|
||||
fi
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"bats": "^1.1.0",
|
||||
"bats": "^1.10.0",
|
||||
"bats-assert": "ztombol/bats-assert",
|
||||
"bats-support": "ztombol/bats-support"
|
||||
},
|
||||
|
@@ -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,19 +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_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
|
||||
@@ -176,7 +213,7 @@ git_auto_commit() {
|
||||
|
||||
assert_line "INPUT_STATUS_OPTIONS: --untracked-files=no"
|
||||
assert_line "INPUT_ADD_OPTIONS: -u"
|
||||
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
|
||||
@@ -186,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
|
||||
@@ -197,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
|
||||
@@ -214,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
|
||||
@@ -222,7 +259,7 @@ git_auto_commit() {
|
||||
}
|
||||
|
||||
@test "It applies commit user and author settings" {
|
||||
INPUT_COMMIT_USER_NAME="A Single Test"
|
||||
INPUT_COMMIT_USER_NAME="Custom User Name"
|
||||
INPUT_COMMIT_USER_EMAIL="single-test@github.com"
|
||||
INPUT_COMMIT_AUTHOR="A Single Test <single@users.noreply.github.com>"
|
||||
|
||||
@@ -232,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: Custom User Name"
|
||||
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'
|
||||
@@ -245,7 +282,7 @@ git_auto_commit() {
|
||||
assert_output --partial "A Single Test"
|
||||
|
||||
run git log -1 --pretty=format:'%cn'
|
||||
assert_output --partial "A Single Test"
|
||||
assert_output --partial "Custom User Name"
|
||||
|
||||
run git log -1 --pretty=format:'%ce'
|
||||
assert_output --partial "single-test@github.com"
|
||||
@@ -262,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
|
||||
@@ -273,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
|
||||
}
|
||||
@@ -282,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"
|
||||
|
||||
@@ -298,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"
|
||||
|
||||
@@ -341,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
|
||||
}
|
||||
@@ -381,7 +417,7 @@ git_auto_commit() {
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "::debug::git-fetch has not been executed"
|
||||
assert_line "::debug::git-fetch will not be executed."
|
||||
}
|
||||
|
||||
@test "If SKIP_CHECKOUT is true git-checkout will not be called" {
|
||||
@@ -394,7 +430,7 @@ git_auto_commit() {
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "::debug::git-checkout has not been executed"
|
||||
assert_line "::debug::git-checkout will not be executed."
|
||||
}
|
||||
|
||||
@test "It pushes generated commit and tag to remote and actually updates the commit shas" {
|
||||
@@ -419,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"
|
||||
@@ -462,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
|
||||
|
||||
# ---
|
||||
|
||||
@@ -487,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
|
||||
@@ -504,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}
|
||||
|
||||
# ---
|
||||
|
||||
@@ -532,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" {
|
||||
@@ -553,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"
|
||||
|
||||
@@ -562,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" {
|
||||
@@ -581,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: "
|
||||
@@ -598,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
|
||||
@@ -621,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: "
|
||||
@@ -638,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
|
||||
@@ -663,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
|
||||
@@ -675,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: "
|
||||
@@ -697,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
|
||||
@@ -722,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
|
||||
@@ -745,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"
|
||||
|
||||
@@ -789,7 +837,7 @@ 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" {
|
||||
@@ -825,7 +873,7 @@ git_auto_commit() {
|
||||
@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;
|
||||
mkdir foo
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/foo/new-file-2.neon
|
||||
|
||||
INPUT_FILE_PATTERN="**/*.neon *.neon"
|
||||
@@ -847,8 +895,8 @@ git_auto_commit() {
|
||||
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
|
||||
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
|
||||
@@ -856,7 +904,7 @@ 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";
|
||||
assert_output --partial "another-ignored-file.txt"
|
||||
|
||||
# Configure git-auto-commit
|
||||
INPUT_SKIP_DIRTY_CHECK=true
|
||||
@@ -866,9 +914,9 @@ git_auto_commit() {
|
||||
# Run git-auto-commit with special configuration
|
||||
run git_auto_commit
|
||||
|
||||
assert_output --partial "nothing to commit, working tree clean";
|
||||
assert_output --partial "nothing to commit, working tree clean"
|
||||
|
||||
assert_failure;
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "expands file patterns correctly and commits all changed files" {
|
||||
@@ -926,33 +974,141 @@ git_auto_commit() {
|
||||
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" {
|
||||
@test "detects if crlf in files change and does not create commit" {
|
||||
# Set autocrlf to true
|
||||
cd "${FAKE_LOCAL_REPOSITORY}";
|
||||
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
|
||||
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||
echo -ne "crlf test1\n" > "${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
|
||||
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||
echo -ne "crlf test1\r\n" > "${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 "2 files changed, 2 insertions(+), 2 deletions(-)"
|
||||
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
|
||||
|
||||
refute_line --partial "new-file-2.txt"
|
||||
refute_line --partial "new-file-3.txt"
|
||||
assert_line --partial "Working tree clean. Nothing to commit."
|
||||
assert_line --partial "new-file-2.txt"
|
||||
assert_line --partial "new-file-3.txt"
|
||||
|
||||
# Changes are not detected
|
||||
run cat_github_output
|
||||
assert_line "changes_detected=false"
|
||||
}
|
||||
|
||||
@test "detects if crlf in files change and creates commit if the actual content of the files change" {
|
||||
# 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
|
||||
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||
echo -ne "crlf test1\n" > "${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
|
||||
echo -ne "crlf test2\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
|
||||
echo -ne "crlf test2\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
|
||||
|
||||
# Run git-auto-commit to commit the 2 changes files
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line --partial "2 files changed, 2 insertions(+), 2 deletions(-)"
|
||||
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
|
||||
|
||||
assert_line --partial "new-file-2.txt"
|
||||
assert_line --partial "new-file-3.txt"
|
||||
|
||||
# Changes are detected
|
||||
run cat_github_output
|
||||
assert_line "changes_detected=true"
|
||||
}
|
||||
|
||||
|
||||
@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."
|
||||
}
|
||||
|
||||
@test "It creates multi-line commit messages" {
|
||||
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
|
||||
|
||||
COMMIT_MESSAGE=$(cat <<-END
|
||||
this commit message
|
||||
has multiple lines
|
||||
END
|
||||
)
|
||||
|
||||
INPUT_COMMIT_MESSAGE=$COMMIT_MESSAGE
|
||||
|
||||
run git_auto_commit
|
||||
|
||||
assert_success
|
||||
|
||||
# Assert last commit was signed off
|
||||
run git log -n 1
|
||||
assert_output --partial $COMMIT_MESSAGE
|
||||
}
|
||||
|
@@ -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.7.0"
|
||||
resolved "https://registry.yarnpkg.com/bats/-/bats-1.7.0.tgz#caae958b1d211eda6b1322ac7792515de40165a2"
|
||||
integrity sha512-pt5zjJQUB4+JI8Si+z/IAWc8yhMyhdZs6IXMCKgzF768dUIyW5xyBstWtDI5uGSa80v7UQOhh+w0GA4p4+01Bg==
|
||||
bats@^1.10.0:
|
||||
version "1.10.0"
|
||||
resolved "https://registry.yarnpkg.com/bats/-/bats-1.10.0.tgz#d22cb6e2d88fd39302167da237d710406d1587ce"
|
||||
integrity sha512-yOQrC7npuCrN+Ic3TyjTjJlzHa0qlK3oEO6VAYPWwFeutx/GmpljIyB6uNSl/UTASyc2w4FgVuA/QMMf9OdsCw==
|
||||
|
Reference in New Issue
Block a user