Replace diff step with PowerShell (#120)

* Replace diff step with PowerShell

Using same language for all steps with logic will be easier to maintain.
We already depend heavily on PowerShell so it is the obvious choice

* Update github action and fix typo

Co-authored-by: Johan Dahlbom <johan@dahlbom.eu>
This commit is contained in:
Simon Wåhlin 2022-08-02 09:16:07 +02:00 коммит произвёл GitHub
Родитель fcc45c4c92
Коммит 4068ed305a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 37 добавлений и 24 удалений

30
.github/actions/validate-deploy/action.yml поставляемый
Просмотреть файл

@ -17,20 +17,26 @@ runs:
#
- name: "Diff"
shell: bash
shell: pwsh
run: |
if [ ! -z "$(git diff --name-status HEAD^ HEAD)" ]; then
echo $(git diff --name-status HEAD^ HEAD)
git diff --name-status HEAD^ HEAD > /tmp/diff.txt
if [ ! -z "$(git diff --diff-filter=D HEAD^ HEAD --no-renames)" ]; then
echo $(git diff --diff-filter=D HEAD^ HEAD --no-prefix --no-renames | grep ^- | sed -r "s/^([^-+ ]*)[-+ ]/\\1/" | less -r)
git diff --diff-filter=D HEAD^ HEAD --no-prefix --no-renames | grep ^- | sed -r "s/^([^-+ ]*)[-+ ]/\\1/" | less -r > /tmp/diffdeletedfiles.txt
fi
else
echo "The validation pipeline failed because there is currently no change to be processed"
$gitDiff = git diff --name-status HEAD^ HEAD
if ($null -ne $gitDiff) {
$gitDiff | Write-Host
$gitDiff | Out-File -FilePath '/tmp/diff.txt'
$deletedContent = git diff --diff-filter=D HEAD^ HEAD --no-prefix --no-renames
if($null -ne $deletedContent) {
$deletedContent = $deletedContent -match '^-' -replace '^([^-+ ]*)[-+ ]', '$1'
Write-Host '##[group]Deleted files content'
$deletedContent | Write-Host
Write-Host '##[endgroup]'
$deletedContent | Out-File -FilePath '/tmp/diffdeletedfiles.txt'
}
}
else {
Write-Host '##[error]The validation pipeline failed because there is currently no change to be processed'
exit 1
fi
}
#
# Deploy
# Initial deployment of any index changes

Просмотреть файл

@ -10,22 +10,29 @@ steps:
# List index changes
#
- task: Bash@3
- task: PowerShell@2
displayName: "Diff"
inputs:
targetType: "inline"
script: |
if [ ! -z "$(git diff --name-status HEAD^ HEAD)" ]; then
echo $(git diff --name-status HEAD^ HEAD)
git diff --name-status HEAD^ HEAD > /tmp/diff.txt
if [ ! -z "$(git diff --diff-filter=D HEAD^ HEAD --no-renames)" ]; then
echo $(git diff --diff-filter=D HEAD^ HEAD --no-prefix --no-renames | grep ^- | sed -r "s/^([^-+ ]*)[-+ ]/\\1/" | less -r)
git diff --diff-filter=D HEAD^ HEAD --no-prefix --no-renames | grep ^- | sed -r "s/^([^-+ ]*)[-+ ]/\\1/" | less -r > /tmp/diffdeletedfiles.txt
fi
else
echo "The validation pipeline failed because there is currently no change to be processed"
exit 1
fi
$gitDiff = git diff --name-status HEAD^ HEAD
if($null -ne $gitDiff) {
$gitDiff | Write-Host
$gitDiff | Out-File -FilePath '/tmp/diff.txt'
$deletedContent = git diff --diff-filter=D HEAD^ HEAD --no-prefix --no-renames
if($null -ne $deletedContent) {
$deletedContent = $deletedContent -match '^-' -replace '^([^-+ ]*)[-+ ]', '$1'
Write-Host '##[group]Deleted files content'
$deletedContent | Write-Host
Write-Host '##[endgroup]'
$deletedContent | Out-File -FilePath '/tmp/diffdeletedfiles.txt'
}
}
else {
Write-Host '##[error]The validation pipeline failed because there is currently no change to be processed'
exit 1
}
#
# Validate or Deploy