diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 69cfc0b3..6b9b1759 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -12,7 +12,7 @@ categories: - 'changelog:changed' - title: Deprecated labels: - - 'changelog:deprecated ' + - 'changelog:deprecated' - title: Removed labels: - 'changelog:removed' diff --git a/.github/workflows/git-auto-commit.yml b/.github/workflows/git-auto-commit.yml index 038521e4..d7db234d 100644 --- a/.github/workflows/git-auto-commit.yml +++ b/.github/workflows/git-auto-commit.yml @@ -10,17 +10,22 @@ jobs: git-auto-commit: runs-on: ubuntu-latest + permissions: + # Give the default GITHUB_TOKEN write permission. + # https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ + contents: write + steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use git-auto-commit-action id: "auto-commit-action" uses: ./ - name: "no changes detected" - if: steps.auto-commit-action.outputs.changes_detected == false + if: steps.auto-commit-action.outputs.changes_detected == 'false' run: "echo \"No changes detected\"" - name: "changes detected" - if: steps.auto-commit-action.outputs.changes_detected == true + if: steps.auto-commit-action.outputs.changes_detected == 'true' run: "echo \"Changes detected\"" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index a01cc3fa..e355374d 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -9,10 +9,10 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Lint Code Base - uses: github/super-linter@v4 + uses: github/super-linter@v5 env: VALIDATE_ALL_CODEBASE: false VALIDATE_MARKDOWN: false diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 17fdb961..6106be2d 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -8,6 +8,12 @@ on: jobs: update_release_draft: runs-on: ubuntu-latest + + permissions: + # Give the default GITHUB_TOKEN write permission. + # https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ + contents: write + steps: - uses: release-drafter/release-drafter@v5 env: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 48f3a84b..35ee1e2c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install testing dependencies run: yarn install diff --git a/.github/workflows/update-changelog.yaml b/.github/workflows/update-changelog.yaml index a5d65093..691e6dc3 100644 --- a/.github/workflows/update-changelog.yaml +++ b/.github/workflows/update-changelog.yaml @@ -8,9 +8,15 @@ jobs: update: runs-on: ubuntu-latest + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # updated CHANGELOG back to the repository. + # https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ + contents: write + steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: master diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml index ad052193..04b1f87c 100644 --- a/.github/workflows/versioning.yml +++ b/.github/workflows/versioning.yml @@ -7,6 +7,12 @@ on: jobs: actions-tagger: runs-on: windows-latest + + permissions: + # Give the default GITHUB_TOKEN write permission. + # https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ + contents: write + steps: - uses: Actions-R-Us/actions-tagger@latest env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8238615a..3658910a 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.15.4...HEAD) +## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.16.0...HEAD) > TBD +## [v4.16.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.4...v4.16.0) - 2022-12-02 + +### Changed + +- Don't commit files when only LF/CRLF changes ([#265](https://github.com/stefanzweifel/git-auto-commit-action/pull/265)) [@ZeroRin](https://github.com/@ZeroRin) +- Update default email address of github-actions[bot] ([#264](https://github.com/stefanzweifel/git-auto-commit-action/pull/264)) [@Teko012](https://github.com/@Teko012) + +### Fixed + +- Fix link and text for workflow limitation ([#263](https://github.com/stefanzweifel/git-auto-commit-action/pull/263)) [@Teko012](https://github.com/@Teko012) + ## [v4.15.4](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.3...v4.15.4) - 2022-11-05 ### Fixed diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index ed87d512..9cd1debc 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -55,7 +55,7 @@ further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at hello@stefanzweifel.io. All +reported by contacting the project team at stefan@stefanzweifel.dev. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. diff --git a/README.md b/README.md index b2497660..9c2d9e0d 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,42 @@ If you want to learn more how this Action works under the hood, check out [this ## Usage -Add the following step at the end of your job, after other steps that might add or change files. +Adding git-auto-commit to your Workflow only takes a couple lines of code. + +1. Set the `contents`-permission of the default GITHUB_TOKEN to `true`. (Required to push new commits to the repository) +2. Add the following step at the end of your job, after other steps that might add or change files. ```yaml - uses: stefanzweifel/git-auto-commit-action@v4 ``` -Note that the Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`). -If you don't use the default permission of the GITHUB_TOKEN, give the Job or Workflow at least the `contents: write` permission. +Your Workflow should look similar to this example. + +```yaml +name: Format + +on: push + +jobs: + format-code: + runs-on: ubuntu-latest + + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + + steps: + - uses: actions/checkout@v4 + + # Other steps that change files in the repository + + # Commit all changed files back to the repository + - uses: stefanzweifel/git-auto-commit-action@v4 +``` + +> **Note** +> The Action has to be used in a Job that runs on a UNIX system (e.g. `ubuntu-latest`). The following is an extended example with all available options. @@ -111,8 +139,12 @@ jobs: php-cs-fixer: runs-on: ubuntu-latest + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository. + contents: write + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} @@ -169,7 +201,7 @@ You must use `action/checkout@v2` or later versions to check out the repository. In non-`push` events, such as `pull_request`, make sure to specify the `ref` to check out: ```yaml -- uses: actions/checkout@v2 +- uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} ``` @@ -187,7 +219,7 @@ You can change this by creating a new [Personal Access Token (PAT)](https://gith storing the token as a secret in your repository and then passing the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step. ```yaml -- uses: actions/checkout@v2 +- uses: actions/checkout@v4 with: token: ${{ secrets.PAT }} ``` @@ -198,17 +230,66 @@ If you work in an organization and don't want to create a PAT from your personal ### Change to file is not detected -Does your workflow change a file but "git-auto-commit" does not detect the change? Check the `.gitignore` that applies to the respective file. You might have accidentally marked the file to be ignored by git. +Does your workflow change a file, but "git-auto-commit" does not detect the change? Check the `.gitignore` that applies to the respective file. You might have accidentally marked the file to be ignored by git. ## Advanced Uses +### Multiline Commit Messages + +If your commit message should span multiple lines, you have to create a separate step to generate the string. + +The example below can be used as a starting point to generate a multiline commit meesage. Learn more how multiline strings in GitHub Actions work in the [GitHub documentation](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings). + +```yaml + # Building a multiline commit message + # Adjust to your liking + - run: echo "Commit Message 1" >> commitmessage.txt + - run: echo "Commit Message 2" >> commitmessage.txt + - run: echo "Commit Message 3" >> commitmessage.txt + + # Create a multiline string to be used by the git-auto-commit Action + - name: Set commit message + id: commit_message_step + run: | + echo 'commit_message<> $GITHUB_OUTPUT + cat commitmessage.txt >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + # Quick and dirty step to get rid of the temporary file holding the commit message + - run: rm -rf commitmessage.txt + + - uses: stefanzweifel/git-auto-commit-action@v4 + id: commit + with: + commit_message: ${{ steps.commit_message_step.outputs.commit_message }} +``` + +### Signing Commits & Other Git Command Line Options + +Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regularly. + +- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer)) + +### Push to forks from private repositories + +By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings. + +See [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) or the [GitHub docs](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) for details. + + +### Use in forks from public repositories +
-Use in forks from public repositories +Expand to learn more -**☝️ Important Notice**: This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\ -If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch. +> **Note** +> This Action technically works with forks. However, please note that the combination of triggers and their options can cause issues. Please read [the documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) on which triggers GitHub Actions support.\ +> Ensure your contributors enable "Allow edits by maintainers" when opening a pull request. ([Learn more](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)) \ +> \ +> **If you use this Action in combination with a linter/fixer, it's easier if you run the Action on `push` on your `main`-branch.** ---- +> **Warning** +> Due to limitations of GitHub, this Action currently can't push commits to a base repository, if the fork _lives_ under an organisation. See [github/community#6634](https://github.com/orgs/community/discussions/5634) and [this comment](https://github.com/stefanzweifel/git-auto-commit-action/issues/211#issuecomment-1428849944) for details. By default, this Action will not run on Pull Requests which have been opened by forks. (This is a limitation by GitHub, not by us.) However, there are a couple of ways to use this Actions in Workflows that should be triggered by forked repositories. @@ -234,10 +315,19 @@ on: jobs: php-cs-fixer: runs-on: ubuntu-latest + permissions: + contents: write + steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: + # Checkout the fork/head-repository and push changes to the fork. + # If you skip this, the base repository will be checked out and changes + # will be committed to the base repository! repository: ${{ github.event.pull_request.head.repo.full_name }} + + # Checkout the branch made in the fork. Will automatically push changes + # back to this branch. ref: ${{ github.head_ref }} - name: Run php-cs-fixer @@ -248,6 +338,11 @@ jobs: ### Workflow should run in **forked** repository +> **Warning** +> **This part of the documentation is outdated.** +> We were not able to configure a GitHub Action workflow for forks, that the workflow would run in the fork / head repository. +> Please let us know in the [discussions](https://github.com/stefanzweifel/git-auto-commit-action/discussions)-area, if and how you achieved that. + If the workflow should run in the forked repository, follow these steps: 1. In addition to listening to the `pull_request` event in your Workflow triggers, you have to add an additional event: `pull_request_target`. You can learn more about this event in [the GitHub docs](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target). @@ -271,7 +366,7 @@ jobs: php-cs-fixer: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Run php-cs-fixer uses: docker://oskarstark/php-cs-fixer-ga @@ -295,37 +390,15 @@ For more information about running Actions on forks, see [this announcement from
-
-Push to forks from private repositories - -By default, GitHub Actions doesn't run Workflows on forks from private repositories. To enable Actions for **private** repositories enable "Run workflows from pull requests" in your repository settings. - -See [this announcement from GitHub](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) or the [GitHub docs](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) for details. - -
- -
- - Signing Commits & Other Git Command Line Options - - -Using command lines options needs to be done manually for each workflow which you require the option enabled. So for example signing commits requires you to import the gpg signature each and every time. The following list of actions are worth checking out if you need to automate these tasks regularly. - -- [Import GPG Signature](https://github.com/crazy-max/ghaction-import-gpg) (Suggested by [TGTGamer](https://github.com/tgtgamer)) - -
+### Using `--amend` and `--no-edit` as commit options
- - 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. -**☝️ Important Notice:** You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase) +> **Warning** +> You should understand the implications of rewriting history if you amend a commit that has already been published. [See rebasing](https://git-scm.com/docs/git-rebase#_recovering_from_upstream_rebase). First, you need to extract the previous commit message by using `git log -1 --pretty=%s`. Then you need to provide this last commit message to the Action through the `commit_message` input option. @@ -335,7 +408,7 @@ Finally, you have to use `push_options: '--force'` to overwrite the git history The steps in your workflow might look like this: ```yaml -- uses: actions/checkout@master +- uses: actions/checkout@4 with: # Fetch the last 2 commits instead of just 1. (Fetching just 1 commit would overwrite the whole history) fetch-depth: 2 @@ -379,13 +452,14 @@ First, you have to create a new [Personal Access Token (PAT)](https://github.com store the token as a secret in your repository and pass the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action step. ```yaml -- uses: actions/checkout@v2 +- uses: actions/checkout@v4 with: token: ${{ secrets.PAT }} ``` You can learn more about Personal Access Token in the [GitHub documentation](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). -**Note:** If you're working in an organisation, and you don't want to create the PAT from your personal account, we recommend using a bot-account for such tokens. +> **Note** +> If you're working in an organisation, and you don't want to create the PAT from your personal account, we recommend using a bot-account for such tokens. If you go the "force pushes" route, you have to enable force pushes to a protected branch (See [documentation](https://help.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)) and update your Workflow to use force push like this. diff --git a/action.yml b/action.yml index afc4bf2b..8192c950 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ name: Git Auto Commit description: 'Automatically commits files which have been changed during the workflow run and push changes back to remote repository.' -author: Stefan Zweifel +author: Stefan Zweifel inputs: commit_message: @@ -81,7 +81,7 @@ outputs: description: Full hash of the created commit. Only present if the "changes_detected" output is "true". runs: - using: 'node16' + using: 'node20' main: 'index.js' branding: diff --git a/entrypoint.sh b/entrypoint.sh index 3c858317..6fe017a0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,6 +6,26 @@ if "$INPUT_DISABLE_GLOBBING"; then set -o noglob; fi +_set_github_output() { + local name=${1} + local value=${2} + + # Check if $GITHUB_OUTPUT is available + # (Feature detection will be removed in spring 2023) + if [ -z ${GITHUB_OUTPUT+x} ]; then + echo "::set-output name=$name::$value"; + else + echo "$name=$value" >> $GITHUB_OUTPUT; + fi +} + +_log() { + local level=${1} + local message=${2} + + echo "::$level::$message"; +} + _main() { _check_if_git_is_available @@ -13,20 +33,14 @@ _main() { if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then - # Check if $GITHUB_OUTPUT is available - # (Feature detection will be removed in late December 2022) - if [ -z ${GITHUB_OUTPUT+x} ]; then - echo "::set-output name=changes_detected::true"; - else - echo "changes_detected=true" >> $GITHUB_OUTPUT; - fi + _set_github_output "changes_detected" "true" _switch_to_branch _add_files # Check dirty state of repo again using git-diff. - # (git-diff detects beter if CRLF of files changes and does NOT + # (git-diff detects better if CRLF of files changes and does NOT # proceed, if only CRLF changes are detected. See #241 and #265 # for more details.) if [ -n "$(git diff --staged)" ] || "$INPUT_SKIP_DIRTY_CHECK"; then @@ -36,26 +50,12 @@ _main() { _push_to_github else - - # Check if $GITHUB_OUTPUT is available - # (Feature detection will be removed in late December 2022) - if [ -z ${GITHUB_OUTPUT+x} ]; then - echo "::set-output name=changes_detected::false"; - else - echo "changes_detected=false" >> $GITHUB_OUTPUT; - fi + _set_github_output "changes_detected" "false" echo "Working tree clean. Nothing to commit."; fi else - - # Check if $GITHUB_OUTPUT is available - # (Feature detection will be removed in late December 2022) - if [ -z ${GITHUB_OUTPUT+x} ]; then - echo "::set-output name=changes_detected::false"; - else - echo "changes_detected=false" >> $GITHUB_OUTPUT; - fi + _set_github_output "changes_detected" "false" echo "Working tree clean. Nothing to commit."; fi @@ -63,9 +63,9 @@ _main() { _check_if_git_is_available() { if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then - echo "::debug::git binary found."; + _log "debug" "git binary found."; else - echo "::error ::git-auto-commit could not find git binary. Please make sure git is available." + _log "error" "git-auto-commit could not find git binary. Please make sure git is available." exit 1; fi } @@ -77,7 +77,7 @@ _switch_to_repository() { _git_is_dirty() { echo "INPUT_STATUS_OPTIONS: ${INPUT_STATUS_OPTIONS}"; - echo "::debug::Apply status options ${INPUT_STATUS_OPTIONS}"; + _log "debug" "Apply status options ${INPUT_STATUS_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; @@ -91,14 +91,14 @@ _switch_to_branch() { # Fetch remote to make sure that repo can be switched to the right branch. if "$INPUT_SKIP_FETCH"; then - echo "::debug::git-fetch has not been executed"; + _log "debug" "git-fetch will not be executed."; else git fetch --depth=1; fi # If `skip_checkout`-input is true, skip the entire checkout step. if "$INPUT_SKIP_CHECKOUT"; then - echo "::debug::git-checkout has not been executed"; + _log "debug" "git-checkout will not be executed."; else # Create new local branch if `create_branch`-input is true if "$INPUT_CREATE_BRANCH"; then @@ -114,7 +114,7 @@ _switch_to_branch() { _add_files() { echo "INPUT_ADD_OPTIONS: ${INPUT_ADD_OPTIONS}"; - echo "::debug::Apply add options ${INPUT_ADD_OPTIONS}"; + _log "debug" "Apply add options ${INPUT_ADD_OPTIONS}"; echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"; read -r -a INPUT_FILE_PATTERN_EXPANDED <<< "$INPUT_FILE_PATTERN"; @@ -125,7 +125,7 @@ _add_files() { _local_commit() { echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"; - echo "::debug::Apply commit options ${INPUT_COMMIT_OPTIONS}"; + _log "debug" "Apply commit options ${INPUT_COMMIT_OPTIONS}"; # shellcheck disable=SC2206 INPUT_COMMIT_OPTIONS_ARRAY=( $INPUT_COMMIT_OPTIONS ); @@ -140,14 +140,7 @@ _local_commit() { --author="$INPUT_COMMIT_AUTHOR" \ ${INPUT_COMMIT_OPTIONS:+"${INPUT_COMMIT_OPTIONS_ARRAY[@]}"}; - - # Check if $GITHUB_OUTPUT is available - # (Feature detection will be removed in late December 2022) - if [ -z ${GITHUB_OUTPUT+x} ]; then - echo "::set-output name=commit_hash::$(git rev-parse HEAD)"; - else - echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT; - fi + _set_github_output "commit_hash" $(git rev-parse HEAD) } _tag_commit() { @@ -155,7 +148,7 @@ _tag_commit() { if [ -n "$INPUT_TAGGING_MESSAGE" ] then - echo "::debug::Create tag $INPUT_TAGGING_MESSAGE"; + _log "debug" "Create tag $INPUT_TAGGING_MESSAGE"; git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE"; else echo "No tagging message supplied. No tag will be added."; @@ -165,7 +158,7 @@ _tag_commit() { _push_to_github() { echo "INPUT_PUSH_OPTIONS: ${INPUT_PUSH_OPTIONS}"; - echo "::debug::Apply push options ${INPUT_PUSH_OPTIONS}"; + _log "debug" "Apply push options ${INPUT_PUSH_OPTIONS}"; # shellcheck disable=SC2206 INPUT_PUSH_OPTIONS_ARRAY=( $INPUT_PUSH_OPTIONS ); @@ -175,15 +168,15 @@ _push_to_github() { # Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set if [ -n "$INPUT_TAGGING_MESSAGE" ] then - echo "::debug::git push origin --tags"; + _log "debug" "git push origin --tags"; git push origin --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"}; else - echo "::debug::git push origin"; + _log "debug" "git push origin"; git push origin ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"}; fi else - echo "::debug::Push commit to remote branch $INPUT_BRANCH"; + _log "debug" "Push commit to remote branch $INPUT_BRANCH"; git push --set-upstream origin "HEAD:$INPUT_BRANCH" --follow-tags --atomic ${INPUT_PUSH_OPTIONS:+"${INPUT_PUSH_OPTIONS_ARRAY[@]}"}; fi } diff --git a/package.json b/package.json index b012db72..40c35d7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "devDependencies": { - "bats": "^1.8.2", + "bats": "^1.10.0", "bats-assert": "ztombol/bats-assert", "bats-support": "ztombol/bats-support" }, diff --git a/tests/git-auto-commit.bats b/tests/git-auto-commit.bats index ead4db75..daf5bc0b 100644 --- a/tests/git-auto-commit.bats +++ b/tests/git-auto-commit.bats @@ -259,7 +259,7 @@ cat_github_output() { } @test "It applies commit user and author settings" { - INPUT_COMMIT_USER_NAME="A Single Test" + INPUT_COMMIT_USER_NAME="Custom User Name" INPUT_COMMIT_USER_EMAIL="single-test@github.com" INPUT_COMMIT_AUTHOR="A Single Test " @@ -269,7 +269,7 @@ cat_github_output() { assert_success - assert_line "INPUT_COMMIT_USER_NAME: A Single Test" + assert_line "INPUT_COMMIT_USER_NAME: Custom User Name" assert_line "INPUT_COMMIT_USER_EMAIL: single-test@github.com" assert_line "INPUT_COMMIT_AUTHOR: A Single Test " assert_line "::debug::Push commit to remote branch ${FAKE_DEFAULT_BRANCH}" @@ -282,7 +282,7 @@ cat_github_output() { assert_output --partial "A Single Test" run git log -1 --pretty=format:'%cn' - assert_output --partial "A Single Test" + assert_output --partial "Custom User Name" run git log -1 --pretty=format:'%ce' assert_output --partial "single-test@github.com" @@ -417,7 +417,7 @@ cat_github_output() { assert_success - assert_line "::debug::git-fetch has not been executed" + assert_line "::debug::git-fetch will not be executed." } @test "If SKIP_CHECKOUT is true git-checkout will not be called" { @@ -430,7 +430,7 @@ cat_github_output() { assert_success - assert_line "::debug::git-checkout has not been executed" + assert_line "::debug::git-checkout will not be executed." } @test "It pushes generated commit and tag to remote and actually updates the commit shas" { @@ -1090,5 +1090,25 @@ cat_github_output() { run git_auto_commit assert_failure; - assert_line "::error ::git-auto-commit could not find git binary. Please make sure git is available." + assert_line "::error::git-auto-commit could not find git binary. Please make sure git is available." +} + +@test "It creates multi-line commit messages" { + touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt + + COMMIT_MESSAGE=$(cat <<-END + this commit message + has multiple lines +END +) + + INPUT_COMMIT_MESSAGE=$COMMIT_MESSAGE + + run git_auto_commit + + assert_success + + # Assert last commit was signed off + run git log -n 1 + assert_output --partial $COMMIT_MESSAGE } diff --git a/yarn.lock b/yarn.lock index dad53d06..50212d43 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.8.2: - version "1.8.2" - resolved "https://registry.yarnpkg.com/bats/-/bats-1.8.2.tgz#bdbaa7690a18f04291b35144a8ce5435cffb8dc5" - integrity sha512-KLUIaPYuIMjqui8MbZmK84+CiwhjFVFAhFy5PXP0prLbkovc5faVzc+Qaowbz76F97zP573JrF31ODFAH7vzhg== +bats@^1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/bats/-/bats-1.10.0.tgz#d22cb6e2d88fd39302167da237d710406d1587ce" + integrity sha512-yOQrC7npuCrN+Ic3TyjTjJlzHa0qlK3oEO6VAYPWwFeutx/GmpljIyB6uNSl/UTASyc2w4FgVuA/QMMf9OdsCw== pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy