mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-07-30 22:46:13 +08:00
Compare commits
29 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 |
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@v3
|
||||
- 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@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Lint Code Base
|
||||
uses: github/super-linter@v4
|
||||
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@v3
|
||||
- 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@v3
|
||||
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:
|
||||
|
25
CHANGELOG.md
25
CHANGELOG.md
@@ -5,10 +5,33 @@ 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.3...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
|
||||
|
@@ -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.
|
||||
|
162
README.md
162
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 }}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -81,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,6 +6,26 @@ 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
|
||||
|
||||
@@ -13,32 +33,29 @@ _main() {
|
||||
|
||||
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
|
||||
|
||||
# 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
|
||||
_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
|
||||
else
|
||||
|
||||
# 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";
|
||||
_push_to_github
|
||||
else
|
||||
echo "changes_detected=false" >> $GITHUB_OUTPUT;
|
||||
_set_github_output "changes_detected" "false"
|
||||
|
||||
echo "Working tree clean. Nothing to commit.";
|
||||
fi
|
||||
else
|
||||
_set_github_output "changes_detected" "false"
|
||||
|
||||
echo "Working tree clean. Nothing to commit.";
|
||||
fi
|
||||
@@ -46,9 +63,9 @@ _main() {
|
||||
|
||||
_check_if_git_is_available() {
|
||||
if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then
|
||||
echo "::debug::git binary found.";
|
||||
_log "debug" "git binary found.";
|
||||
else
|
||||
echo "::error ::git-auto-commit could not find git binary. Please make sure git is available."
|
||||
_log "error" "git-auto-commit could not find git binary. Please make sure git is available."
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
@@ -60,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";
|
||||
@@ -74,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
|
||||
@@ -97,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";
|
||||
@@ -108,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 );
|
||||
@@ -123,14 +140,7 @@ _local_commit() {
|
||||
--author="$INPUT_COMMIT_AUTHOR" \
|
||||
${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"};
|
||||
|
||||
|
||||
# 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
|
||||
_set_github_output "commit_hash" $(git rev-parse HEAD)
|
||||
}
|
||||
|
||||
_tag_commit() {
|
||||
@@ -138,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.";
|
||||
@@ -148,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 );
|
||||
@@ -158,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.8.2",
|
||||
"bats": "^1.10.0",
|
||||
"bats-assert": "ztombol/bats-assert",
|
||||
"bats-support": "ztombol/bats-support"
|
||||
},
|
||||
|
@@ -259,7 +259,7 @@ cat_github_output() {
|
||||
}
|
||||
|
||||
@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>"
|
||||
|
||||
@@ -269,7 +269,7 @@ cat_github_output() {
|
||||
|
||||
assert_success
|
||||
|
||||
assert_line "INPUT_COMMIT_USER_NAME: A Single Test"
|
||||
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}"
|
||||
@@ -282,7 +282,7 @@ cat_github_output() {
|
||||
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"
|
||||
@@ -417,7 +417,7 @@ cat_github_output() {
|
||||
|
||||
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" {
|
||||
@@ -430,7 +430,7 @@ cat_github_output() {
|
||||
|
||||
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" {
|
||||
@@ -974,7 +974,7 @@ cat_github_output() {
|
||||
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}"
|
||||
git config core.autocrlf true
|
||||
@@ -982,26 +982,65 @@ cat_github_output() {
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
@@ -1051,5 +1090,25 @@ cat_github_output() {
|
||||
run git_auto_commit
|
||||
|
||||
assert_failure;
|
||||
assert_line "::error ::git-auto-commit could not find git binary. Please make sure git is available."
|
||||
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.8.2:
|
||||
version "1.8.2"
|
||||
resolved "https://registry.yarnpkg.com/bats/-/bats-1.8.2.tgz#bdbaa7690a18f04291b35144a8ce5435cffb8dc5"
|
||||
integrity sha512-KLUIaPYuIMjqui8MbZmK84+CiwhjFVFAhFy5PXP0prLbkovc5faVzc+Qaowbz76F97zP573JrF31ODFAH7vzhg==
|
||||
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