-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
202 lines (184 loc) · 6.47 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
202 lines (184 loc) · 6.47 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
stages:
- build
- validate
- publish
- deploy
# Prefer the merge request pipeline once a branch has an open MR, so the same
# validation suite is not run twice for a single push.
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
when: never
- if: '$CI_COMMIT_BRANCH'
before_script:
# Inject internal NuGet mirror for CI. The checked-in nuget.config only has
# nuget.org so external contributors can build; CI overwrites it at runtime
# to prefer the internal mirror (faster) with nuget.org as automatic fallback.
- |
cat > nuget.config << 'NUGETEOF'
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="aiursoft" value="https://nuget.aiursoft.com/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
NUGETEOF
- "export PATH=$PATH:$HOME/.dotnet/tools"
- "which jb || dotnet tool install JetBrains.ReSharper.GlobalTools --global $CUSTOM_NUGET_ARGS -v d"
- "which reportgenerator || dotnet tool install dotnet-reportgenerator-globaltool --global $CUSTOM_NUGET_ARGS -v d"
- 'echo "Hostname: $(hostname)"'
- "dotnet --info"
variables:
GIT_CLONE_PATH: "$CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_PIPELINE_ID/$CI_JOB_ID"
MSBUILDDISABLENODEREUSE: "1"
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
CUSTOM_NUGET_ARGS: "--add-source https://nuget.aiursoft.com/v3/index.json --configfile ./nuget.config"
restore:
stage: build
script:
- dotnet restore --disable-parallel --no-cache --configfile nuget.config
retry:
max: 2
when: script_failure
build:
stage: build
needs:
- restore
script:
- dotnet build -maxcpucount:1 --no-self-contained
lint:
stage: validate
needs:
- build
script:
- chmod +x ./lint.sh
- ./lint.sh
artifacts:
when: always
expire_in: 1 day
paths:
- ./analyze_output.xml
retry:
max: 2
when: script_failure
test:
stage: validate
needs:
- build
coverage: '/TOTAL_COVERAGE=(\d+.\d+)/'
script:
- dotnet test *.sln --collect:"XPlat Code Coverage" --logger "junit;MethodFormat=Class;FailureBodyFormat=Verbose"
- reportgenerator -reports:"**/coverage.cobertura.xml" -targetdir:"." -reporttypes:"cobertura"
- COVERAGE_VALUE=$(grep -oPm 1 'line-rate="\K([0-9.]+)' "./Cobertura.xml")
- COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERAGE_VALUE * 100" | bc)
- 'echo "TOTAL_COVERAGE=$COVERAGE_PERCENTAGE%"'
artifacts:
when: always
expire_in: 1 day
paths:
- ./**/TestResults.xml
- ./Cobertura.xml
reports:
junit:
- ./**/TestResults.xml
coverage_report:
coverage_format: cobertura
path: ./Cobertura.xml
retry:
max: 2
when: script_failure
validate_docker:
stage: validate
timeout: 3h
needs:
- build
script:
- docker buildx use aiur-global-builder
- docker buildx build . --platform linux/amd64,linux/arm64
rules:
- exists:
- Dockerfile
validate_apkg:
stage: validate
needs:
- build
script:
- "which apkg || dotnet tool install Aiursoft.Apkg.Client --global $CUSTOM_NUGET_ARGS -v d"
- |
aosproj_files=$(find . -type f -name '*.aosproj')
if [ -z "$aosproj_files" ]; then
echo "No .aosproj files found. Skipping APKG validation."
exit 0
fi
echo "$aosproj_files" | while IFS= read -r aosproj_file; do
echo "Building APKG project: $aosproj_file"
apkg build --path "$(dirname "$aosproj_file")" --all || exit 1
done
pack:
stage: publish
needs:
- lint
- test
- validate_apkg
# validate_docker is absent when this template has no Dockerfile. If the
# job exists, pack still waits for it to succeed.
- job: validate_docker
optional: true
script:
- dotnet build -maxcpucount:1 --configuration Release --no-self-contained -p:GeneratePackageOnBuild=false *.sln
- dotnet pack -maxcpucount:1 --configuration Release --no-build *.sln
artifacts:
expire_in: 1 week
paths:
- "**/*.nupkg"
deploy_local_nuget:
stage: deploy
environment: production
needs:
- pack
script:
- |
for file in $(find . -name "*.nupkg"); do
dotnet nuget push "$file" --api-key "$LOCAL_NUGET_API_KEY" --source "https://nuget.aiursoft.com/v3/index.json" --skip-duplicate || exit 1;
done
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
deploy_public_nuget:
stage: deploy
environment: production
needs:
- pack
script:
- |
for file in $(find . -name "*.nupkg"); do
dotnet nuget push "$file" --api-key "$NUGET_API_KEY" --source "https://api.nuget.org/v3/index.json" --skip-duplicate || exit 1;
done
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
deploy_docker_all:
stage: deploy
timeout: 3h
retry:
max: 2
environment: production
needs:
- job: pack
artifacts: false
script:
- if [ "$CI_COMMIT_REF_NAME" = "master" ]; then TAG="latest"; else TAG="$CI_COMMIT_REF_NAME"; fi
- if [ "$CI_PROJECT_NAMESPACE" = "anduin" ]; then HUB_NAMESPACE="anduin2019"; else HUB_NAMESPACE="$CI_PROJECT_NAMESPACE"; fi
- LOCAL_TARGET_COM="hub.aiursoft.com/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$TAG"
- PUBLIC_TARGET="$HUB_NAMESPACE/$CI_PROJECT_NAME:$TAG"
- echo "$LOCAL_DOCKER_PASSWORD" | docker login hub.aiursoft.com -u "$LOCAL_DOCKER_USERNAME" --password-stdin
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker buildx use aiur-global-builder
# Both required destinations must succeed. China replication is handled
# asynchronously by puller_cn after the home-registry push completes.
- docker buildx build . --platform linux/amd64,linux/arm64 --tag "$LOCAL_TARGET_COM" --tag "$PUBLIC_TARGET" --push
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
exists:
- Dockerfile