Compare commits

...

10 Commits

Author SHA1 Message Date
ZeroRin
3ea6ae190b Fix "nothing to commit" error with LF/CRLF changes #241 (#265)
* fix crlf test

* add diff check before commit

* add dirty check flag (not sure if needed)

* Update test name and add more assertions

Update test name to make it clear that the Action no longer fails to detect CRLF changes.

* Add Comment to explain why we use git-diff again

* Add test to confirm content changes are commited

* Closes #241 

Co-authored-by: Stefan Zweifel <hello@stefanzweifel.io>
2022-12-01 20:47:06 +01:00
Teko
976f22029f Fix github-actions[bot] email address (#264) 2022-11-15 20:12:31 +01:00
Teko
ebb5756042 Fix link and text for workflow limitation (#263) 2022-11-13 10:06:41 +01:00
stefanzweifel
3dce995a13 Update CHANGELOG 2022-11-05 10:56:08 +00:00
Stefan Zweifel
0b007fbd11 Let Action fail if git binary can't be located (#261)
* Check if git binary exists

* Add Tests
2022-11-05 11:53:46 +01:00
dependabot[bot]
7106b2184a Bump github/super-linter from 3 to 4 (#258)
Bumps [github/super-linter](https://github.com/github/super-linter) from 3 to 4.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v3...v4)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:05:48 +02:00
dependabot[bot]
f166130208 Bump bats from 1.7.0 to 1.8.2 (#259)
Bumps [bats](https://github.com/bats-core/bats-core) from 1.7.0 to 1.8.2.
- [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.7.0...v1.8.2)

---
updated-dependencies:
- dependency-name: bats
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:04:33 +02:00
dependabot[bot]
021a6363fa Bump actions/checkout from 2 to 3 (#257)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-26 19:03:57 +02:00
Stefan Zweifel
38864a638f Create dependabot.yml 2022-10-26 19:02:41 +02:00
stefanzweifel
393fea59ef Update CHANGELOG 2022-10-26 16:57:18 +00:00
12 changed files with 135 additions and 26 deletions

10
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Use git-auto-commit-action - name: Use git-auto-commit-action
id: "auto-commit-action" id: "auto-commit-action"

View File

@@ -9,10 +9,10 @@ jobs:
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Lint Code Base - name: Lint Code Base
uses: github/super-linter@v3 uses: github/super-linter@v4
env: env:
VALIDATE_ALL_CODEBASE: false VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: false VALIDATE_MARKDOWN: false

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Install testing dependencies - name: Install testing dependencies
run: yarn install run: yarn install

View File

@@ -10,7 +10,7 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
ref: master ref: master

View File

@@ -5,10 +5,28 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.2...HEAD) ## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.4...HEAD)
> TBD > TBD
## [v4.15.4](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.3...v4.15.4) - 2022-11-05
### Fixed
- Let Action fail if git binary can't be located ([#261](https://github.com/stefanzweifel/git-auto-commit-action/pull/261)) [@stefanzweifel](https://github.com/@stefanzweifel)
### Dependency Updates
- Bump github/super-linter from 3 to 4 ([#258](https://github.com/stefanzweifel/git-auto-commit-action/pull/258)) [@dependabot](https://github.com/@dependabot)
- Bump bats from 1.7.0 to 1.8.2 ([#259](https://github.com/stefanzweifel/git-auto-commit-action/pull/259)) [@dependabot](https://github.com/@dependabot)
- Bump actions/checkout from 2 to 3 ([#257](https://github.com/stefanzweifel/git-auto-commit-action/pull/257)) [@dependabot](https://github.com/@dependabot)
## [v4.15.3](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.2...v4.15.3) - 2022-10-26
### Changed
- Use deprecated set-output syntax if GITHUB_OUTPUT environment is not available ([#255](https://github.com/stefanzweifel/git-auto-commit-action/pull/255)) [@stefanzweifel](https://github.com/@stefanzweifel)
## [v4.15.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.1...v4.15.2) - 2022-10-22 ## [v4.15.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.15.1...v4.15.2) - 2022-10-22
### Changed ### Changed

View File

@@ -53,7 +53,7 @@ The following is an extended example with all available options.
# Optional commit user and author settings # Optional commit user and author settings
commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]" commit_user_name: My GitHub Actions Bot # defaults to "github-actions[bot]"
commit_user_email: my-github-actions-bot@example.org # defaults to "github-actions[bot]@users.noreply.github.com" commit_user_email: my-github-actions-bot@example.org # defaults to "41898282+github-actions[bot]@users.noreply.github.com"
commit_author: Author <actions@github.com> # defaults to author of the commit that triggered the run commit_author: Author <actions@github.com> # defaults to author of the commit that triggered the run
# Optional. Tag name being created in the local repository and # Optional. Tag name being created in the local repository and
@@ -399,7 +399,7 @@ If you go the "force pushes" route, you have to enable force pushes to a protect
### No new workflows are triggered by the commit of this action ### No new workflows are triggered by the commit of this action
This is due to limitations set up by GitHub, [commits of this Action do not trigger new Workflow runs](#commits-of-this-action-do-not-trigger-new-workflow-runs). This is due to limitations set up by GitHub, [commits made by this Action do not trigger new Workflow runs](#commits-made-by-this-action-do-not-trigger-new-workflow-runs).
### Pathspec 'x' did not match any files ### Pathspec 'x' did not match any files

View File

@@ -39,7 +39,7 @@ inputs:
commit_user_email: commit_user_email:
description: Email address used for the commit user description: Email address used for the commit user
required: false required: false
default: github-actions[bot]@users.noreply.github.com default: 41898282+github-actions[bot]@users.noreply.github.com
commit_author: commit_author:
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run. description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
required: false required: false
@@ -70,6 +70,9 @@ inputs:
create_branch: create_branch:
description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet. description: Create new branch with the name of `branch`-input in local and remote repository, if it doesn't exist yet.
default: false default: false
internal_git_binary:
description: Internal use only! Path to git binary used to check if git is available. (Don't change this!)
default: git
outputs: outputs:
changes_detected: changes_detected:

View File

@@ -7,6 +7,8 @@ if "$INPUT_DISABLE_GLOBBING"; then
fi fi
_main() { _main() {
_check_if_git_is_available
_switch_to_repository _switch_to_repository
if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then if _git_is_dirty || "$INPUT_SKIP_DIRTY_CHECK"; then
@@ -23,11 +25,28 @@ _main() {
_add_files _add_files
_local_commit # Check dirty state of repo again using git-diff.
# (git-diff detects beter if CRLF of files changes and does NOT
# proceed, if only CRLF changes are detected. See #241 and #265
# for more details.)
if [ -n "$(git diff --staged)" ] || "$INPUT_SKIP_DIRTY_CHECK"; then
_local_commit
_tag_commit _tag_commit
_push_to_github _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
echo "Working tree clean. Nothing to commit.";
fi
else else
# Check if $GITHUB_OUTPUT is available # Check if $GITHUB_OUTPUT is available
@@ -42,6 +61,14 @@ _main() {
fi fi
} }
_check_if_git_is_available() {
if hash -- "$INPUT_INTERNAL_GIT_BINARY" 2> /dev/null; then
echo "::debug::git binary found.";
else
echo "::error ::git-auto-commit could not find git binary. Please make sure git is available."
exit 1;
fi
}
_switch_to_repository() { _switch_to_repository() {
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY"; echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";

View File

@@ -1,6 +1,6 @@
{ {
"devDependencies": { "devDependencies": {
"bats": "^1.1.0", "bats": "^1.8.2",
"bats-assert": "ztombol/bats-assert", "bats-assert": "ztombol/bats-assert",
"bats-support": "ztombol/bats-support" "bats-support": "ztombol/bats-support"
}, },

View File

@@ -37,6 +37,7 @@ setup() {
export INPUT_SKIP_CHECKOUT=false export INPUT_SKIP_CHECKOUT=false
export INPUT_DISABLE_GLOBBING=false export INPUT_DISABLE_GLOBBING=false
export INPUT_CREATE_BRANCH=false export INPUT_CREATE_BRANCH=false
export INPUT_INTERNAL_GIT_BINARY=git
# Set GitHub environment variables used by the GitHub Action # Set GitHub environment variables used by the GitHub Action
temp_github_output_file=$(mktemp -t github_output_test.XXXXX) temp_github_output_file=$(mktemp -t github_output_test.XXXXX)
@@ -973,7 +974,7 @@ cat_github_output() {
assert_line --partial "another-subdirectory/new-file-3.txt" assert_line --partial "another-subdirectory/new-file-3.txt"
} }
@test "fails to detect crlf change in files and does not detect change or commit changes" { @test "detects if crlf in files change and does not create commit" {
# Set autocrlf to true # Set autocrlf to true
cd "${FAKE_LOCAL_REPOSITORY}" cd "${FAKE_LOCAL_REPOSITORY}"
git config core.autocrlf true git config core.autocrlf true
@@ -981,26 +982,65 @@ cat_github_output() {
assert_line "true" assert_line "true"
# Add more .txt files # Add more .txt files
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to add new files to repository # Run git-auto-commit to add new files to repository
run git_auto_commit run git_auto_commit
# Change control characters in files # Change control characters in files
sed 's/^M$//' "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
sed 's/$/^M/' "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to commit the 2 changes files # Run git-auto-commit to commit the 2 changes files
run git_auto_commit run git_auto_commit
assert_success assert_success
# Changes are not detected refute_line --partial "2 files changed, 2 insertions(+), 2 deletions(-)"
assert_line --partial "Working tree clean. Nothing to commit." assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
refute_line --partial "new-file-2.txt" assert_line --partial "Working tree clean. Nothing to commit."
refute_line --partial "new-file-3.txt" assert_line --partial "new-file-2.txt"
assert_line --partial "new-file-3.txt"
# Changes are not detected
run cat_github_output
assert_line "changes_detected=false"
}
@test "detects if crlf in files change and creates commit if the actual content of the files change" {
# Set autocrlf to true
cd "${FAKE_LOCAL_REPOSITORY}"
git config core.autocrlf true
run git config --get-all core.autocrlf
assert_line "true"
# Add more .txt files
echo -ne "crlf test1\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
echo -ne "crlf test1\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to add new files to repository
run git_auto_commit
# Change control characters in files
echo -ne "crlf test2\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-2.txt
echo -ne "crlf test2\r\n" > "${FAKE_LOCAL_REPOSITORY}"/new-file-3.txt
# Run git-auto-commit to commit the 2 changes files
run git_auto_commit
assert_success
assert_line --partial "2 files changed, 2 insertions(+), 2 deletions(-)"
assert_line --partial "warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
assert_line --partial "new-file-2.txt"
assert_line --partial "new-file-3.txt"
# Changes are detected
run cat_github_output
assert_line "changes_detected=true"
} }
@@ -1041,3 +1081,14 @@ cat_github_output() {
assert_line "::set-output name=changes_detected::false" assert_line "::set-output name=changes_detected::false"
refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$" refute_line -e "::set-output name=commit_hash::[0-9a-f]{40}$"
} }
@test "It fails hard if git is not available" {
INPUT_INTERNAL_GIT_BINARY=binary-does-not-exist
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
run git_auto_commit
assert_failure;
assert_line "::error ::git-auto-commit could not find git binary. Please make sure git is available."
}

View File

@@ -10,7 +10,7 @@ bats-support@ztombol/bats-support:
version "0.3.0" version "0.3.0"
resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee" resolved "https://codeload.github.com/ztombol/bats-support/tar.gz/004e707638eedd62e0481e8cdc9223ad471f12ee"
bats@^1.1.0: bats@^1.8.2:
version "1.7.0" version "1.8.2"
resolved "https://registry.yarnpkg.com/bats/-/bats-1.7.0.tgz#caae958b1d211eda6b1322ac7792515de40165a2" resolved "https://registry.yarnpkg.com/bats/-/bats-1.8.2.tgz#bdbaa7690a18f04291b35144a8ce5435cffb8dc5"
integrity sha512-pt5zjJQUB4+JI8Si+z/IAWc8yhMyhdZs6IXMCKgzF768dUIyW5xyBstWtDI5uGSa80v7UQOhh+w0GA4p4+01Bg== integrity sha512-KLUIaPYuIMjqui8MbZmK84+CiwhjFVFAhFy5PXP0prLbkovc5faVzc+Qaowbz76F97zP573JrF31ODFAH7vzhg==