From 488db3d5039c2879d03cb74567b8215a01208a9e Mon Sep 17 00:00:00 2001 From: stefanzweifel Date: Tue, 12 Apr 2022 18:43:36 +0000 Subject: [PATCH 01/18] Update CHANGELOG --- CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d5458c..5a5464a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,21 @@ 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.14.0...HEAD) +## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.14.1...HEAD) > 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) @jooola +- Change Commit User Email from "actions@github.com" to "github-actions[bot]@users.noreply.github.com" (#213) @jooola + +## Fixed + +- Update doc link to GITHUB_TOKEN not triggering new workflow runs (#206) @gapple + ## [v4.14.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.1...v4.14.0) - 2022-03-18 ## Added From 79ae6eea9571e6564ff5bc076266872207a5bdac Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 15 Apr 2022 20:06:11 +0200 Subject: [PATCH 02/18] Update README concerning pull_request_target trigger Closes #211 --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b7a1e8ce..8ec33401 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Add the following step at the end of your job, after other steps that might add Note that the Action has to be used in a Job that runs on a UNIX system (eg. `ubuntu-latest`). If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the `contents: write` permission. -The following is an extended example with all possible options available for this Action. +The following is an extended example with all available options. ```yaml - uses: stefanzweifel/git-auto-commit-action@v4 @@ -153,7 +153,7 @@ The goal of this Action is to be "the Action for committing files for the 80% us 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. @@ -204,9 +204,45 @@ If you use this Action in combination with a linter/fixer, it's easier if you ru --- -By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.) +By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.) +However, there are a couple of ways to use this Actions in Workflows that should be triggered by forked repositories. -If you want that a Workflow using this Action runs on Pull Requests opened by forks, 2 things have to be changed: +### Workflow should run in **base** repository + +The workflow below runs whenever a commit is pushed to the `main`-branch or when activity on a pull request happens, by listening to the [`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) event. + +If the workflow is triggered by the `pull_request_target`-event, the workflow will run in the context of the base of the pull request, rather than in the context of the merge commit, as the `pull_request` event does. +In other words, this will allow your workflow to be run in the repository where the pull request is opened to and will push changes back to the fork. + +Check out the discussion in [#211](https://github.com/stefanzweifel/git-auto-commit-action/issues/211) for more information on this. + +```yaml +name: Format PHP + +on: + push: + branches: + - main + pull_request_target: + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + + - name: Run php-cs-fixer + uses: docker://oskarstark/php-cs-fixer-ga + + - uses: stefanzweifel/git-auto-commit-action@v4 +``` + +### Workflow should run in **forked** repository + +If the workflow should run in the forked repository, follow these steps: 1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target). 2. GitHub Action has to be enabled on the forked repository. \ @@ -239,7 +275,7 @@ jobs: commit_message: Apply php-cs-fixer changes ``` -Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the the forked repository and will push commits to the same branch. +Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the the **forked** repository and will push commits to the same branch. Here's how the Pull Request will look like: From 789f58e41a0d5e3af8438b58272ab02db9438f80 Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Mon, 6 Jun 2022 07:36:31 +0200 Subject: [PATCH 03/18] Add missing links in the CHANGELOG (#223) * Update CHANGELOG Add missing references to Pull Requests. * Link to PRs and Authors in upcoming release notes Co-authored-by: Stefan Zweifel --- .github/release-drafter.yml | 2 +- CHANGELOG.md | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 455bbd65..69cfc0b3 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,7 +1,7 @@ ame-template: 'v$RESOLVED_VERSION' tag-template: 'v$RESOLVED_VERSION' +change-template: '- $TITLE ([#$NUMBER](https://github.com/stefanzweifel/git-auto-commit-action/pull/$NUMBER)) [@$AUTHOR](https://github.com/@$AUTHOR)' template: | - # What's Changed $CHANGES categories: - title: Added diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5464a6..45ee049b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,38 +13,38 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Changed -- Change Commit User Name from "GitHub Actions" to "github-actions[bot]" (#213) @jooola -- Change Commit User Email from "actions@github.com" to "github-actions[bot]@users.noreply.github.com" (#213) @jooola +- 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) @gapple +- 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) @stefanzweifel +- 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) @funkyfuture +- README.md: Updates hyperlink to GH docs ([#200](https://github.com/stefanzweifel/git-auto-commit-action/pull/200)) @funkyfuture ## [v4.13.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.13.0...v4.13.1) - 2022-01-13 ## Fixed -- Properly disambiguate between branch or file checkout (#199) @kenodegard +- Properly disambiguate between branch or file checkout ([#199](https://github.com/stefanzweifel/git-auto-commit-action/pull/199)) @kenodegard ## [v4.13.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.12.0...v4.13.0) - 2022-01-10 ## Added -- Add `skip_checkout` option (#197) @cmbuckley +- Add `skip_checkout` option ([#197](https://github.com/stefanzweifel/git-auto-commit-action/pull/197)) @cmbuckley ## Changed -- Add note on minimum permissions to the docs (#180) @ericcornelissen +- Add note on minimum permissions to the docs ([#180](https://github.com/stefanzweifel/git-auto-commit-action/pull/180)) @ericcornelissen ## [v4.12.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.11.0...v4.12.0) - 2021-09-10 From f990bd0ed13ca1e41d474ae0bff84ea053b3bd65 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Mon, 27 Jun 2022 20:56:36 +0200 Subject: [PATCH 04/18] Add Note about .gitignore --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8ec33401..9f69ffcc 100644 --- a/README.md +++ b/README.md @@ -194,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. +### 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
From 571d6b78ed2213bc3630491d4cfffb7fe3f152bb Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 28 Jun 2022 20:08:10 +0200 Subject: [PATCH 05/18] Add test to verify issue #227 This test confirms the problem mentioned in #227. If `file_pattern` contains a pattern of, for example 2 file extensions, and only files for one extensions are dirty but not for the otherone, `git-add` will throw a fatal error. It does not throw an error if the files for the pattern already exist but are not dirty. --- tests/git-auto-commit.bats | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index ea53cad8..47687ced 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -793,3 +793,33 @@ git_auto_commit() { 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 fataal 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 +} From f0d72a04e7eb2216f50ae6c9089b42165b342737 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Wed, 29 Jun 2022 20:24:50 +0200 Subject: [PATCH 06/18] Add note about pathspec error --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 9f69ffcc..8bf22dda 100644 --- a/README.md +++ b/README.md @@ -399,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). +### 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 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`. From f33e764001cd92cef6fcdd2d494661df3d143a75 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 11 Jul 2022 15:25:38 +0200 Subject: [PATCH 07/18] fix typo in readme (#230) remote was misspelled --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8bf22dda..7c5dcc91 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The following is an extended example with all available options. commit_author: Author # defaults to author of the commit that triggered the run # Optional. Tag name being created in the local repository and - # pushed to remtoe repository and defined branch. + # pushed to remote repository and defined branch. tagging_message: 'v1.0.0' # Optional. Option used by `git-status` to determine if the repository is From f5b5fefa06a5c27d8b29ab2f0f31c0ce1a5b9d59 Mon Sep 17 00:00:00 2001 From: Derrick Lee Date: Wed, 27 Jul 2022 14:23:35 +0800 Subject: [PATCH 08/18] docs: fix typos and grammer errors in readme.md (#235) --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7c5dcc91..dad822fd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add the following step at the end of your job, after other steps that might add - uses: stefanzweifel/git-auto-commit-action@v4 ``` -Note that the Action has to be used in a Job that runs on a UNIX system (eg. `ubuntu-latest`). +Note that the Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`). If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the `contents: write` permission. The following is an extended example with all available options. @@ -149,7 +149,7 @@ You can use these outputs to trigger other Actions in your Workflow run based on ## Limitations & Gotchas -The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore you might run into issues if your Workflow falls into the not supported 20% portion. +The goal of this Action is to be "the Action for committing files for the 80% use case". Therefore, you might run into issues if your Workflow falls into the not supported 20% portion. The following is a list of edge cases the Action knowingly does not support: @@ -279,7 +279,7 @@ jobs: commit_message: Apply php-cs-fixer changes ``` -Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the the **forked** repository and will push commits to the same branch. +Next time a user forks your project **and** enabled GitHub Actions **and** opened a Pull Request, the Workflow will run on the **forked** repository and will push commits to the same branch. Here's how the Pull Request will look like: @@ -307,7 +307,7 @@ See [this announcement from GitHub](https://github.blog/2020-08-03-github-action Signing Commits & Other Git Command Line Options -Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regulary. +Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regularly. - [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer)) @@ -371,7 +371,7 @@ Updating the `token` value with a Personal Access Token should fix your issues. ### Push to protected branches -If your repository uses [protected branches](https://help.github.com/en/github/administering-a-repository/configuring-protected-branches) you have to make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Acess Token needs to belong to an Administrator. +If your repository uses [protected branches](https://help.github.com/en/github/administering-a-repository/configuring-protected-branches) you have to make some changes to your Workflow for the Action to work properly: You need a Personal Access Token and you either have to allow force pushes or the Personal Access Token needs to belong to an Administrator. First, you have to create a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new), store the token as a secret in your repository and pass the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step. @@ -383,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). -**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. @@ -403,7 +403,7 @@ This is due to limitations set up by GitHub, [commits of this Action do not trig 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. +`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. @@ -427,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 also provide major version tags to make it easier to always use the latest release of a major version. For example you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version. +We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use `stefanzweifel/git-auto-commit-action@v4` to always use the latest release of the current major version. (More information about this [here](https://help.github.com/en/actions/building-actions/about-actions#versioning-your-action).) ## Credits From 32807d4f18f1f004ed74e14e047fecfe5204874b Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 30 Jul 2022 20:14:29 +0200 Subject: [PATCH 09/18] Upgrade Bats --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1d4ab408..efbe05d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11,6 +11,6 @@ bats-support@ztombol/bats-support: resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee" bats@^1.1.0: - version "1.2.1" - resolved "https://registry.yarnpkg.com/bats/-/bats-1.2.1.tgz#c15aecc3eb331aedf28678880fab2be0b73eba43" - integrity sha512-2fcPDRQa/Kvh6j1IcCqsHpT5b9ObMzRzw6abC7Bg298PX8Qdh9VRkvO2WJUEhdyfjq2rLBCOAWdcv0tS4+xTUA== + version "1.7.0" + resolved "https://registry.yarnpkg.com/bats/-/bats-1.7.0.tgz#caae958b1d211eda6b1322ac7792515de40165a2" + integrity sha512-pt5zjJQUB4+JI8Si+z/IAWc8yhMyhdZs6IXMCKgzF768dUIyW5xyBstWtDI5uGSa80v7UQOhh+w0GA4p4+01Bg== From 926240570901a8a0cbb6fb2ec40f26e35d5644fe Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 30 Jul 2022 20:14:41 +0200 Subject: [PATCH 10/18] Fix Typo in Test --- tests/git-auto-commit.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 47687ced..21c3eeac 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -805,7 +805,7 @@ git_auto_commit() { assert_line --partial "fatal: pathspec '*.bar' did not match any files" } -@test "does not throw fataal error if files for file pattern exist but only one is dirty" { +@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 From dce7e85096193516db2ae686bd562faf5bc7f4ea Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 30 Jul 2022 20:21:57 +0200 Subject: [PATCH 11/18] Add Tests to Cover #233 --- tests/git-auto-commit.bats | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 21c3eeac..449d9d87 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -823,3 +823,19 @@ 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" +} From 4e7c0d67cd27ac96adcf4d3e06db1070c1a3c4f0 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 6 Sep 2022 21:04:34 +0200 Subject: [PATCH 12/18] Assert throws error when force adding ignored files See https://github.com/stefanzweifel/git-auto-commit-action/issues/204#issuecomment-1236880360 --- tests/git-auto-commit.bats | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 449d9d87..775d24a3 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -839,3 +839,36 @@ git_auto_commit() { 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; +} From 4d00f10668b767d99f539489062c0e3dd052c645 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 15:18:36 +0200 Subject: [PATCH 13/18] Expand `file_pattern`-input to an array (#205) * Expand file_pattern input * Expand file pattern array in git-status * Add Failing Test * Expand INPUT_FILE_PATTERN * Fix Shellcheck Issues * Add test to cover file expansion works when globbing is disabled * Add explanation to README --- README.md | 20 +++++++++++++ entrypoint.sh | 8 ++++-- tests/git-auto-commit.bats | 57 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dad822fd..1f776475 100644 --- a/README.md +++ b/README.md @@ -407,6 +407,26 @@ If you're using the Action with a custom `file_pattern` and the Action throws a See [Issue #227](https://github.com/stefanzweifel/git-auto-commit-action/issues/227) for details. +### Custom `file_pattern`, changed files but seeing "Working tree clean. Nothing to commit." in the logs + +If you're using a custom `file_pattern` and the Action does not detect the changes made in your worfklow, you're probably running into a globbing issue. + +Let's imagine you use `file_pattern: '*.md'` to detect and commit changes to all Markdown files in your repository. +If your Workflow now only updates `.md`-files in a subdirectory, but you have an untouched `.md`-file in the root of the repository, the git-auto-commit Action will display "Working tree clean. Nothing to commit." in the Workflow log. + +This is due to the fact, that the `*.md`-glob is expanded before sending it to `git-status`. `git-status` will receive the filename of your untouched `.md`-file in the root of the repository and won't detect any changes; and therefore the Action does nothing. + +To fix this add `disable_globbing: true` to your Workflow. + +```yaml +- uses: stefanzweifel/git-auto-commit-action@v4 + with: + file_pattern: '*.md' + disable_globbing: true +``` + +See [Issue #239](https://github.com/stefanzweifel/git-auto-commit-action/issues/239) for details. + ## Running the tests The Action has tests written in [bats](https://github.com/bats-core/bats-core). Before you can run the test suite locally, you have to install the dependencies with `npm` or `yarn`. diff --git a/entrypoint.sh b/entrypoint.sh index dee54a95..e34e72ea 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -40,8 +40,11 @@ _git_is_dirty() { echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}"; echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}"; + echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; + read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; + # shellcheck disable=SC2086 - [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- $INPUT_FILE_PATTERN)" ] + [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ] } _switch_to_branch() { @@ -75,9 +78,10 @@ _add_files() { echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; + read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; # shellcheck disable=SC2086 - git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN}; + git add ${INPUT_ADD_OPTIONS} ${INPUT_FILE_PATTERN:+"${INPUT_FILE_PATTERN_EXPANDED[@]}"}; } _local_commit() { diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index 775d24a3..819b1e88 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -164,7 +164,6 @@ git_auto_commit() { } @test "It applies INPUT_ADD_OPTIONS when adding files" { - INPUT_FILE_PATTERN="" INPUT_STATUS_OPTIONS="--untracked-files=no" INPUT_ADD_OPTIONS="-u" @@ -177,7 +176,6 @@ git_auto_commit() { assert_line "INPUT_STATUS_OPTIONS: --untracked-files=no" assert_line "INPUT_ADD_OPTIONS: -u" - assert_line "INPUT_FILE_PATTERN: " assert_line "::debug::Push commit to remote branch master" # Assert that PHP files have not been added. @@ -872,3 +870,58 @@ git_auto_commit() { assert_failure; } + +@test "expands file patterns correctly and commits all changed files" { + # Add more .txt files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.txt + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar + + INPUT_FILE_PATTERN="*.txt *.bar" + + run git_auto_commit + + assert_success + + assert_line --partial "new-file-1.txt" + assert_line --partial "subdirectory/new-file-2.txt" + assert_line --partial "new-file-3.bar" +} + +@test "expands file patterns correctly and commits all changed files when globbing is disabled" { + # Add more .txt files + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-1.txt + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.bar + + INPUT_FILE_PATTERN="*.txt *.bar" + INPUT_DISABLE_GLOBBING=true + + run git_auto_commit + + assert_success + + assert_line --partial "new-file-1.txt" + assert_line --partial "subdirectory/new-file-2.txt" + assert_line --partial "new-file-3.bar" +} + +@test "expands file patterns correctly and commits all changed files if dirty files are only in subdirectory" { + # Add more .txt files + mkdir "${FAKE_LOCAL_REPOSITORY}"/subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/subdirectory/new-file-2.txt + mkdir "${FAKE_LOCAL_REPOSITORY}"/another-subdirectory/ + touch "${FAKE_LOCAL_REPOSITORY}"/another-subdirectory/new-file-3.txt + + INPUT_FILE_PATTERN="*.txt" + INPUT_DISABLE_GLOBBING=true + + run git_auto_commit + + assert_success + + assert_line --partial "subdirectory/new-file-2.txt" + assert_line --partial "another-subdirectory/new-file-3.txt" +} From 03246c1ceed0c91e9b14bf5a366ba777eb931d5e Mon Sep 17 00:00:00 2001 From: Karol <50302144+karolswdev@users.noreply.github.com> Date: Sat, 17 Sep 2022 07:33:25 -0600 Subject: [PATCH 14/18] Changed the extended example to correctly use quotes for strings (#196) Co-authored-by: Stefan Zweifel --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f776475..58320edb 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,14 @@ The following is an extended example with all available options. with: # Optional. Commit message for the created commit. # Defaults to "Apply automatic changes" - commit_message: Automated Change + commit_message: 'Automated Change' # Optional. Local and remote branch name where commit is going to be pushed # to. Defaults to the current branch. # You might need to set `create_branch: true` if the branch does not exist. branch: feature-123 + # Optional. Options used by `git-commit`. # See https://git-scm.com/docs/git-commit#_options commit_options: '--no-verify --signoff' @@ -45,7 +46,7 @@ The following is an extended example with all available options. # See the `pathspec`-documentation for git # - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203 # - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec - file_pattern: src/*.js tests/*.js *.php + file_pattern: '*.php src/*.js tests/*.js' # Optional. Local file path to the repository. # Defaults to the root of the repository. From 52eb0eedc8e2bf33895ad736b09ad81083847739 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 15:34:02 +0200 Subject: [PATCH 15/18] Update README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 58320edb..302c7a19 100644 --- a/README.md +++ b/README.md @@ -29,14 +29,13 @@ The following is an extended example with all available options. with: # Optional. Commit message for the created commit. # Defaults to "Apply automatic changes" - commit_message: 'Automated Change' + commit_message: Automated Change # Optional. Local and remote branch name where commit is going to be pushed # to. Defaults to the current branch. # You might need to set `create_branch: true` if the branch does not exist. branch: feature-123 - # Optional. Options used by `git-commit`. # See https://git-scm.com/docs/git-commit#_options commit_options: '--no-verify --signoff' From 18870f2286c2860e1e6c802fe8f7d5f382b903d7 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 16:02:44 +0200 Subject: [PATCH 16/18] Add note about line break detection --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 302c7a19..665924bd 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,8 @@ 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. + If this Action doesn't work for your workflow, check out [EndBug/add-and-commit](https://github.com/EndBug/add-and-commit). ### Checkout the correct branch From a4a482b6c5c4ddd79f093f0f516a1c9a10669a8a Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 16:35:49 +0200 Subject: [PATCH 17/18] Update Issue Templates --- .github/ISSUE_TEMPLATE/bug.yaml | 63 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/bug_report.md | 38 -------------- .github/ISSUE_TEMPLATE/config.yml | 8 +++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ------- 4 files changed, 71 insertions(+), 58 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug.yaml delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug.yaml b/.github/ISSUE_TEMPLATE/bug.yaml new file mode 100644 index 00000000..9db3b751 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.yaml @@ -0,0 +1,63 @@ +name: Bug Report +description: If you've already asked for help with a problem and confirmed something is broken with git-auto-commit itself, create a bug report. +body: + - type: markdown + attributes: + value: | + Before opening a bug report, please search for the behaviour in the existing issues. + + --- + + Thank you for taking the time to file a bug report! + - type: input + id: git-auto-commit-version + attributes: + label: git-auto-commit Version + description: "Which exact version of git-auto-commit are you using in your Workflow?" + placeholder: "v4.14.0" + validations: + required: true + - type: dropdown + id: machine + attributes: + label: Machine Type + description: On which type of machine is your workflow running? + options: + - Ubuntu (eg. ubuntu-latest) + - macOS (eg. macos-latest) + - Windows (Not supported!) + validations: + required: true + - type: textarea + id: bug-description + attributes: + label: Bug description + description: What exactly happened? + validations: + required: true + - type: textarea + id: steps + attributes: + label: Steps to reproduce + description: Which steps do we need to take to reproduce this error? + validations: + required: true + - type: textarea + id: tried-solutions + attributes: + label: Tried solutions + description: Have you tried solving the issue by adapting your Workflow? What steps did you take? + - type: textarea + id: example-workflow + attributes: + label: Example Workflow + description: Please share your GitHub Actions workflow which causes the bug. We use this to reproduce the error. No need for backticks here. + render: yaml + validations: + required: true + - type: textarea + id: logs + attributes: + label: Relevant log output + description: If applicable, provide relevant log output. No need for backticks here. + render: shell diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 29d2cf93..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - - - -**Version of the Action** -`v4.x.x` - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Used Workflow** - -```yaml -# Paste the Workflow you've used here -``` - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..edb1c778 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Get Help + url: https://github.com/stefanzweifel/git-auto-commit-action/discussions/new?category=help + about: If you can't get something to work the way you expect, open a question in our discussion forums. + - name: Feature Request + url: https://github.com/tailwindlabs/tailwindcss/discussions/new?category=ideas + about: 'Suggest any ideas you have using our discussion forums.' diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index bbcbbe7d..00000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. From 6c32682a4040e023c054b2fc60a7cf65cc77f7ad Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Sat, 17 Sep 2022 16:37:41 +0200 Subject: [PATCH 18/18] Add bug label to new issues --- .github/ISSUE_TEMPLATE/bug.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/bug.yaml b/.github/ISSUE_TEMPLATE/bug.yaml index 9db3b751..3221ab95 100644 --- a/.github/ISSUE_TEMPLATE/bug.yaml +++ b/.github/ISSUE_TEMPLATE/bug.yaml @@ -1,5 +1,6 @@ name: Bug Report description: If you've already asked for help with a problem and confirmed something is broken with git-auto-commit itself, create a bug report. +labels: ["bug"] body: - type: markdown attributes: