From 1d1f6563ebb696febe268e6a98884a5ed3901d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=A5hlin?= Date: Fri, 10 Jun 2022 23:48:27 +0200 Subject: [PATCH 1/2] 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 --- .pipelines/.templates/validate-deploy.yml | 31 ++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/.pipelines/.templates/validate-deploy.yml b/.pipelines/.templates/validate-deploy.yml index 24a25e6a..9f6fbd09 100644 --- a/.pipelines/.templates/validate-deploy.yml +++ b/.pipelines/.templates/validate-deploy.yml @@ -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-rename + 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 From 9317382342cfe65c426dfe5769f10562dc3ac8d4 Mon Sep 17 00:00:00 2001 From: Johan Dahlbom Date: Tue, 2 Aug 2022 09:11:18 +0200 Subject: [PATCH 2/2] Update github action and fix typo --- .github/actions/validate-deploy/action.yml | 30 +++++++++++++--------- .pipelines/.templates/validate-deploy.yml | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/actions/validate-deploy/action.yml b/.github/actions/validate-deploy/action.yml index 5c5bdf07..d5c092cd 100644 --- a/.github/actions/validate-deploy/action.yml +++ b/.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 diff --git a/.pipelines/.templates/validate-deploy.yml b/.pipelines/.templates/validate-deploy.yml index 9f6fbd09..c38e8598 100644 --- a/.pipelines/.templates/validate-deploy.yml +++ b/.pipelines/.templates/validate-deploy.yml @@ -20,7 +20,7 @@ steps: $gitDiff | Write-Host $gitDiff | Out-File -FilePath '/tmp/diff.txt' - $deletedContent = git diff --diff-filter=D HEAD^ HEAD --no-prefix --no-rename + $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'