Skip to content

Commit 68b5a6a

Browse files
author
Qingqing Sun
committed
update appveyor to download unzip and upload files
1 parent 0e4834f commit 68b5a6a

File tree

1 file changed

+32
-190
lines changed

1 file changed

+32
-190
lines changed

appveyor.yml

Lines changed: 32 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,190 +1,32 @@
1-
environment:
2-
github_access_token:
3-
secure: XgRTP/48Tcb8jdBahG9aZEhKeu2qBc5gCugjShWkT+zNqcQihEtKIIonzPaGcUV+
4-
5-
build_script:
6-
- ps: |
7-
Write-Host "Begin processing files"
8-
9-
$docPath = Join-Path (Get-Item -Path ".\" -Verbose).FullName $env:DocFolder
10-
$files = Get-ChildItem -Path $docPath -Recurse | where {$_.extension -eq $env:Extension} | % { $_.FullName }
11-
$pattern = '^(?s)\s*[-]{3}(.*?)[-]{3}\r?\n'
12-
13-
Write-Host "Found " $files.count "Files"
14-
15-
foreach($file in $files)
16-
{
17-
if(!((Get-Content $file | Out-String) -match $pattern))
18-
{
19-
continue
20-
}
21-
22-
$header = $matches[1]
23-
$new_header = $matches[1]
24-
25-
#metadata: updated_at
26-
$date = [datetime](Get-ItemProperty -Path $file -Name LastWriteTime).lastwritetime
27-
28-
if($header -match 'updated_at[\s\S].*')
29-
{
30-
$new_header = $new_header.replace($matches[0], 'updated_at: ' + (Get-Date $date -format g))
31-
}
32-
else
33-
{
34-
$new_header = $new_header + 'updated_at: ' + (Get-Date $date -format g) + "`r`n"
35-
}
36-
#metadata: ms.date
37-
if($header -match 'ms.date[\s\S].*')
38-
{
39-
$new_header = $new_header.replace($matches[0], 'ms.date: ' + (Get-Date $date -format d))
40-
}
41-
else
42-
{
43-
$new_header = $new_header + 'ms.date: ' + (Get-Date $date -format d) + "`r`n"
44-
}
45-
Set-Content $file (Get-Content $file | Out-String).replace($header, $new_header) -NoNewline
46-
47-
(Get-Content $file | Out-String) -match $pattern | out-null
48-
$header = $matches[1]
49-
$new_header = $matches[1]
50-
51-
#metadata: ms.topic
52-
$topicType = 'reference'
53-
if($header -match 'Module Name')
54-
{
55-
$topicType = 'conceptual'
56-
}
57-
58-
if($header -match 'ms.topic[\s\S].*')
59-
{
60-
$new_header = $new_header.replace($matches[0], 'ms.topic: ' + $topicType)
61-
}
62-
else
63-
{
64-
$new_header = $new_header + 'ms.topic: ' + $topicType + "`r`n"
65-
}
66-
67-
#metadata: content_git_url and original_content_git_url
68-
$rel_path = Get-Item $file | Resolve-Path -Relative
69-
$git_url_path = $env:source_repo + '/blob/' + $env:source_branch +'/' + $rel_path
70-
$git_url = (New-object System.Uri $git_url_path).AbsoluteUri
71-
72-
if($header -match 'content_git_url[\s\S].*')
73-
{
74-
$new_header = $new_header.replace($matches[0], 'content_git_url: ' + $git_url)
75-
}
76-
else
77-
{
78-
$new_header = $new_header + 'content_git_url: ' + $git_url + "`r`n"
79-
}
80-
81-
if($header -match 'original_content_git_url[\s\S].*')
82-
{
83-
$new_header = $new_header.replace($matches[0], 'original_content_git_url: ' + $git_url)
84-
}
85-
else
86-
{
87-
$new_header = $new_header + 'original_content_git_url: ' + $git_url + "`r`n"
88-
}
89-
90-
#metadata: gitcommit
91-
$commitId = (git rev-list -1 HEAD $file)
92-
$git_commit_path = $env:source_repo + '/blob/' + $commitId + '/' + $rel_path
93-
$git_commit_url = (New-object System.Uri $git_commit_path).AbsoluteUri
94-
95-
if($header -match 'gitcommit[\s\S].*')
96-
{
97-
98-
$new_header = $new_header.replace($matches[0], 'gitcommit: ' + $git_commit_url)
99-
}
100-
else
101-
{
102-
$new_header = $new_header + 'gitcommit: ' + $git_commit_url + "`r`n"
103-
}
104-
105-
#filter invalid characters
106-
if($header -match '{{' -or $header -match '}}')
107-
{
108-
$new_header = $new_header.replace('{{', '').replace('}}', '')
109-
}
110-
111-
#update file
112-
Set-Content $file (Get-Content $file | Out-String).replace($header, $new_header) -NoNewline
113-
}
114-
Write-Host 'Finish processing files.'
115-
- ps: |
116-
function GetToc
117-
{
118-
$docPath = Join-Path (Get-Item -Path ".\" -Verbose).FullName $env:DocFolder
119-
$tocPath = Join-Path $docPath "toc.yml"
120-
121-
if(Test-Path $tocPath)
122-
{
123-
Remove-Item $tocPath
124-
}
125-
New-Item $tocPath
126-
DoGetToc $docPath $tocPath $env:Extension 0
127-
}
128-
129-
function global:DoGetToc($folderPath, $tocPath, $extension, $level)
130-
{
131-
Write-Host "constructing toc in $folderPath"
132-
$pre = ""
133-
134-
for($i=0;$i -lt $level;$i++)
135-
{
136-
$pre = $pre + " "
137-
}
138-
139-
Add-Content -Path $tocPath -Value ($pre + "- name: " + (Split-Path -Path $folderPath -Leaf))
140-
$subFolders = Get-ChildItem $folderPath -Directory | Select-Object FullName
141-
142-
if($subFolders -eq $null)
143-
{
144-
$files = (Get-ChildItem $folderPath) | Where-Object { $_.Extension -eq $Extension } | select -ExpandProperty FullName
145-
$landingPage = ""
146-
147-
foreach($file in $files)
148-
{
149-
$found = (Get-Content $file | Out-String) -match '^(?s)\s*[-]{3}(.*?)[-]{3}\r?\n'
150-
if($found -and $matches[1] -match 'Module Name')
151-
{
152-
Add-Content -Path $tocPath -Value ($pre + " href: " + (Get-Item $file | Resolve-Path -Relative).replace($env:DocFolder + '\', ''))
153-
$landingPage = $file
154-
break
155-
}
156-
}
157-
Add-Content -Path $tocPath -Value ($pre + " items:")
158-
$pre = $pre + " "
159-
foreach($file in $files)
160-
{
161-
if($file -ne $landingPage)
162-
{
163-
Add-Content -Path $tocPath -Value ($pre + "- name: " + (Split-Path -Path $file -Leaf -Resolve).split('\.')[-2])
164-
Add-Content -Path $tocPath -Value ($pre + " href: " + (Get-Item $file | Resolve-Path -Relative).replace($env:DocFolder + '\', ''))
165-
}
166-
}
167-
}
168-
else
169-
{
170-
Add-Content -Path $tocPath -Value ($pre + " items:")
171-
foreach($subFolder in $subFolders)
172-
{
173-
DoGetToc $subFolder.FullName $tocPath $extension ($level+1)
174-
}
175-
}
176-
}
177-
GetToc
178-
on_success:
179-
- git clone -q --branch=%TargetBranch% %ContentRepo% %TEMP%\AzurePowerShell
180-
- ps: Get-ChildItem $env:TEMP\AzurePowerShell\$env:DocFolder -dir | Remove-Item -Recurse -Force
181-
- robocopy %APPVEYOR_BUILD_FOLDER%\%DocFolder% %TEMP%\AzurePowerShell\%DocFolder% /e & IF %ERRORLEVEL% LEQ 1 exit 0
182-
- copy %APPVEYOR_BUILD_FOLDER%\%DocFolder%\toc.yml %TEMP%\AzurePowerShell\%DocFolder%
183-
- cd %TEMP%\AzurePowerShell
184-
- git config --global credential.helper store
185-
- ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:github_access_token):[email protected]`n"
186-
- git config --global user.email %Email%
187-
- git config --global user.name %Name%
188-
- git add -A
189-
- git commit -m "commit from appveyor"
190-
- git push origin %TargetBranch%
1+
environment:
2+
github_access_token:
3+
secure: XgRTP/48Tcb8jdBahG9aZEhKeu2qBc5gCugjShWkT+zNqcQihEtKIIonzPaGcUV+
4+
5+
build_script:
6+
- ps: |
7+
Write-Host "Begin download artifacts"
8+
9+
$file_name = $env:APPVEYOR_REPO_TAG_NAME + ".zip"
10+
$source = "https://github.com/summersun/poc/archive/" + $file_name
11+
# https://github.com/Azure/azure-powershell/archive/v2.2.0-September2016.zip
12+
$dest = "C:\application\data"
13+
Invoke-WebRequest -Uri $source -OutFile $env:APPVEYOR_BUILD_FOLDER
14+
15+
7z x $file_name -o$env:APPVEYOR_BUILD_FOLDER -y
16+
17+
# problem 1: find the target folders and files
18+
# problem 2: process the files
19+
# problem 3: generate toc
20+
# problem 4: git push files
21+
on_success:
22+
- git clone -q --branch=%TargetBranch% %ContentRepo% %TEMP%\AzurePowerShell
23+
- ps: Get-ChildItem $env:TEMP\AzurePowerShell\$env:DocFolder -dir | Remove-Item -Recurse -Force
24+
- robocopy %APPVEYOR_BUILD_FOLDER%\ %TEMP%\AzurePowerShell\%DocFolder% /e & IF %ERRORLEVEL% LEQ 1 exit 0
25+
- cd %TEMP%\AzurePowerShell
26+
- git config --global credential.helper store
27+
- ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:github_access_token):[email protected]`n"
28+
- git config --global user.email %Email%
29+
- git config --global user.name %Name%
30+
- git add -A
31+
- git commit -m "commit from appveyor"
32+
- git push origin %TargetBranch%

0 commit comments

Comments
 (0)