From e27a68931bfdedc02d161959134e07e91ffaafeb Mon Sep 17 00:00:00 2001 From: stefanzweifel Date: Fri, 6 Oct 2023 17:55:19 +0000 Subject: [PATCH 01/13] Update CHANGELOG --- CHANGELOG.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3658910a..2d611c76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,31 @@ 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.16.0...HEAD) +## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v5.0.0...HEAD) > TBD +## [v5.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.16.0...v5.0.0) - 2023-10-06 + +New major release that bumps the default runtime to Node 20. There are no other breaking changes. + +### Changed + +- Update node version to node20 ([#300](https://github.com/stefanzweifel/git-auto-commit-action/pull/300)) [@ryudaitakai](https://github.com/@ryudaitakai) +- Add _log and _set_github_output functions ([#273](https://github.com/stefanzweifel/git-auto-commit-action/pull/273)) [@stefanzweifel](https://github.com/@stefanzweifel) + +### Fixed + +- Seems like there is an extra space ([#288](https://github.com/stefanzweifel/git-auto-commit-action/pull/288)) [@pedroamador](https://github.com/@pedroamador) +- Fix git-auto-commit.yml ([#277](https://github.com/stefanzweifel/git-auto-commit-action/pull/277)) [@zcong1993](https://github.com/@zcong1993) + +### Dependency Updates + +- Bump actions/checkout from 3 to 4 ([#302](https://github.com/stefanzweifel/git-auto-commit-action/pull/302)) [@dependabot](https://github.com/@dependabot) +- Bump bats from 1.9.0 to 1.10.0 ([#293](https://github.com/stefanzweifel/git-auto-commit-action/pull/293)) [@dependabot](https://github.com/@dependabot) +- Bump github/super-linter from 4 to 5 ([#289](https://github.com/stefanzweifel/git-auto-commit-action/pull/289)) [@dependabot](https://github.com/@dependabot) +- Bump bats from 1.8.2 to 1.9.0 ([#282](https://github.com/stefanzweifel/git-auto-commit-action/pull/282)) [@dependabot](https://github.com/@dependabot) + ## [v4.16.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.4...v4.16.0) - 2022-12-02 ### Changed From eb38c210f2fc7b4533fe335ac7c74cbe8715ee5e Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 6 Oct 2023 19:56:27 +0200 Subject: [PATCH 02/13] Use v5 in update-changelog Workflow --- .github/workflows/update-changelog.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-changelog.yaml b/.github/workflows/update-changelog.yaml index 691e6dc3..1a03dfc7 100644 --- a/.github/workflows/update-changelog.yaml +++ b/.github/workflows/update-changelog.yaml @@ -27,7 +27,7 @@ jobs: latest-version: ${{ github.event.release.name }} - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: branch: master commit_message: Update CHANGELOG From 98d2782f49833831d777f51f3ada1d7ac3073f7d Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 6 Oct 2023 19:56:33 +0200 Subject: [PATCH 03/13] Use v5 in README --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9c2d9e0d..c72dcecd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Adding git-auto-commit to your Workflow only takes a couple lines of code. 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 +- uses: stefanzweifel/git-auto-commit-action@v5 ``` Your Workflow should look similar to this example. @@ -44,7 +44,7 @@ jobs: # Other steps that change files in the repository # Commit all changed files back to the repository - - uses: stefanzweifel/git-auto-commit-action@v4 + - uses: stefanzweifel/git-auto-commit-action@v5 ``` > **Note** @@ -53,7 +53,7 @@ jobs: The following is an extended example with all available options. ```yaml -- uses: stefanzweifel/git-auto-commit-action@v4 +- uses: stefanzweifel/git-auto-commit-action@v5 with: # Optional. Commit message for the created commit. # Defaults to "Apply automatic changes" @@ -151,7 +151,7 @@ jobs: - name: Run php-cs-fixer uses: docker://oskarstark/php-cs-fixer-ga - - uses: stefanzweifel/git-auto-commit-action@v4 + - uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Apply php-cs-fixer changes ``` @@ -258,7 +258,7 @@ The example below can be used as a starting point to generate a multiline commit # 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 + - uses: stefanzweifel/git-auto-commit-action@v5 id: commit with: commit_message: ${{ steps.commit_message_step.outputs.commit_message }} @@ -333,7 +333,7 @@ jobs: - name: Run php-cs-fixer uses: docker://oskarstark/php-cs-fixer-ga - - uses: stefanzweifel/git-auto-commit-action@v4 + - uses: stefanzweifel/git-auto-commit-action@v5 ``` ### Workflow should run in **forked** repository @@ -371,7 +371,7 @@ jobs: - name: Run php-cs-fixer uses: docker://oskarstark/php-cs-fixer-ga - - uses: stefanzweifel/git-auto-commit-action@v4 + - uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Apply php-cs-fixer changes ``` @@ -420,7 +420,7 @@ The steps in your workflow might look like this: run: | echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT -- uses: stefanzweifel/git-auto-commit-action@v4 +- uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: ${{ steps.last-commit-message.outputs.msg }} commit_options: '--amend --no-edit' @@ -465,7 +465,7 @@ You can learn more about Personal Access Token in the [GitHub documentation](htt 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. ```yaml - - uses: stefanzweifel/git-auto-commit-action@v4 + - uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Apply php-cs-fixer changes push_options: --force @@ -495,7 +495,7 @@ This is due to the fact, that the `*.md`-glob is expanded before sending it to ` To fix this add `disable_globbing: true` to your Workflow. ```yaml -- uses: stefanzweifel/git-auto-commit-action@v4 +- uses: stefanzweifel/git-auto-commit-action@v5 with: file_pattern: '*.md' disable_globbing: true @@ -523,7 +523,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@v5` 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 8036286d3751929c947d18324a45433db4ff357f Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 12 Dec 2023 20:38:06 +0100 Subject: [PATCH 04/13] Use new Markdown Alerts in README --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c72dcecd..9182c12f 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ jobs: - uses: stefanzweifel/git-auto-commit-action@v5 ``` -> **Note** +> [!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. @@ -282,13 +282,13 @@ See [this announcement from GitHub](https://github.blog/2020-08-03-github-action
Expand to learn more -> **Note** +> [!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** +> [!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.) @@ -338,7 +338,7 @@ jobs: ### Workflow should run in **forked** repository -> **Warning** +> [!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. @@ -397,7 +397,7 @@ For more information about running Actions on forks, see [this announcement from 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. -> **Warning** +> [!CAUTION] > 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`. @@ -458,7 +458,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** +> [!TIP] > 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. From 8d90676eefd6ee2df2214033002d76f2ce6b6989 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 12 Dec 2023 20:38:26 +0100 Subject: [PATCH 05/13] Little Doc Updates --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9182c12f..c8e0493c 100644 --- a/README.md +++ b/README.md @@ -270,9 +270,9 @@ Using command lines options needs to be done manually for each workflow which yo - [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer)) -### Push to forks from private repositories +### Use in 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. +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. @@ -461,8 +461,7 @@ You can learn more about Personal Access Token in the [GitHub documentation](htt > [!TIP] > 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. ```yaml - uses: stefanzweifel/git-auto-commit-action@v5 @@ -477,7 +476,7 @@ This is due to limitations set up by GitHub, [commits made by this Action do not ### 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. +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. From 2818fe7949d2daf9e2b5d7d808ca2ca11ccf70ad Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 12 Dec 2023 20:42:25 +0100 Subject: [PATCH 06/13] Add Alert about pull_request_target https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1837270114 --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c8e0493c..03340bf0 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,15 @@ However, there are a couple of ways to use this Actions in Workflows that should ### 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. +> [!CAUTION] +> The following section explains how you can use git-auto-commit in combination with the `pull_request_target` trigger. +> **Using `pull_request_target` in your workflows can lead to repository compromise as [mentioned](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) by GitHub's own security team. This means, that a bad actor could potentially leak/steal your GitHub Actions repository secrets.** +> Please be aware of this risk when using `pull_request_target` in your workflows. +> +> If your workflow runs code-fixing tools, consider running the workflow on your default branch by listening to the `push` event or use a third-party tool like [autofix.ci](https://autofix.ci/). +> We keep this documentation around, as many questions came in over the years, on how to use this action for public forks. + +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. From 29183a25ec7450c8f6fbab7ff22ccd42d8ab7416 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 12 Dec 2023 20:45:33 +0100 Subject: [PATCH 07/13] Remove outdated docs --- README.md | 66 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 03340bf0..040fc3b6 100644 --- a/README.md +++ b/README.md @@ -279,9 +279,6 @@ See [this announcement from GitHub](https://github.blog/2020-08-03-github-action ### Use in forks from public repositories -
-Expand to learn more - > [!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)) \ @@ -297,11 +294,11 @@ However, there are a couple of ways to use this Actions in Workflows that should ### Workflow should run in **base** repository > [!CAUTION] -> The following section explains how you can use git-auto-commit in combination with the `pull_request_target` trigger. -> **Using `pull_request_target` in your workflows can lead to repository compromise as [mentioned](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) by GitHub's own security team. This means, that a bad actor could potentially leak/steal your GitHub Actions repository secrets.** +> The following section explains how you can use git-auto-commit in combination with the `pull_request_target` trigger. +> **Using `pull_request_target` in your workflows can lead to repository compromise as [mentioned](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) by GitHub's own security team. This means, that a bad actor could potentially leak/steal your GitHub Actions repository secrets.** > Please be aware of this risk when using `pull_request_target` in your workflows. > -> If your workflow runs code-fixing tools, consider running the workflow on your default branch by listening to the `push` event or use a third-party tool like [autofix.ci](https://autofix.ci/). +> If your workflow runs code-fixing tools, consider running the workflow on your default branch by listening to the `push` event or use a third-party tool like [autofix.ci](https://autofix.ci/). > We keep this documentation around, as many questions came in over the years, on how to use this action for public forks. 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. @@ -344,65 +341,10 @@ jobs: - uses: stefanzweifel/git-auto-commit-action@v5 ``` -### 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). -2. GitHub Action has to be enabled on the forked repository. \ -For security reasons, GitHub does not automatically enable GitHub Actions on forks. The user has to explicitly enable GitHub Actions in the "Actions"-tab of the forked repository. (Mention this in your projects README or CONTRIBUTING.md!) - -After you have added the `pull_request_target` to your desired Workflow and the forked repository has enabled Actions and a new Pull Request is opened, the Workflow will run **on the forked repository**. - -Due to the fact that the Workflow is not run on the repository the Pull Request is opened in, you won't see any status indicators inside the Pull Request. - -#### Example - -The following workflow runs `php-cs-fixer` (a code linter and fixer for PHP) when a `pull_request` is opened. We've added the `pull_request_target`-trigger too, to make it work for forks. - -```yaml -name: Format PHP - -on: [push, pull_request, pull_request_target] - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Run php-cs-fixer - uses: docker://oskarstark/php-cs-fixer-ga - - - uses: stefanzweifel/git-auto-commit-action@v5 - with: - 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 **forked** repository and will push commits to the same branch. - -Here's how the Pull Request will look like: - -![Screenshot of a Pull Request from a Fork](https://user-images.githubusercontent.com/1080923/90955964-9c74c080-e482-11ea-8097-aa7f5161f50e.png) - - -As you can see, your contributors have to go through hoops to make this work. **For Workflows which run linters and fixers (like the example above) we recommend running them when a push happens on the `main`-branch.** - - For more information about running Actions on forks, see [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/). -
- ### Using `--amend` and `--no-edit` as commit options -
-Expand to learn more - 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. > [!CAUTION] @@ -438,8 +380,6 @@ The steps in your workflow might look like this: See discussion in [#159](https://github.com/stefanzweifel/git-auto-commit-action/issues/159#issuecomment-845347950) for details. -
- ## Troubleshooting ### Action does not push commit to repository From 12f68633e45c72459cd040c868605f2471c7f63b Mon Sep 17 00:00:00 2001 From: Nikita Panuhin Date: Sun, 24 Dec 2023 07:35:30 +0100 Subject: [PATCH 08/13] Clarify `commit_author` input option (#315) * Clarify `commit_author` input option * Update README.md --------- Co-authored-by: Stefan Zweifel --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 040fc3b6..49107a16 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,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 "41898282+github-actions[bot]@users.noreply.github.com" - commit_author: Author # defaults to author of the commit that triggered the run + commit_author: Author # defaults to "username ", where "username" belongs to the author of the commit that triggered the run # Optional. Tag name being created in the local repository and # pushed to remote repository and defined branch. @@ -353,6 +353,8 @@ If you would like to use this Action to create a commit using [`--amend`](https: 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. +By default, the commit author is changed to `username `, where `username` is the name of the user who triggered the workflow (The [`github.actor`](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) context is used here). If you want to preserve the name and email of the original author, you must extract them from the last commit and provide them to the Action through the `commit_author` input option. + Finally, you have to use `push_options: '--force'` to overwrite the git history on the GitHub remote repository. (git-auto-commit will not do a `git-rebase` for you!) The steps in your workflow might look like this: @@ -366,13 +368,15 @@ The steps in your workflow might look like this: # Other steps in your workflow to trigger a changed file - name: Get last commit message - id: last-commit-message + id: last-commit run: | - echo "msg=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT + echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT + echo "author=$(git log -1 --pretty=\"%an <%ae>\")" >> $GITHUB_OUTPUT - uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: ${{ steps.last-commit-message.outputs.msg }} + commit_author: ${{ steps.last-commit.outputs.author }} + commit_message: ${{ steps.last-commit.outputs.message }} commit_options: '--amend --no-edit' push_options: '--force' skip_fetch: true From 4d160c5e4d67c62e67f03ae49aa38359e964139a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 07:16:57 +0100 Subject: [PATCH 09/13] Bump release-drafter/release-drafter from 5 to 6 (#319) --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 6106be2d..1f36cb9d 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -15,6 +15,6 @@ jobs: contents: write steps: - - uses: release-drafter/release-drafter@v5 + - uses: release-drafter/release-drafter@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From e040c596f0a65570b339c60818081175bcf82d11 Mon Sep 17 00:00:00 2001 From: Philip Couling Date: Thu, 22 Feb 2024 07:26:06 +0000 Subject: [PATCH 10/13] Linux is not UNIX (#321) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49107a16..5eb57485 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ jobs: ``` > [!NOTE] -> The Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`). +> The Action has to be used in a Job that runs on a UNIX-like system (e.g. `ubuntu-latest`). The following is an extended example with all available options. From 9b5e5ee10a5c7b2e05d5f25da265a1c73b24e6a6 Mon Sep 17 00:00:00 2001 From: Christian Vermeulen Date: Fri, 15 Mar 2024 16:06:58 +0100 Subject: [PATCH 11/13] Add step id explanation for output in README.md (#324) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5eb57485..afd09f6c 100644 --- a/README.md +++ b/README.md @@ -167,9 +167,16 @@ You can use these outputs to trigger other Actions in your Workflow run based on - `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed. - `commit_hash`: Returns the full hash of the commit if one was created. +**⚠️ When using outputs, the step needs to be given an id. See example below.** + ### Example ```yaml + - uses: stefanzweifel/git-auto-commit-action@v5 + id: auto-commit-action #mandatory for the output to show up in ${{ steps }} + with: + commit_message: Apply php-cs-fixer changes + - name: "Run if changes have been detected" if: steps.auto-commit-action.outputs.changes_detected == 'true' run: echo "Changes!" From b0f4d47f590e46dfe55fea81b3b068cb0aab8678 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 08:29:07 +0100 Subject: [PATCH 12/13] Bump bats from 1.10.0 to 1.11.0 (#325) Bumps [bats](https://github.com/bats-core/bats-core) from 1.10.0 to 1.11.0. - [Release notes](https://github.com/bats-core/bats-core/releases) - [Changelog](https://github.com/bats-core/bats-core/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/bats-core/bats-core/compare/v1.10.0...v1.11.0) --- updated-dependencies: - dependency-name: bats dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 40c35d7a..d71dd690 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "devDependencies": { - "bats": "^1.10.0", + "bats": "^1.11.0", "bats-assert": "ztombol/bats-assert", "bats-support": "ztombol/bats-support" }, diff --git a/yarn.lock b/yarn.lock index 50212d43..65fc8101 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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.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== +bats@^1.11.0: + version "1.11.0" + resolved "https://registry.yarnpkg.com/bats/-/bats-1.11.0.tgz#40281f021f5befcc10da54ed5674aa5b181f4953" + integrity sha512-qiKdnS4ID3bJ1MaEOKuZe12R4w+t+psJF0ICj+UdkiHBBoObPMHv8xmD3w6F4a5qwUyZUHS+413lxENBNy8xcQ== From 8621497c8c39c72f3e2a999a26b4ca1b5058a842 Mon Sep 17 00:00:00 2001 From: Constantin Comendant Date: Thu, 11 Apr 2024 21:00:36 +0200 Subject: [PATCH 13/13] Fail if attempting to execute git commands in a directory that is not a git-repo. (#326) * Fail (and log message) if attempting to execute git commands in a directory that is not a git-repo. * Add Test * Code Formatting --------- Co-authored-by: Constantin Comendant Co-authored-by: Stefan Zweifel --- entrypoint.sh | 9 ++++++++- tests/git-auto-commit.bats | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6fe017a0..bff98e0e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -82,8 +82,15 @@ _git_is_dirty() { echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; + # capture stderr + gitStatusMessage="$((git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}} >/dev/null ) 2>&1)"; # shellcheck disable=SC2086 - [ -n "$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})" ] + gitStatus="$(git status -s $INPUT_STATUS_OPTIONS -- ${INPUT_FILE_PATTERN_EXPANDED:+${INPUT_FILE_PATTERN_EXPANDED[@]}})"; + if [ $? -ne 0 ]; then + _log "error" "git-status failed with:<$gitStatusMessage>"; + exit 1; + fi + [ -n "$gitStatus" ] } _switch_to_branch() { diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index daf5bc0b..d08597cc 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -8,6 +8,7 @@ setup() { export FAKE_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/tests_local_repository" export FAKE_REMOTE="${BATS_TEST_DIRNAME}/tests_remote_repository" export FAKE_TEMP_LOCAL_REPOSITORY="${BATS_TEST_DIRNAME}/tests_clone_of_remote_repository" + export FAKE_FOLDER_WITHOUT_GIT_REPO="/tmp/tests_folder_without_git_repo" # While it is likely the GitHub hosted runners will use master as the default branch, # locally anyone may change that. So for tests lets grab whatever is currently set @@ -58,6 +59,7 @@ teardown() { rm -rf "${FAKE_LOCAL_REPOSITORY}" rm -rf "${FAKE_REMOTE}" rm -rf "${FAKE_TEMP_LOCAL_REPOSITORY}" + rm -rf "${INPUT_REPOSITORY}" if [ -z ${GITHUB_OUTPUT+x} ]; then echo "GITHUB_OUTPUT is not set" @@ -1112,3 +1114,14 @@ END run git log -n 1 assert_output --partial $COMMIT_MESSAGE } + +@test "It exits with error message if entrypoint.sh is being run not in a git repository" { + INPUT_REPOSITORY="${FAKE_FOLDER_WITHOUT_GIT_REPO}" + + mkdir "${INPUT_REPOSITORY}" + + run git_auto_commit + + assert_failure; + assert_line "::error::git-status failed with:" +}