Skip to content

Commit 7006676

Browse files
authored
Merge pull request #6 from LuisLiraC/feat/action-file
Create action file
2 parents 9ac5525 + 51a9985 commit 7006676

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
# Git Diff Action
3+
4+
This GitHub Action performs a git diff and outputs the files that changed in a Pull Request, based on specified patterns.
5+
6+
## Inputs
7+
8+
### `patterns`
9+
10+
**Required**: A string containing file patterns to include or exclude in the diff. Patterns should be separated by commas.
11+
12+
- Use `*` as a wildcard for any number of characters.
13+
- Use `**` for recursive directory matching.
14+
- Prefix patterns with `!` to exclude files.
15+
16+
Examples:
17+
- `*.rs`: All Rust files
18+
- `src/**/*`: All files within the `src` directory and its subdirectories
19+
- `!README.md`: Exclude the README.md file
20+
21+
## Outputs
22+
23+
### `DIFF_FILES`
24+
25+
A list of files that changed in the PR, matching the specified patterns.
26+
27+
### `DIFF_COUNT`
28+
29+
The number of files that changed in the PR, matching the specified patterns.
30+
31+
## Example usage
32+
33+
```yaml
34+
name: Git Diff Check
35+
36+
on:
37+
pull_request:
38+
branches: [ main ]
39+
40+
jobs:
41+
check_diff:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Get changed files
47+
id: diff
48+
uses: LuisLiraC/git-diff@main
49+
with:
50+
patterns: '*.rs,src/**/*,!README.md'
51+
52+
- name: Get diff outputs
53+
run: |
54+
echo "Files: ${{ steps.diff.outputs.DIFF_FILES }}"
55+
echo "Count: ${{ steps.diff.outputs.DIFF_COUNT }}"
56+
```

action.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: 'Git Diff'
2+
description: 'Action to get the files that have been changed in a pull request'
3+
inputs:
4+
patterns:
5+
description: 'Patterns to search for'
6+
required: true
7+
outputs:
8+
DIFF_FILES:
9+
description: 'List of files that have been changed'
10+
value: ${{ steps.get-git-diff.outputs.DIFF_FILES }}
11+
DIFF_COUNT:
12+
description: 'Number of files that have been changed'
13+
value: ${{ steps.get-git-diff.outputs.DIFF_COUNT }}
14+
runs:
15+
using: 'composite'
16+
steps:
17+
- name: Get Binary
18+
shell: bash
19+
run: |
20+
BIN_URL=$(curl https://api.github.com/repos/LuisLiraC/git-diff/releases/latest | jq -r '.assets[0].browser_download_url')
21+
echo "Downloading from $BIN_URL"
22+
curl -L $BIN_URL -o rust-binary.tgz
23+
tar -xzvf rust-binary.tgz
24+
mv ./Linux/git-diff ./git-diff
25+
26+
- name: Run git-diff
27+
id: get-git-diff
28+
shell: bash
29+
run: |
30+
./git-diff --patterns='${{ inputs.patterns }}'

0 commit comments

Comments
 (0)