forked from shesha-io/shesha-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarter-template-publisher.yml
More file actions
135 lines (120 loc) · 6.81 KB
/
starter-template-publisher.yml
File metadata and controls
135 lines (120 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
# trigger:
# - main
pool:
vmImage: ubuntu-latest
steps:
- script: echo ProjectTemplate Process Starting...
# displayName: 'Run a one-line script'
- task: PowerShell@2
displayName: Getting directory structure ready
inputs:
targetType: 'inline'
script: |
Write-Host "Renaming frontend to adminportal and delete Intent"
Rename-Item -Path "frontend" -NewName "adminportal"
# Remove-Item -LiteralPath "intent/.intent" -Force -Recurse
# Write-Host "Completed"
# Write-Host "Copy database to root and delete database folder"
# Copy-Item 'database/*' -Destination '.' -Recurse
# Remove-Item -LiteralPath "database" -Force -Recurse
# Write-Host "Completed"
# Write-Host "Changing version reference in packages.json to latest public version"
# Set-Location -Path "$(System.DefaultWorkingDirectory)/shesha-starter/adminportal"
# $filePath = "package.json"
# $Jsonfile = Get-Content $filePath -raw | ConvertFrom-Json
# $Jsonfile.dependencies.'@shesha-io/reactjs' = "latest"
# ConvertTo-Json $Jsonfile -Depth 5 | Set-Content $filePath
Write-Host "Completed"
workingDirectory: '$(System.DefaultWorkingDirectory)/shesha-starter/'
- task: PowerShell@2
displayName: Generate and Replace SecurityKey
inputs:
targetType: 'inline'
script: |
# Generate cryptographically secure 86-character alphanumeric key
$key = -join (1..86 | ForEach-Object { [char](Get-Random -InputObject ((65..90) + (48..57))) })
Write-Host "Generated new 86-character SecurityKey for this template build"
Write-Host "Key Length: $($key.Length) characters"
# Find and replace in all appsettings.json files within shesha-starter
$appsettingsFiles = Get-ChildItem -Path "shesha-starter" -Filter "appsettings.json" -Recurse -ErrorAction SilentlyContinue
Write-Host "Found $($appsettingsFiles.Count) appsettings.json file(s)"
foreach ($file in $appsettingsFiles) {
$content = Get-Content $file.FullName -Raw
if ($content -match '#{securityKey}#') {
$newContent = $content -replace '#{securityKey}#', $key
Set-Content -Path $file.FullName -Value $newContent -NoNewline
Write-Host "Updated: $($file.FullName)"
}
}
# Find and replace in all app.config.json.pipeline files within shesha-starter
$pipelineConfigFiles = Get-ChildItem -Path "shesha-starter" -Filter "app.config.json.pipeline" -Recurse -ErrorAction SilentlyContinue
Write-Host "Found $($pipelineConfigFiles.Count) app.config.json.pipeline file(s)"
foreach ($file in $pipelineConfigFiles) {
$content = Get-Content $file.FullName -Raw
if ($content -match '#{securityKey}#') {
$newContent = $content -replace '#{securityKey}#', $key
Set-Content -Path $file.FullName -Value $newContent -NoNewline
Write-Host "Updated: $($file.FullName)"
}
}
Write-Host "SecurityKey replacement completed successfully"
workingDirectory: '$(System.DefaultWorkingDirectory)'
- task: ArchiveFiles@2
displayName: Zip Starter Directory
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/shesha-starter/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
# - task: 7z@1
# displayName: Zip Starter Directory
# inputs:
# Folder: '$(System.DefaultWorkingDirectory)/shesha-starter/'
# Archive: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
# ArchiveFormat: 'zip'
# - task: Bash@3
# displayName: Curl Starter zip file to DemoShesha
# inputs:
# targetType: 'inline'
# script: |
# echo 'Starting'
# curl -X 'POST' \
# 'https://demoshesha.azurewebsites.net/api/services/SheshaAspnetCoreDemo/ProjectTemplate/Create' \
# -H 'accept: application/json' \
# -H 'Content-Type: multipart/form-data' \
# -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJBc3BOZXQuSWRlbnRpdHkuU2VjdXJpdHlTdGFtcCI6IjM3NzZiODQyLTc1NmUtN2YzZi00YmNlLTM5ZjBlNmFlYThhOSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkFkbWluIiwic3ViIjoiMSIsImp0aSI6IjU2ZTQ1ZDJmLTA0YWItNDVkMS04ZmY3LTgzMTliZTRlNGNhOCIsImlhdCI6MTcwNjgxOTg5NSwibmJmIjoxNzA2ODE5ODk1LCJleHAiOjE3MDcyNTE4OTUsImlzcyI6IlNoZXNoYSIsImF1ZCI6IlNoZXNoYSJ9.UMHjyEVfnl2hwkb2dsOjD5DWso5YFd4_EzQsW8qrtOc' \
# -F 'zipFile=@$(Build.BuildId).zip;type=application/x-zip-compressed' \
# -F 'name=shesha-starter-template-@$(Build.BuildId)' \
# -F 'description=A shesha starter template using the pipeline' \
# -F 'version=$(Build.SourceBranch)' \
# -F 'isPublished=true'
# echo 'Completed'
# Obtain the token
# response=$(curl -X POST "https://demoshesha.azurewebsites.net/swagger/index.html" \
# -H "Content-Type: application/x-www-form-urlencoded" \
# -d "grant_type=client_credentials&client_id=admin&client_secret=123qwe")
# token=$(echo $response | jq -r '.access_token')
# Use the token in the API request
- task: Bash@3
displayName: Curl Starter zip file to DemoShesha
inputs:
targetType: 'inline'
script: |
echo 'Starting'
curl -X 'POST' \
'https://demoshesha.azurewebsites.net/api/services/SheshaAspnetCoreDemo/ProjectTemplate/Create' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW4iLCJBc3BOZXQuSWRlbnRpdHkuU2VjdXJpdHlTdGFtcCI6IjM3NzZiODQyLTc1NmUtN2YzZi00YmNlLTM5ZjBlNmFlYThhOSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkFkbWluIiwic3ViIjoiMSIsImp0aSI6ImU4NTNkZTA4LWRiNzMtNDViNy1iYmIzLWI2ZjA2ZDkzYjgzOCIsImlhdCI6MTc3MDAyNTUxNSwibmJmIjoxNzcwMDI1NTE1LCJleHAiOjE3NzA0NTc1MTUsImlzcyI6IlNoZXNoYSIsImF1ZCI6IlNoZXNoYSJ9.bbcTKEVRm5MRVnmz85SODQ9CHVm4_Ub2tSAyX5xz0DM' \
-F 'zipFile=@$(Build.BuildId).zip;type=application/x-zip-compressed' \
-F 'name=shesha-starter-template-@$(Build.BuildId)' \
-F 'description=A shesha starter template using the pipeline' \
-F 'version=$(Build.SourceBranch)' \
-F 'isPublished=true'
echo 'Completed'
workingDirectory: '$(Build.ArtifactStagingDirectory)'