1
0
Files
am-wd/win/check-changes/action.yml

50 lines
1.5 KiB
YAML

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