|
| 1 | +name: 'Check Path Changes' |
| 2 | +description: 'Check if specific paths have changed between commits' |
| 3 | +inputs: |
| 4 | + base_sha: |
| 5 | + description: 'Base commit SHA to compare from' |
| 6 | + required: true |
| 7 | + head_sha: |
| 8 | + description: 'Head commit SHA to compare to' |
| 9 | + required: true |
| 10 | + path_pattern: |
| 11 | + description: 'Path pattern to check for changes (e.g., "rust/", "solidity/")' |
| 12 | + required: true |
| 13 | + path_pattern_only: |
| 14 | + description: 'If true, checks if ONLY the specified path changed. If false, checks if ANY files in the path changed.' |
| 15 | + required: false |
| 16 | + default: 'false' |
| 17 | +outputs: |
| 18 | + has_changes: |
| 19 | + description: 'Whether the specified path has any changes' |
| 20 | + value: ${{ steps.check-changes.outputs.has_changes }} |
| 21 | + only_changes: |
| 22 | + description: 'Whether ONLY the specified path has changes (only set if path_pattern_only=true)' |
| 23 | + value: ${{ steps.check-changes.outputs.only_changes }} |
| 24 | +runs: |
| 25 | + using: 'composite' |
| 26 | + steps: |
| 27 | + - name: Check for path changes |
| 28 | + id: check-changes |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + # Check if the specified path has any changes |
| 32 | + if git diff ${{ inputs.base_sha }}..${{ inputs.head_sha }} --name-only | grep -qE '^${{ inputs.path_pattern }}'; then |
| 33 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 34 | +
|
| 35 | + # If path_pattern_only is requested, also check if ONLY this path changed |
| 36 | + if [[ "${{ inputs.path_pattern_only }}" == "true" ]]; then |
| 37 | + if ! git diff ${{ inputs.base_sha }}..${{ inputs.head_sha }} --name-only | grep -qvE '^${{ inputs.path_pattern }}'; then |
| 38 | + echo "only_changes=true" >> $GITHUB_OUTPUT |
| 39 | + echo "Only ${{ inputs.path_pattern }} changes detected." |
| 40 | + else |
| 41 | + echo "only_changes=false" >> $GITHUB_OUTPUT |
| 42 | + echo "${{ inputs.path_pattern }} changes detected along with other changes." |
| 43 | + fi |
| 44 | + fi |
| 45 | + else |
| 46 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 47 | + if [[ "${{ inputs.path_pattern_only }}" == "true" ]]; then |
| 48 | + echo "only_changes=false" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | + echo "No ${{ inputs.path_pattern }} changes detected." |
| 51 | + fi |
0 commit comments