Skip to content

Commit 13a8443

Browse files
authored
Merge pull request #13 from planetscale/gha/self-test
2 parents 4452950 + e0fee5a commit 13a8443

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

.github/workflows/self-test.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: self-test
2+
3+
# Uncomment to run test on your branch, but keep in mind there will be an extra
4+
# commit added to your PR
5+
# on:
6+
# pull_request:
7+
8+
jobs:
9+
self-test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: modify some files
16+
run: |
17+
git mv README.md README.md.old
18+
echo 'test' >new.file
19+
20+
- name: ghcommit
21+
uses: ./
22+
with:
23+
commit_message: "test"
24+
repo: ${{ github.repository }}
25+
branch: ${{ github.head_ref || github.ref_name }}
26+
env:
27+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
28+
DEBUG: 1

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
# Run steps that make changes to the local repo here.
4343

4444
# Commit all changed files back to the repository
45-
- uses: planetscale/[email protected].5
45+
- uses: planetscale/[email protected].6
4646
with:
4747
commit_message: "🤖 fmt"
4848
repo: ${{ github.repository }}
@@ -56,7 +56,7 @@ jobs:
5656
Example showing all options:
5757
5858
```yaml
59-
- uses: planetscale/[email protected].5
59+
- uses: planetscale/[email protected].6
6060
with:
6161
commit_message: "🤖 fmt"
6262
repo: ${{ github.repository }}

entrypoint.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4+
[[ -n "${DEBUG:-}" ]] && set -x
45

56
COMMIT_MESSAGE="${1:?Missing commit_message input}"
67
REPO="${2:?Missing repo input}"
@@ -15,8 +16,7 @@ deletes=()
1516

1617
# shellcheck disable=SC2086
1718
while IFS= read -r -d $'\0' line; do
18-
# Uncomment for debugging:
19-
#echo "line: '$line'"
19+
[[ -n "${DEBUG:-}" ]] && echo "line: '$line'"
2020

2121
# Extract the status in the tree and status in the index (first two characters)
2222
index_status="${line:0:1}"
@@ -25,15 +25,15 @@ while IFS= read -r -d $'\0' line; do
2525
# Renamed files have status code 'R' and two filenames separated by NUL. We need to read
2626
# an additional chunk (up to the next NUL) to get the new filename.
2727
if [[ "$index_status" == "R" || "$tree_status" == "R" ]]; then
28-
IFS= read -r -d $'\0' new_filename
29-
filename="${line:3}"
28+
IFS= read -r -d $'\0' old_filename
29+
new_filename="${line:3}"
3030

3131
echo "Renamed file detected:"
32-
echo "Old Filename: $filename"
32+
echo "Old Filename: $old_filename"
3333
echo "New Filename: $new_filename"
3434
echo "-----------------------------"
3535
adds+=("$new_filename")
36-
deletes+=("$filename")
36+
deletes+=("$old_filename")
3737
continue
3838
fi
3939

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

76+
[[ -n "${DEBUG:-}" ]] && echo "ghcommit args: '${ghcommit_args[*]}'"
77+
7678
ghcommit "${ghcommit_args[@]}"

tests/fixtures/git-status.out-1

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)