-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
188 lines (175 loc) · 6.15 KB
/
.gitlab-ci.yml
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
include:
- project: sequence/templates/cicd
file: .gitlab/ci/default.default.yml
- project: sequence/templates/cicd
file: .gitlab/ci/default.rules.yml
- project: sequence/templates/cicd
file: .gitlab/ci/default.scripts.yml
- project: sequence/templates/cicd
file: .gitlab/ci/default.stages.yml
- project: sequence/templates/cicd
file: .gitlab/ci/default.variables.yml
- project: sequence/templates/cicd
file: .gitlab/ci/default.workflow.yml
- project: sequence/templates/cicd
file: .gitlab/ci/build.yml
- project: sequence/templates/cicd
file: .gitlab/ci/package.yml
- project: sequence/templates/cicd
file: .gitlab/ci/push.yml
- project: sequence/templates/cicd
file: .gitlab/ci/sign.yml
default:
image: mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
tags:
- rt-powershell
variables:
PACKAGE_NAME_EXE: Sequence.EntityImportClient
PACKAGE_NAME_NUGET: Sequence.EntityImportClient
build dev:
script:
- nuget restore
- msbuild -property:"Configuration=$CONFIG" -consoleLoggerParameters:"Summary;WarningsOnly;ErrorsOnly"
test dev:
stage: test
extends:
- .rules_dev
variables:
CONFIG: $CONFIG_DEV
script:
- vstest.console.exe ".\EntityImportClient.Tests\bin\$CONFIG\EntityImportClient.Tests.dll"
test release:
extends:
- test dev
- .rules_release
variables:
CONFIG: $CONFIG_RELEASE
version check dev:
stage: test
extends:
- .rules_dev
needs: []
cache: {}
script:
- |
if ($env:CI_JOB_NAME -eq "version check release") {
Write-Host "Tag version : ${env:CI_COMMIT_TAG}" ;
}
$timestamp = Get-Date -Format "yyMMddHHmm" ;
Write-Host "Version timestamp : $timestamp" ;
$releasesUri = "https://gitlab.com/api/v4/projects/${env:CI_PROJECT_ID}/releases" ;
$releasesRsp = Invoke-RestMethod -Uri $releasesUri -Headers @{ "JOB-TOKEN" = $env:CI_JOB_TOKEN } ;
$releases = $releasesRsp | Select-Object -ExpandProperty name ;
$protoPath = '.\EntityImportClient.Proto\EntityImportClient.Proto.csproj' ;
$protoFile = Get-Content $protoPath -Raw ;
$protoFile -match "<Version>(.+?)(\$\(VersionSuffix\))?</Version>" | Out-Null ;
$protoVersion = $Matches[1] ;
$projPath = '.\EntityImportClient\Properties\AssemblyInfo.cs' ;
$aFile = Get-Content $projPath -Raw ;
$aFile -match "AssemblyVersion\(`"([\d\.]+?)`"\)" | Out-Null ;
$assemblyVersion = $Matches[1] ;
$aFile -match "AssemblyFileVersion\(`"([\d\.]+?)`"\)" | Out-Null ;
$assemblyFileVersion = $Matches[1] ;
$assemblyVersion -match "(\d+\.){3}" | Out-Null ;
$version = $Matches[0].TrimEnd('.') ;
$suffix = "-" + $env:DEFAULT_PRERELEASE_VERSION ;
if ($env:CI_COMMIT_BRANCH -eq $env:CI_DEFAULT_BRANCH) {
$suffix += ".main" ;
} else {
$suffix += ".dev" ;
}
$suffix += ".$timestamp" ;
Write-Host "Assembly Version : $assemblyVersion" ;
Write-Host "Assembly File Version : $assemblyFileVersion" ;
Write-Host "Protobufs Version : $protoVersion" ;
Write-Host "Version : $version" ;
Write-Host "Version suffix : $suffix" ;
"PROJECT_VERSION=v$version`nVERSION_SUFFIX=$suffix`nVERSION_TIMESTAMP=$timestamp" |
Out-File -FilePath ./version.env -Encoding ascii ;
"${version}${suffix}" | Out-File -FilePath ./version.txt -Encoding ascii ;
if ($assemblyVersion -ne $assemblyFileVersion) {
Write-Host -Fore Red "ERROR: Assembly Version must equal Assembly File Version" ;
}
if ($version -ne $protoVersion) {
Write-Host -Fore Red "ERROR: Protobufs project version must equal the EntityImportClient Version" ;
}
if ($env:CI_JOB_NAME -ne "version check release" -and ("v$version" -in $releases -or "v$protoVersion" -in $releases)) {
Write-Host -Fore Red "ERROR: A release for this version ($version) already exists." ;
exit 1
}
if ($env:CI_JOB_NAME -eq "version check release" -and (
"v$protoVersion" -ne $env:CI_COMMIT_TAG -or "v$version" -ne $env:CI_COMMIT_TAG)) {
Write-Host -Fore Red "ERROR: The project version $version does not match the release tag version ${env:CI_COMMIT_TAG}" ;
exit 1 ;
}
artifacts:
reports:
dotenv: version.env
expose_as: Build Version
paths: ['version.txt']
version check release:
extends:
- version check dev
- .rules_release
package exe dev:
stage: package
extends:
- .rules_dev_manual
needs:
- build dev
- test dev
- version check dev
script:
- cp -Recurse -Force .\EntityImportClient\bin\$CONFIG\* .\$PACKAGE_NAME_EXE\
artifacts:
name: '$PACKAGE_NAME_EXE-$PROJECT_VERSION'
paths:
- $PACKAGE_NAME_EXE/
expire_in: 3 months
package exe release:
extends:
- package exe dev
- .rules_release
needs:
- build release
- test release
- version check release
artifacts:
expire_in: 2 hours
sign exe release:
stage: sign
image: registry.gitlab.com/reductech/containers/codesigning
cache: {}
extends:
- .rules_release
needs:
- package exe release
- version check release
variables:
DOCKER_AUTH_CONFIG: $RT_SIGN_REGISTRY
TIMESTAMP_SERVER: http://timestamp.sectigo.com
ALGO_FILE_DIGEST: SHA256
ALGO_TIME_DIGEST: SHA256
script:
- signtool.exe sign /f $RT_CERT_PATH /p $RT_CERT_PASS /fd $ALGO_FILE_DIGEST
/tr $TIMESTAMP_SERVER /td $ALGO_TIME_DIGEST .\$PACKAGE_NAME_EXE\EntityImportClient.exe
artifacts:
name: '$PACKAGE_NAME_EXE-$PROJECT_VERSION'
paths:
- $PACKAGE_NAME_EXE/
expire_in: never
package nuget dev:
script:
- dotnet pack .\EntityImportClient.Proto\EntityImportClient.Proto.csproj
--configuration $CONFIG_DEV --version-suffix $VERSION_SUFFIX --output ./
artifacts:
name: '$PACKAGE_NAME_NUGET-$PROJECT_VERSION$VERSION_SUFFIX.nupkg'
package nuget release:
script:
- dotnet pack .\EntityImportClient.Proto\EntityImportClient.Proto.csproj
--configuration $CONFIG_RELEASE --output ./
artifacts:
name: '$PACKAGE_NAME_NUGET-$PROJECT_VERSION.nupkg'
package dll release:
rules:
- when: never