diff --git a/lnx/check-changes/action.yml b/lnx/check-changes/action.yml new file mode 100644 index 0000000..c525924 --- /dev/null +++ b/lnx/check-changes/action.yml @@ -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 \ No newline at end of file diff --git a/win/check-changes/action.yml b/win/check-changes/action.yml new file mode 100644 index 0000000..9c40c8e --- /dev/null +++ b/win/check-changes/action.yml @@ -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 \ No newline at end of file