1
0

Check for changes in the repository in specific paths

This commit is contained in:
2026-04-09 20:30:03 +02:00
parent d1ddfe37aa
commit 9412092d94
2 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
name: 'check-changes'
description: 'Checks for file changes in a specified path.'
inputs:
base-commit:
description: 'The commit hash to compare against. If not provided, the action will use HEAD^.'
default: 'HEAD^'
paths:
description: 'A comma-separated list of file paths to check for changes. If any of these paths has changed files, the action will return true.'
default: ''
outputs:
has-changes:
description: 'Indicates whether there are changes in the specified paths.'
value: ${{ steps.check.outputs.has-changes }}
runs:
using: 'composite'
steps:
- name: Check changes
id: check
shell: bash
run: |
hasChanges=false
baseCommit='${{ inputs.base-commit }}'
if [ "$baseCommit" = "0000000000000000000000000000000000000000" ]; then
echo "Base commit is zero hash (merge commit or new branch). Define as always has changes."
hasChanges=true
fi
if [ $hasChanges = false ]; then
diff=$(git diff --name-only $baseCommit HEAD)
IFS=',' read -r -a paths <<< "${{ inputs.paths }}"
for path in "${paths[@]}"; do
if [[ $diff == $path* ]]; then
hasChanges=true
break
fi
done
fi
echo "OUT: has-changes=$hasChanges"
echo "has-changes=$hasChanges" >> $GITHUB_OUTPUT

View File

@@ -0,0 +1,50 @@
name: 'check-changes'
description: 'Checks for file changes in a specified path.'
inputs:
base-commit:
description: 'The commit hash to compare against. If not provided, the action will use HEAD^.'
default: 'HEAD^'
paths:
description: 'A comma-separated list of file paths to check for changes. If any of these paths has changed files, the action will return true.'
default: ''
outputs:
has-changes:
description: 'Indicates whether there are changes in the specified paths.'
value: ${{ steps.check.outputs.has-changes }}
runs:
using: 'composite'
steps:
- name: Check changes
id: check
shell: powershell
run: |
$hasChanges = $false
$baseCommit = '${{ inputs.base-commit }}'
if ($baseCommit -eq '0000000000000000000000000000000000000000') {
Write-Host "Base commit is zero hash (merge commit or new branch). Define as always has changes."
$hasChanges = $true
}
if (-not $hasChanges) {
$diff = git diff --name-only $baseCommit HEAD
$paths = '${{ inputs.paths }}' -split ',' | ForEach-Object { $_.Trim() }
$diffChanges = $diff |
Where-Object {
foreach ($path in $paths) {
if ($_.StartsWith($path)) {
return $true
}
}
}
$hasChanges = $diffChanges.Count -gt 0
}
Write-Output "OUT: has-changes=$($hasChanges)"
Write-Output "has-changes=$($hasChanges)" | Add-Content -Path $env:GITHUB_OUTPUT