update pipeline

This commit is contained in:
Matteias Collet 2020-03-09 09:49:36 +01:00
parent 011d1446e5
commit f6ccb81826
3 changed files with 77 additions and 37 deletions

View file

@ -6,47 +6,20 @@ trigger:
pool: pool:
vmImage: 'windows-latest' vmImage: 'windows-latest'
variables:
pushChanges: 'No'
steps: steps:
- task: PowerShell@2 - task: PowerShell@2
displayName: 'Create GCM Archive' displayName: 'Update GCM Archive'
inputs: inputs:
targetType: 'inline' targetType: 'filePath'
script: '$ErrorActionPreference = "Stop"; filePath: './update_gcm_archive.azure.ps1'
New-Item -ItemType directory -Path "./gcmbuild";
Copy-Item "./codes/GMSE01.xml" "./gcmbuild/GMSE01.xml";
Copy-Item "./codes/GMSE01.xml" "./gcmbuild/GMSP01.xml";
Copy-Item "./codes/GMSE01.xml" "./gcmbuild/GMSJ01.xml";
Copy-Item "./codes/GMSE01.xml" "./gcmbuild/GMSJ0A.xml";
cd "./gcmbuild";
function XmlToGcm($source, $destination, $versionname) {
[xml]$xml = Get-Content $source;
Add-Content $destination $versionname;
Add-Content $destination "Super Mario Sunshine" -NoNewline;
foreach($code in $xml.codes.code) {
Add-Content $destination "";
Add-Content $destination "";
Add-Content $destination "$($code.title."#text") ($($code.date)) [$($code.author)]";
$codeSource = $code.source -replace " +$", "" -replace "^? [^a-zA-Z0-9]", "";
Add-Content $destination $codeSource.Trim() -NoNewline;
};
};
XmlToGcm "GMSE01.xml" "GMSE01.txt" "GMSE01";
XmlToGcm "GMSP01.xml" "GMSP01.txt" "GMSP01";
XmlToGcm "GMSJ01.xml" "GMSJ01.txt" "GMSJ01";
XmlToGcm "GMSJ0A.xml" "GMSJ01 (A).txt" "GMSJ01";
Compress-Archive "./*.txt" "../files/GCMCodes.zip" -Force;
cd ..;
Remove-Item "./gcmbuild" -Recurse;'
failOnStderr: true failOnStderr: true
workingDirectory: '.' workingDirectory: '.'
- task: PowerShell@2 - task: PowerShell@2
displayName: 'Commit Changes' displayName: 'Commit and push changes'
condition: and(succeeded(), eq(variables.pushChanges, 'Yes'))
inputs: inputs:
targetType: 'inline' targetType: 'inline'
script: '$ErrorActionPreference = "Stop"; script: '$ErrorActionPreference = "Stop";
@ -58,6 +31,7 @@ steps:
workingDirectory: '.' workingDirectory: '.'
- task: PowerShell@2 - task: PowerShell@2
displayName: 'Push Changes' displayName: 'Push Changes'
condition: and(succeeded(), eq(variables.pushChanges, 'Yes'))
env: env:
GitHub_PAT: $(GitHub_PAT) GitHub_PAT: $(GitHub_PAT)
inputs: inputs:
@ -65,4 +39,4 @@ steps:
script: '$ErrorActionPreference = "Stop"; script: '$ErrorActionPreference = "Stop";
git push -q $(GitHub_PAT) HEAD:master;' git push -q $(GitHub_PAT) HEAD:master;'
failOnStderr: true failOnStderr: true
workingDirectory: '.' workingDirectory: '.'

View file

@ -1391,4 +1391,5 @@
</source> </source>
</code> </code>
--> -->
<!-- Pipeline Test -->
</codes> </codes>

View file

@ -0,0 +1,65 @@
$ErrorActionPreference = "Stop";
# Retrieve commit hash from latest archive update
Write-Host -ForegroundColor Blue "Retrieving last update commit.."
$LastGCMUpdate = (git log -1 --pretty=format:"%H" ./files/GCMCodes.zip);
if ([string]::IsNullOrWhiteSpace($LastGCMUpdate)) {
Write-Host -ForegroundColor Red "Failed to retrieve the latest update commit";
exit -1;
}
Write-Host -ForegroundColor Green "Last GCM Archive Update:" $LastGCMUpdate;
# Check whether any one of the code files chnged
Write-Host -ForegroundColor Blue "Scanning for code changes.."
$CodeUpdates = (git diff --name-only $LastGCMUpdate HEAD -- './codes/*.xml')
if ([string]::IsNullOrWhiteSpace($CodeUpdates)) {
Write-Host -ForegroundColor Green "No code changes detected";
exit 0;
}
Write-Host "Changed files since last archive Update:" $CodeUpdates;
# Start build
Write-Host -ForegroundColor Blue "Packing new archive...";
# Setup workspace
New-Item -ItemType directory -Path "./.gcmbuild";
Copy-Item "./codes/*.xml" "./.gcmbuild/";
Set-Location "./.gcmbuild";
# Helper function to convert the XML files to the GCM txt format
function XmlToGcm($source, $destination, $versionname) {
[xml]$xml = Get-Content $source;
Add-Content $destination $versionname;
Add-Content $destination "Super Mario Sunshine" -NoNewline;
foreach ($code in $xml.codes.code) {
Add-Content $destination "";
Add-Content $destination "";
Add-Content $destination "$($code.title."#text") ($($code.date)) [$($code.author)]";
$codeSource = $code.source -replace " +$", "" -replace "^? [^a-zA-Z0-9]", "";
Add-Content $destination $codeSource.Trim() -NoNewline;
};
};
# Convert files
Write-Host "Converting XML files..";
XmlToGcm "GMSE01.xml" "GMSE01.txt" "GMSE01";
XmlToGcm "GMSP01.xml" "GMSP01.txt" "GMSP01";
XmlToGcm "GMSJ01.xml" "GMSJ01.txt" "GMSJ01";
XmlToGcm "GMSJ0A.xml" "GMSJ01 (A).txt" "GMSJ01";
# Replace zip file
Write-Host "Compressing and replacing archive..";
Compress-Archive "./*.txt" "../files/GCMCodes.zip" -Force;
Set-Location ..;
Remove-Item "./.gcmbuild" -Recurse;
Write-Host -ForegroundColor Green "Done";
# Set Azure environment to commit and push changes
Write-Host "##vso[task.setvariable variable=pushChanges;isOutput=true]Yes"