diff --git a/.github/workflows/self-test.yaml b/.github/workflows/self-test.yaml new file mode 100644 index 0000000..967dc5d --- /dev/null +++ b/.github/workflows/self-test.yaml @@ -0,0 +1,28 @@ +name: self-test + +# Uncomment to run test on your branch, but keep in mind there will be an extra +# commit added to your PR +# on: +# pull_request: + +jobs: + self-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: modify some files + run: | + git mv README.md README.md.old + echo 'test' >new.file + + - name: ghcommit + uses: ./ + with: + commit_message: "test" + repo: ${{ github.repository }} + branch: ${{ github.head_ref || github.ref_name }} + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + DEBUG: 1 diff --git a/README.md b/README.md index 0e2a290..eaf0a68 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ jobs: # Run steps that make changes to the local repo here. # Commit all changed files back to the repository - - uses: planetscale/ghcommit-action@v0.1.5 + - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 fmt" repo: ${{ github.repository }} @@ -56,7 +56,7 @@ jobs: Example showing all options: ```yaml - - uses: planetscale/ghcommit-action@v0.1.5 + - uses: planetscale/ghcommit-action@v0.1.6 with: commit_message: "🤖 fmt" repo: ${{ github.repository }} diff --git a/entrypoint.sh b/entrypoint.sh index 6987f2d..f655121 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -euo pipefail +[[ -n "${DEBUG:-}" ]] && set -x COMMIT_MESSAGE="${1:?Missing commit_message input}" REPO="${2:?Missing repo input}" @@ -15,8 +16,7 @@ deletes=() # shellcheck disable=SC2086 while IFS= read -r -d $'\0' line; do - # Uncomment for debugging: - #echo "line: '$line'" + [[ -n "${DEBUG:-}" ]] && echo "line: '$line'" # Extract the status in the tree and status in the index (first two characters) index_status="${line:0:1}" @@ -25,15 +25,15 @@ while IFS= read -r -d $'\0' line; do # Renamed files have status code 'R' and two filenames separated by NUL. We need to read # an additional chunk (up to the next NUL) to get the new filename. if [[ "$index_status" == "R" || "$tree_status" == "R" ]]; then - IFS= read -r -d $'\0' new_filename - filename="${line:3}" + IFS= read -r -d $'\0' old_filename + new_filename="${line:3}" echo "Renamed file detected:" - echo "Old Filename: $filename" + echo "Old Filename: $old_filename" echo "New Filename: $new_filename" echo "-----------------------------" adds+=("$new_filename") - deletes+=("$filename") + deletes+=("$old_filename") continue fi @@ -73,4 +73,6 @@ fi ghcommit_args+=("${adds[@]/#/--add=}") ghcommit_args+=("${deletes[@]/#/--delete=}") +[[ -n "${DEBUG:-}" ]] && echo "ghcommit args: '${ghcommit_args[*]}'" + ghcommit "${ghcommit_args[@]}" diff --git a/tests/fixtures/git-status.out-1 b/tests/fixtures/git-status.out-1 index d61b1a9..36fd3bb 100644 Binary files a/tests/fixtures/git-status.out-1 and b/tests/fixtures/git-status.out-1 differ