Merge branch 'master' into refactor/expand-file-pattern

This commit is contained in:
Stefan Zweifel 2022-09-14 18:35:17 +02:00
commit b6b3a4f866
6 changed files with 173 additions and 27 deletions

View File

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

View File

@ -5,25 +5,46 @@ 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/) 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). and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...HEAD) ## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.1...HEAD)
> TBD > TBD
## [v4.14.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.0...v4.14.1) - 2022-04-12
## Changed
- Change Commit User Name from "GitHub Actions" to "github-actions[bot]" ([#213](https://github.com/stefanzweifel/git-auto-commit-action/pull/213)) @jooola
- Change Commit User Email from "actions@github.com" to "github-actions[bot]@users.noreply.github.com" ([#213](https://github.com/stefanzweifel/git-auto-commit-action/pull/213)) @jooola
## Fixed
- Update doc link to GITHUB_TOKEN not triggering new workflow runs ([#206](https://github.com/stefanzweifel/git-auto-commit-action/pull/206)) @gapple
## [v4.14.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...v4.14.0) - 2022-03-18
## Added
- Add `create_branch` option to force create a new branch ([#203](https://github.com/stefanzweifel/git-auto-commit-action/pull/203)) @stefanzweifel
## Fixed
- README.md: Updates hyperlink to GH docs ([#200](https://github.com/stefanzweifel/git-auto-commit-action/pull/200)) @funkyfuture
## [v4.13.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...v4.13.1) - 2022-01-13 ## [v4.13.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...v4.13.1) - 2022-01-13
## Fixed ## Fixed
- Properly disambiguate between branch or file checkout (#199) @kenodegard - Properly disambiguate between branch or file checkout ([#199](https://github.com/stefanzweifel/git-auto-commit-action/pull/199)) @kenodegard
## [v4.13.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...v4.13.0) - 2022-01-10 ## [v4.13.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...v4.13.0) - 2022-01-10
## Added ## Added
- Add `skip_checkout` option (#197) @cmbuckley - Add `skip_checkout` option ([#197](https://github.com/stefanzweifel/git-auto-commit-action/pull/197)) @cmbuckley
## Changed ## Changed
- Add note on minimum permissions to the docs (#180) @ericcornelissen - Add note on minimum permissions to the docs ([#180](https://github.com/stefanzweifel/git-auto-commit-action/pull/180)) @ericcornelissen
## [v4.12.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...v4.12.0) - 2021-09-10 ## [v4.12.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...v4.12.0) - 2021-09-10

View File

@ -2,7 +2,6 @@
> The GitHub Action for committing files for the 80% use case. > The GitHub Action for committing files for the 80% use case.
<a href="https://github.com/search?o=desc&q=stefanzweifel%2Fgit-auto-commit-action+path%3A.github%2Fworkflows+language%3AYAML&s=&type=Code" target="_blank" title="Public workflows that use this action."><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fapi-git-master.endbug.vercel.app%2Fapi%2Fgithub-actions%2Fused-by%3Faction%3Dstefanzweifel%2Fgit-auto-commit-action%26badge%3Dtrue" alt="Public workflows that use this action."></a>
<a href="https://github.com/stefanzweifel/git-auto-commit-action/actions?query=workflow%3Atests"> <a href="https://github.com/stefanzweifel/git-auto-commit-action/actions?query=workflow%3Atests">
<img src="https://github.com/stefanzweifel/git-auto-commit-action/workflows/tests/badge.svg" alt=""> <img src="https://github.com/stefanzweifel/git-auto-commit-action/workflows/tests/badge.svg" alt="">
</a> </a>
@ -20,10 +19,10 @@ Add the following step at the end of your job, after other steps that might add
- uses: stefanzweifel/git-auto-commit-action@v4 - uses: stefanzweifel/git-auto-commit-action@v4
``` ```
Note that the Action has to be used in a Job that runs on a UNIX system (eg. `ubuntu-latest`). Note that the Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`).
If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the `contents: write` permission. If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the `contents: write` permission.
The following is an extended example with all possible options available for this Action. The following is an extended example with all available options.
```yaml ```yaml
- uses: stefanzweifel/git-auto-commit-action@v4 - uses: stefanzweifel/git-auto-commit-action@v4
@ -53,12 +52,12 @@ The following is an extended example with all possible options available for thi
repository: . repository: .
# Optional commit user and author settings # Optional commit user and author settings
commit_user_name: My GitHub Actions Bot # defaults to "GitHub Actions" commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]"
commit_user_email: my-github-actions-bot@example.org # defaults to "actions@github.com" commit_user_email: my-github-actions-bot@example.org # defaults to "github-actions[bot]@users.noreply.github.com"
commit_author: Author <actions@github.com> # defaults to author of the commit that triggered the run 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 # Optional. Tag name being created in the local repository and
# pushed to remtoe repository and defined branch. # pushed to remote repository and defined branch.
tagging_message: 'v1.0.0' tagging_message: 'v1.0.0'
# Optional. Option used by `git-status` to determine if the repository is # Optional. Option used by `git-status` to determine if the repository is
@ -87,7 +86,6 @@ The following is an extended example with all possible options available for thi
disable_globbing: true disable_globbing: true
# Optional. Create given branch name in local and remote repository. # Optional. Create given branch name in local and remote repository.
# (Not released yet, available when @master is used)
create_branch: true create_branch: true
``` ```
@ -151,11 +149,11 @@ You can use these outputs to trigger other Actions in your Workflow run based on
## Limitations & Gotchas ## Limitations & Gotchas
The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore you might run into issues if your Workflow falls into the not supported 20% portion. The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore, you might run into issues if your Workflow falls into the not supported 20% portion.
The following is a list of edge cases the Action knowingly does not support: The following is a list of edge cases the Action knowingly does not support:
**No `git pull` when the repository is out of the date with remote.** The Action will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs. **No `git pull` when the repository is out of date with remote.** The Action will not do a `git pull` before doing the `git push`. **You** are responsible for keeping the repository up to date in your Workflow runs.
**No support for running the Action in build matrices**. If your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a `git pull` for you, you have to do that yourself. **No support for running the Action in build matrices**. If your Workflow is using build matrices, and you want that each job commits and pushes files to the remote, you will run into the issue, that the repository in the workflow will become out of date. As the Action will not do a `git pull` for you, you have to do that yourself.
@ -179,7 +177,7 @@ Do this to avoid checking out the repository in a detached state.
### Commits made by this Action do not trigger new Workflow runs ### Commits made by this Action do not trigger new Workflow runs
The resulting commit **will not trigger** another GitHub Actions Workflow run. The resulting commit **will not trigger** another GitHub Actions Workflow run.
This is due to [limitations set by GitHub](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#triggering-a-workflow-from-a-workflow). This is due to [limitations set by GitHub](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow).
> When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. > When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.
@ -196,6 +194,10 @@ If you create a personal access token, apply the `repo` and `workflow` scopes.
If you work in an organization and don't want to create a PAT from your personal account, we recommend using a [robot account](https://docs.github.com/en/github/getting-started-with-github/types-of-github-accounts) for the token. If you work in an organization and don't want to create a PAT from your personal account, we recommend using a [robot account](https://docs.github.com/en/github/getting-started-with-github/types-of-github-accounts) for the token.
### Change to file is not detected
Does your workflow change a file but "git-auto-commit" does not detect the change? Check the `.gitignore` that applies to the respective file. You might have accidentally marked the file to be ignored by git.
## Advanced Uses ## Advanced Uses
<details> <details>
@ -206,9 +208,45 @@ If you use this Action in combination with a linter/fixer, it's easier if you ru
--- ---
By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.) By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.)
However, there are a couple of ways to use this Actions in Workflows that should be triggered by forked repositories.
If you want that a Workflow using this Action runs on Pull Requests opened by forks, 2 things have to be changed: ### Workflow should run in **base** repository
The workflow below runs whenever a commit is pushed to the `main`-branch or when activity on a pull request happens, by listening to the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event.
If the workflow is triggered by the `pull_request_target`-event, the workflow will run in the context of the base of the pull request, rather than in the context of the merge commit, as the `pull_request` event does.
In other words, this will allow your workflow to be run in the repository where the pull request is opened to and will push changes back to the fork.
Check out the discussion in [#211](https://github.com/stefanzweifel/git-auto-commit-action/issues/211) for more information on this.
```yaml
name: Format PHP
on:
push:
branches:
- main
pull_request_target:
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
- name: Run php-cs-fixer
uses: docker://oskarstark/php-cs-fixer-ga
- uses: stefanzweifel/git-auto-commit-action@v4
```
### Workflow should run in **forked** repository
If the workflow should run in the forked repository, follow these steps:
1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target). 1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target).
2. GitHub Action has to be enabled on the forked repository. \ 2. GitHub Action has to be enabled on the forked repository. \
@ -241,7 +279,7 @@ jobs:
commit_message: Apply php-cs-fixer changes commit_message: Apply php-cs-fixer changes
``` ```
Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the the forked repository and will push commits to the same branch. Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the **forked** repository and will push commits to the same branch.
Here's how the Pull Request will look like: Here's how the Pull Request will look like:
@ -269,7 +307,7 @@ See [this announcement from GitHub](https://github.blog/2020-08-03-github-action
Signing Commits & Other Git Command Line Options Signing Commits & Other Git Command Line Options
</summary> </summary>
Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regulary. Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regularly.
- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer)) - [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer))
@ -333,7 +371,7 @@ Updating the `token` value with a Personal Access Token should fix your issues.
### Push to protected branches ### Push to protected branches
If your repository uses [protected branches](https://help.github.com/en/github/administering-a-repository/configuring-protected-branches) you have to make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Acess Token needs to belong to an Administrator. If your repository uses [protected branches](https://help.github.com/en/github/administering-a-repository/configuring-protected-branches) you have to make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Access Token needs to belong to an Administrator.
First, you have to create a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new), First, you have to create a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new),
store the token as a secret in your repository and pass the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step. store the token as a secret in your repository and pass the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step.
@ -345,7 +383,7 @@ store the token as a secret in your repository and pass the new token to the [`a
``` ```
You can learn more about Personal Access Token in the [GitHub documentation](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). 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. If you go the "force pushes" route, you have to enable force pushes to a protected branch (See [documentation](https://help.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)) and update your Workflow to use force push like this.
@ -361,6 +399,14 @@ If you go the "force pushes" route, you have to enable force pushes to a protect
This is due to limitations set up by GitHub, [commits of this Action do not trigger new Workflow runs](#commits-of-this-action-do-not-trigger-new-workflow-runs). This is due to limitations set up by GitHub, [commits of this Action do not trigger new Workflow runs](#commits-of-this-action-do-not-trigger-new-workflow-runs).
### Pathspec 'x' did not match any files
If you're using the Action with a custom `file_pattern` and the Action throws a fatal error with the message "Pathspec 'file-pattern' did not match any files", the problem is probably that no file for the pattern exists in the repository.
`file_pattern` is used both for `git-status` and `git-add` in this Action. `git-add` will throw a fatal error, if for example, you use a file pattern like `*.js *.ts` but no `*.ts` files exist in your projects' repository.
See [Issue #227](https://github.com/stefanzweifel/git-auto-commit-action/issues/227) for details.
## Running the tests ## Running the tests
The Action has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`. The Action has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`.
@ -381,7 +427,7 @@ yarn test
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags). We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags).
We also provide major version tags to make it easier to always use the latest release of a major version. For example you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version. We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version.
(More information about this [here](https://help.github.com/en/actions/building-actions/about-actions#versioning-your-action).) (More information about this [here](https://help.github.com/en/actions/building-actions/about-actions#versioning-your-action).)
## Credits ## Credits

View File

@ -35,11 +35,11 @@ inputs:
commit_user_name: commit_user_name:
description: Name used for the commit user description: Name used for the commit user
required: false required: false
default: GitHub Actions default: github-actions[bot]
commit_user_email: commit_user_email:
description: Email address used for the commit user description: Email address used for the commit user
required: false required: false
default: actions@github.com default: github-actions[bot]@users.noreply.github.com
commit_author: commit_author:
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run. description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
required: false required: false

View File

@ -793,3 +793,82 @@ git_auto_commit() {
assert_equal $current_sha $remote_sha; assert_equal $current_sha $remote_sha;
} }
@test "throws fatal error if file pattern includes files that do not exist" {
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo
INPUT_FILE_PATTERN="*.foo *.bar"
run git_auto_commit
assert_failure
assert_line --partial "fatal: pathspec '*.bar' did not match any files"
}
@test "does not throw fatal error if files for file pattern exist but only one is dirty" {
# Add some .foo and .bar files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.foo
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.bar
INPUT_FILE_PATTERN="*.foo *.bar"
run git_auto_commit
# Add more .foo files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{4,5,6}.foo
INPUT_FILE_PATTERN="*.foo *.bar"
run git_auto_commit
assert_success
}
@test "detects and commits changed files based on pattern in root and subfolders" {
# Add some .neon files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.neon
mkdir foo;
touch "${FAKE_LOCAL_REPOSITORY}"/foo/new-file-2.neon
INPUT_FILE_PATTERN="**/*.neon *.neon"
run git_auto_commit
assert_success
assert_line --partial "new-file-1.neon"
assert_line --partial "foo/new-file-2.neon"
}
@test "throws error if tries to force add ignored files which do not have any changes" {
# Create 2 files which will later will be added to .gitignore
touch "${FAKE_LOCAL_REPOSITORY}"/ignored-file.txt
touch "${FAKE_LOCAL_REPOSITORY}"/another-ignored-file.txt
# Commit the 2 new files
run git_auto_commit
# Add our txt files to gitignore
echo "ignored-file.txt" >> "${FAKE_LOCAL_REPOSITORY}"/.gitignore
echo "another-ignored-file.txt" >> "${FAKE_LOCAL_REPOSITORY}"/.gitignore
# Commit & push .gitignore changes
run git_auto_commit
# Sanity check that txt files are ignored
run cat "${FAKE_LOCAL_REPOSITORY}"/.gitignore
assert_output --partial "ignored-file.txt"
assert_output --partial "another-ignored-file.txt";
# Configure git-auto-commit
INPUT_SKIP_DIRTY_CHECK=true
INPUT_ADD_OPTIONS="-f"
INPUT_FILE_PATTERN="ignored-file.txt another-ignored-file.txt"
# Run git-auto-commit with special configuration
run git_auto_commit
assert_output --partial "nothing to commit, working tree clean";
assert_failure;
}

View File

@ -11,6 +11,6 @@ bats-support@ztombol/bats-support:
resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee" resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee"
bats@^1.1.0: bats@^1.1.0:
version "1.2.1" version "1.7.0"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.2.1.tgz#c15aecc3eb331aedf28678880fab2be0b73eba43" resolved "https://registry.yarnpkg.com/bats/-/bats-1.7.0.tgz#caae958b1d211eda6b1322ac7792515de40165a2"
integrity sha512-2fcPDRQa/Kvh6j1IcCqsHpT5b9ObMzRzw6abC7Bg298PX8Qdh9VRkvO2WJUEhdyfjq2rLBCOAWdcv0tS4+xTUA== integrity sha512-pt5zjJQUB4+JI8Si+z/IAWc8yhMyhdZs6IXMCKgzF768dUIyW5xyBstWtDI5uGSa80v7UQOhh+w0GA4p4+01Bg==