Skip to content

Commit 7028080

Browse files
authored
feat: Use git-diff files and allow negative patterns (#97)
1 parent fe5ac81 commit 7028080

13 files changed

Lines changed: 4241 additions & 4617 deletions

File tree

.github/workflows/test.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ jobs:
2626
steps:
2727
- name: Checkout repo
2828
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29-
with:
30-
sparse-checkout: |
31-
dist
32-
src
33-
README.md
3429

3530
- name: Create test branch
3631
id: branch
@@ -44,8 +39,11 @@ jobs:
4439
run: |
4540
echo -e "\n### $(date -Iseconds)" | tee -a README.md
4641
date -Iseconds | tee date.txt
42+
date -Iseconds | tee test-ignore.txt
43+
echo "$GITHUB_RUN_ID" | tee __tests__/ignore/test-abcdef.txt
4744
echo "$GITHUB_RUN_ID" | tee src/test.txt
4845
echo "$GITHUB_RUN_ID" | tee src/test2.txt
46+
echo "uncommitted file" | tee blah.txt
4947
mkdir -p "$TEST_BRANCH"
5048
for i in {1..4}; do
5149
echo "$i-$GITHUB_RUN_ID" | tee "$TEST_BRANCH/$i-$GITHUB_RUN_ID"
@@ -60,19 +58,12 @@ jobs:
6058
files: |
6159
README.md
6260
date.txt
63-
src/test.txt
61+
!src/test.txt
6462
src/*.txt
63+
__tests__/**
64+
!${{ env.TEST_BRANCH }}/1-*
6565
${{ env.TEST_BRANCH }}/**
6666
67-
- name: Update test branch locally
68-
shell: bash
69-
run: |
70-
rm README.md
71-
rm date.txt
72-
rm src/*.txt
73-
rm -r "$TEST_BRANCH"
74-
git pull origin "$TEST_BRANCH"
75-
7667
- name: Verify GPG signature
7768
shell: bash
7869
env:
@@ -88,12 +79,22 @@ jobs:
8879
env:
8980
COMMIT: ${{ steps.commit.outputs.commit }}
9081
run: |
82+
git status
83+
9184
FILES=$(git diff-tree --no-commit-id --name-only -r "$COMMIT")
92-
echo "$FILES"
93-
if [ "$(wc -l <<< "$FILES")" -ne 8 ]; then
85+
echo -e "Changed files:\n$FILES"
86+
if [ "$(wc -l <<< "$FILES")" -ne 6 ]; then
9487
echo "::error::Unexpected changes in commit"
9588
exit 1
9689
fi
90+
echo
91+
92+
FILES=$(git diff --cached --name-only)
93+
echo -e "Unchanged files:\n$FILES"
94+
if [ "$(wc -l <<< "$FILES")" -ne 3 ]; then
95+
echo "::error::Unexpected uncommit changes"
96+
exit 1
97+
fi
9798
9899
- name: Delete test branch
99100
if: cancelled() == false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ __tests__/runner/*
101101
.idea
102102
.vscode
103103
*.code-workspace
104+
105+
test-ignore.txt

README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ A GitHub Action to create signed and verified commits as the
1414
accomplished via the GitHub [REST API] by using the [Blob] and [Tree] endpoints
1515
to build the commit and update the original Ref to point to it. [^1]
1616

17-
The resulting commit will be signed and verified using
18-
[GitHub's public PGP key](https://github.com/web-flow.gpg)!
17+
After using this Action your local branch will be updated to point to the newly
18+
created commit, which will be signed and verified using
19+
[GitHub's public PGP key](https://github.com/web-flow.gpg)! Files that were not
20+
committed by the Action will be left staged.
1921

2022
> [!IMPORTANT]
2123
>
@@ -37,6 +39,7 @@ The resulting commit will be signed and verified using
3739
README.md
3840
*.txt
3941
src/**/tests/*
42+
!test-data/dont-include-this
4043
test-data/**
4144
```
4245
@@ -52,19 +55,21 @@ The resulting commit will be signed and verified using
5255
> example.txt
5356
> ```
5457

55-
| Name | Type | Description | Default |
56-
| ----------------- | ------ | ------------------------------------------------ | ------------------------- |
57-
| `ref` | String | The ref to push the commit to | `${{ github.ref }}` |
58-
| `files` | List | Files/[Glob] patterns to include with the commit | _required_ |
59-
| `message` | String | Message for the commit [1] | _optional_ |
60-
| `message-file` | String | File to use for the commit message [1] | _optional_ |
61-
| `force-push` | String | Force push the commit | `false` |
62-
| `follow-symlinks` | String | Follow symbolic links when globbing files | `true` |
63-
| `workspace` | String | Directory containing checked out files | `${{ github.workspace }}` |
64-
| `token` | String | GitHub Token for REST API access [2] | `${{ github.token }}` |
65-
66-
> 1. You must include either `message` or `message-file` (which takes priority).
67-
> 2. This Action is intended to work with the default `GITHUB_TOKEN`. See the
58+
| Name | Type | Description | Default |
59+
| ----------------- | ------- | ---------------------------------------------------- | ------------------------- |
60+
| `ref` | String | The ref to push the commit to | `${{ github.ref }}` |
61+
| `files` | List | Files/[Glob] patterns to include with the commit [1] | _required_ |
62+
| `message` | String | Message for the commit [2] | _optional_ |
63+
| `message-file` | String | File to use for the commit message [2] | _optional_ |
64+
| `force-push` | Boolean | Force push the commit | `false` |
65+
| `follow-symlinks` | Boolean | Follow symbolic links when globbing files | `true` |
66+
| `workspace` | String | Directory containing checked out files | `${{ github.workspace }}` |
67+
| `token` | String | GitHub Token for REST API access [3] | `${{ github.token }}` |
68+
69+
> 1. Files within your `.gitignore` will not be included. You can also negate
70+
> any files by prefixing it with `!`
71+
> 2. You must include either `message` or `message-file` (which takes priority).
72+
> 3. This Action is intended to work with the default `GITHUB_TOKEN`. See the
6873
> [notice](#verified-bot-commit-action) and [limitations](#limitations)
6974

7075
### Outputs

__tests__/ignore/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test-abcdef.txt

__tests__/utils.test.ts

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)