-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update appveyor to download unzip and upload files
- Loading branch information
Qingqing Sun
committed
Sep 23, 2016
1 parent
0e4834f
commit 68b5a6a
Showing
1 changed file
with
32 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,190 +1,32 @@ | ||
environment: | ||
github_access_token: | ||
secure: XgRTP/48Tcb8jdBahG9aZEhKeu2qBc5gCugjShWkT+zNqcQihEtKIIonzPaGcUV+ | ||
|
||
build_script: | ||
- ps: | | ||
Write-Host "Begin processing files" | ||
$docPath = Join-Path (Get-Item -Path ".\" -Verbose).FullName $env:DocFolder | ||
$files = Get-ChildItem -Path $docPath -Recurse | where {$_.extension -eq $env:Extension} | % { $_.FullName } | ||
$pattern = '^(?s)\s*[-]{3}(.*?)[-]{3}\r?\n' | ||
Write-Host "Found " $files.count "Files" | ||
foreach($file in $files) | ||
{ | ||
if(!((Get-Content $file | Out-String) -match $pattern)) | ||
{ | ||
continue | ||
} | ||
$header = $matches[1] | ||
$new_header = $matches[1] | ||
#metadata: updated_at | ||
$date = [datetime](Get-ItemProperty -Path $file -Name LastWriteTime).lastwritetime | ||
if($header -match 'updated_at[\s\S].*') | ||
{ | ||
$new_header = $new_header.replace($matches[0], 'updated_at: ' + (Get-Date $date -format g)) | ||
} | ||
else | ||
{ | ||
$new_header = $new_header + 'updated_at: ' + (Get-Date $date -format g) + "`r`n" | ||
} | ||
#metadata: ms.date | ||
if($header -match 'ms.date[\s\S].*') | ||
{ | ||
$new_header = $new_header.replace($matches[0], 'ms.date: ' + (Get-Date $date -format d)) | ||
} | ||
else | ||
{ | ||
$new_header = $new_header + 'ms.date: ' + (Get-Date $date -format d) + "`r`n" | ||
} | ||
Set-Content $file (Get-Content $file | Out-String).replace($header, $new_header) -NoNewline | ||
(Get-Content $file | Out-String) -match $pattern | out-null | ||
$header = $matches[1] | ||
$new_header = $matches[1] | ||
#metadata: ms.topic | ||
$topicType = 'reference' | ||
if($header -match 'Module Name') | ||
{ | ||
$topicType = 'conceptual' | ||
} | ||
if($header -match 'ms.topic[\s\S].*') | ||
{ | ||
$new_header = $new_header.replace($matches[0], 'ms.topic: ' + $topicType) | ||
} | ||
else | ||
{ | ||
$new_header = $new_header + 'ms.topic: ' + $topicType + "`r`n" | ||
} | ||
#metadata: content_git_url and original_content_git_url | ||
$rel_path = Get-Item $file | Resolve-Path -Relative | ||
$git_url_path = $env:source_repo + '/blob/' + $env:source_branch +'/' + $rel_path | ||
$git_url = (New-object System.Uri $git_url_path).AbsoluteUri | ||
if($header -match 'content_git_url[\s\S].*') | ||
{ | ||
$new_header = $new_header.replace($matches[0], 'content_git_url: ' + $git_url) | ||
} | ||
else | ||
{ | ||
$new_header = $new_header + 'content_git_url: ' + $git_url + "`r`n" | ||
} | ||
if($header -match 'original_content_git_url[\s\S].*') | ||
{ | ||
$new_header = $new_header.replace($matches[0], 'original_content_git_url: ' + $git_url) | ||
} | ||
else | ||
{ | ||
$new_header = $new_header + 'original_content_git_url: ' + $git_url + "`r`n" | ||
} | ||
#metadata: gitcommit | ||
$commitId = (git rev-list -1 HEAD $file) | ||
$git_commit_path = $env:source_repo + '/blob/' + $commitId + '/' + $rel_path | ||
$git_commit_url = (New-object System.Uri $git_commit_path).AbsoluteUri | ||
if($header -match 'gitcommit[\s\S].*') | ||
{ | ||
$new_header = $new_header.replace($matches[0], 'gitcommit: ' + $git_commit_url) | ||
} | ||
else | ||
{ | ||
$new_header = $new_header + 'gitcommit: ' + $git_commit_url + "`r`n" | ||
} | ||
#filter invalid characters | ||
if($header -match '{{' -or $header -match '}}') | ||
{ | ||
$new_header = $new_header.replace('{{', '').replace('}}', '') | ||
} | ||
#update file | ||
Set-Content $file (Get-Content $file | Out-String).replace($header, $new_header) -NoNewline | ||
} | ||
Write-Host 'Finish processing files.' | ||
- ps: | | ||
function GetToc | ||
{ | ||
$docPath = Join-Path (Get-Item -Path ".\" -Verbose).FullName $env:DocFolder | ||
$tocPath = Join-Path $docPath "toc.yml" | ||
if(Test-Path $tocPath) | ||
{ | ||
Remove-Item $tocPath | ||
} | ||
New-Item $tocPath | ||
DoGetToc $docPath $tocPath $env:Extension 0 | ||
} | ||
function global:DoGetToc($folderPath, $tocPath, $extension, $level) | ||
{ | ||
Write-Host "constructing toc in $folderPath" | ||
$pre = "" | ||
for($i=0;$i -lt $level;$i++) | ||
{ | ||
$pre = $pre + " " | ||
} | ||
Add-Content -Path $tocPath -Value ($pre + "- name: " + (Split-Path -Path $folderPath -Leaf)) | ||
$subFolders = Get-ChildItem $folderPath -Directory | Select-Object FullName | ||
if($subFolders -eq $null) | ||
{ | ||
$files = (Get-ChildItem $folderPath) | Where-Object { $_.Extension -eq $Extension } | select -ExpandProperty FullName | ||
$landingPage = "" | ||
foreach($file in $files) | ||
{ | ||
$found = (Get-Content $file | Out-String) -match '^(?s)\s*[-]{3}(.*?)[-]{3}\r?\n' | ||
if($found -and $matches[1] -match 'Module Name') | ||
{ | ||
Add-Content -Path $tocPath -Value ($pre + " href: " + (Get-Item $file | Resolve-Path -Relative).replace($env:DocFolder + '\', '')) | ||
$landingPage = $file | ||
break | ||
} | ||
} | ||
Add-Content -Path $tocPath -Value ($pre + " items:") | ||
$pre = $pre + " " | ||
foreach($file in $files) | ||
{ | ||
if($file -ne $landingPage) | ||
{ | ||
Add-Content -Path $tocPath -Value ($pre + "- name: " + (Split-Path -Path $file -Leaf -Resolve).split('\.')[-2]) | ||
Add-Content -Path $tocPath -Value ($pre + " href: " + (Get-Item $file | Resolve-Path -Relative).replace($env:DocFolder + '\', '')) | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Add-Content -Path $tocPath -Value ($pre + " items:") | ||
foreach($subFolder in $subFolders) | ||
{ | ||
DoGetToc $subFolder.FullName $tocPath $extension ($level+1) | ||
} | ||
} | ||
} | ||
GetToc | ||
on_success: | ||
- git clone -q --branch=%TargetBranch% %ContentRepo% %TEMP%\AzurePowerShell | ||
- ps: Get-ChildItem $env:TEMP\AzurePowerShell\$env:DocFolder -dir | Remove-Item -Recurse -Force | ||
- robocopy %APPVEYOR_BUILD_FOLDER%\%DocFolder% %TEMP%\AzurePowerShell\%DocFolder% /e & IF %ERRORLEVEL% LEQ 1 exit 0 | ||
- copy %APPVEYOR_BUILD_FOLDER%\%DocFolder%\toc.yml %TEMP%\AzurePowerShell\%DocFolder% | ||
- cd %TEMP%\AzurePowerShell | ||
- git config --global credential.helper store | ||
- ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:github_access_token):[email protected]`n" | ||
- git config --global user.email %Email% | ||
- git config --global user.name %Name% | ||
- git add -A | ||
- git commit -m "commit from appveyor" | ||
- git push origin %TargetBranch% | ||
environment: | ||
github_access_token: | ||
secure: XgRTP/48Tcb8jdBahG9aZEhKeu2qBc5gCugjShWkT+zNqcQihEtKIIonzPaGcUV+ | ||
|
||
build_script: | ||
- ps: | | ||
Write-Host "Begin download artifacts" | ||
$file_name = $env:APPVEYOR_REPO_TAG_NAME + ".zip" | ||
$source = "https://github.com/summersun/poc/archive/" + $file_name | ||
# https://github.com/Azure/azure-powershell/archive/v2.2.0-September2016.zip | ||
$dest = "C:\application\data" | ||
Invoke-WebRequest -Uri $source -OutFile $env:APPVEYOR_BUILD_FOLDER | ||
7z x $file_name -o$env:APPVEYOR_BUILD_FOLDER -y | ||
# problem 1: find the target folders and files | ||
# problem 2: process the files | ||
# problem 3: generate toc | ||
# problem 4: git push files | ||
on_success: | ||
- git clone -q --branch=%TargetBranch% %ContentRepo% %TEMP%\AzurePowerShell | ||
- ps: Get-ChildItem $env:TEMP\AzurePowerShell\$env:DocFolder -dir | Remove-Item -Recurse -Force | ||
- robocopy %APPVEYOR_BUILD_FOLDER%\ %TEMP%\AzurePowerShell\%DocFolder% /e & IF %ERRORLEVEL% LEQ 1 exit 0 | ||
- cd %TEMP%\AzurePowerShell | ||
- git config --global credential.helper store | ||
- ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:github_access_token):[email protected]`n" | ||
- git config --global user.email %Email% | ||
- git config --global user.name %Name% | ||
- git add -A | ||
- git commit -m "commit from appveyor" | ||
- git push origin %TargetBranch% |