Skip to content

Commit

Permalink
Merge pull request #13 from planetscale/gha/self-test
Browse files Browse the repository at this point in the history
  • Loading branch information
joemiller authored Jun 22, 2023
2 parents 4452950 + e0fee5a commit 13a8443
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/self-test.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
14 changes: 8 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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}"
Expand All @@ -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

Expand Down Expand Up @@ -73,4 +73,6 @@ fi
ghcommit_args+=("${adds[@]/#/--add=}")
ghcommit_args+=("${deletes[@]/#/--delete=}")

[[ -n "${DEBUG:-}" ]] && echo "ghcommit args: '${ghcommit_args[*]}'"

ghcommit "${ghcommit_args[@]}"
Binary file modified tests/fixtures/git-status.out-1
Binary file not shown.

0 comments on commit 13a8443

Please sign in to comment.