From 52f4cc8a95885c3d8b219c6ba1149aef76b434a1 Mon Sep 17 00:00:00 2001 From: joe miller Date: Thu, 22 Jun 2023 14:08:20 +0000 Subject: [PATCH 1/3] ci: add GHA self-test workflow --- .github/workflows/self-test.yaml | 26 ++++++++++++++++++++++++++ entrypoint.sh | 6 ++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/self-test.yaml diff --git a/.github/workflows/self-test.yaml b/.github/workflows/self-test.yaml new file mode 100644 index 0000000..d2d52b9 --- /dev/null +++ b/.github/workflows/self-test.yaml @@ -0,0 +1,26 @@ +name: self-test + +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/entrypoint.sh b/entrypoint.sh index 6987f2d..5b5be57 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}" @@ -73,4 +73,6 @@ fi ghcommit_args+=("${adds[@]/#/--add=}") ghcommit_args+=("${deletes[@]/#/--delete=}") +[[ -n "${DEBUG:-}" ]] && echo "ghcommit args: '${ghcommit_args[*]}'" + ghcommit "${ghcommit_args[@]}" From c42e3a7de69a0b479b3ddf073eded347545bb872 Mon Sep 17 00:00:00 2001 From: joe miller Date: Thu, 22 Jun 2023 14:16:20 +0000 Subject: [PATCH 2/3] fix: inverted old/new filename detection in rename handling `git status` reverses the order of filenames when the `-z` option is used: ```console $ git mv README.md README.md.new $ g status -s --porcelain=v1 -- . R README.md -> README.md.old $ g status -s --porcelain=v1 -z -- . | cat -tve R README.md.old^@README.md^@ ``` --- README.md | 4 ++-- entrypoint.sh | 8 ++++---- tests/fixtures/git-status.out-1 | Bin 87 -> 87 bytes 3 files changed, 6 insertions(+), 6 deletions(-) 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 5b5be57..f655121 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 diff --git a/tests/fixtures/git-status.out-1 b/tests/fixtures/git-status.out-1 index d61b1a9ff882edc6a81b686cc1e7a582d48f34b3..36fd3bb13672b230c9a5c33df321b153bf27c833 100644 GIT binary patch delta 20 bcmWF!pCHYXms+lumYI{vke`z>QQZIlMiK_4 delta 20 bcmWF!pCHYXpOd1OmYI{vke6CMQQZIlMXv^> From e0fee5ae6d3cb766b020b4f0dc6e77788b58dd1e Mon Sep 17 00:00:00 2001 From: joe miller Date: Thu, 22 Jun 2023 14:20:09 +0000 Subject: [PATCH 3/3] ci: disable self-test workflow --- .github/workflows/self-test.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/self-test.yaml b/.github/workflows/self-test.yaml index d2d52b9..967dc5d 100644 --- a/.github/workflows/self-test.yaml +++ b/.github/workflows/self-test.yaml @@ -1,7 +1,9 @@ name: self-test -on: - pull_request: +# 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: