summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: 1a8e22ed8268de24a934f6f677e6ee61539c970c (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
default:
  interruptible: true

# Note: We set `needs` on each job to control the job DAG.
# See https://docs.gitlab.com/ee/ci/yaml/#needs
stages:
  - checks
  - build
  - test

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never
    - if: $CI_COMMIT_BRANCH

# https://blog.nimbleways.com/let-s-make-faster-gitlab-ci-cd-pipelines/
variables:
  FF_USE_NEW_SHELL_ESCAPE: "true"
  FF_USE_FASTZIP: "true"
  # These can be specified per job or per pipeline
  ARTIFACT_COMPRESSION_LEVEL: "fast"
  CACHE_COMPRESSION_LEVEL: "fast"

.Ubuntu_Image:
  tags:
    - docker
    - linux
  image: ubuntu:22.04
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"

Ubuntu_GCC_preprocess:
  extends: .Ubuntu_Image
  cache:
    key: Ubuntu_GCC_preprocess.ubuntu_22.04.v1
    paths:
      - apt-cache/
      - .cache/pip/
  stage: build
  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  before_script:
    - CI/install_debian_deps.sh openmw-deps openmw-deps-dynamic gcc_preprocess
    - pip3 install --user click termtables
  script:
    - CI/ubuntu_gcc_preprocess.sh

.Ubuntu:
  extends: .Ubuntu_Image
  cache:
    paths:
    - apt-cache/
    - ccache/
  stage: build
  variables:
    CMAKE_EXE_LINKER_FLAGS: -fuse-ld=mold
  script:
    - df -h
    - export CCACHE_BASEDIR="`pwd`"
    - export CCACHE_DIR="`pwd`/ccache" && mkdir -pv "$CCACHE_DIR"
    - ccache -z -M "${CCACHE_SIZE}"
    - CI/before_script.linux.sh
    - cd build
    - cmake --build . -- -j $(nproc)
    - df -h
    - du -sh .
    - find . | grep '\.o$' | xargs rm -f
    - df -h
    - du -sh .
    - cmake --install .
    - if [[ "${BUILD_TESTS_ONLY}" ]]; then ./openmw_test_suite --gtest_output="xml:openmw_tests.xml"; fi
    - if [[ "${BUILD_TESTS_ONLY}" ]]; then ./openmw-cs-tests --gtest_output="xml:openmw_cs_tests.xml"; fi
    - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_detournavigator_navmeshtilescache_benchmark; fi
    - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_esm_refid_benchmark; fi
    - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_settings_access_benchmark; fi
    - ccache -s
    - df -h
    - if [[ "${BUILD_WITH_CODE_COVERAGE}" ]]; then gcovr --xml-pretty --exclude-unreachable-branches --print-summary --root "${CI_PROJECT_DIR}" -j $(nproc) -o ../coverage.xml; fi
    - ls | grep -v -e '^extern$' -e '^install$' -e '^openmw_tests.xml$' -e '^openmw_cs_tests.xml$' | xargs -I '{}' rm -rf './{}'
    - cd ..
    - df -h
    - du -sh build/
    - du -sh build/install/
    - du -sh apt-cache/
    - du -sh ccache/
  artifacts:
    paths:
      - build/install/

Coverity:
  tags:
    - docker
    - linux
  image: ubuntu:22.04
  stage: build
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
  cache:
    key: Coverity.ubuntu_22.04.v1
    paths:
    - apt-cache/
    - ccache/
  variables:
    CCACHE_SIZE: 2G
    CC: clang-12
    CXX: clang++-12
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -O0
  before_script:
    - CI/install_debian_deps.sh coverity openmw-deps openmw-deps-dynamic
    - curl -o /tmp/cov-analysis-linux64.tgz https://scan.coverity.com/download/linux64
      --form project=$COVERITY_SCAN_PROJECT_NAME --form token=$COVERITY_SCAN_TOKEN
    - tar xfz /tmp/cov-analysis-linux64.tgz
  script:
    - export CCACHE_BASEDIR="$(pwd)"
    - export CCACHE_DIR="$(pwd)/ccache"
    - mkdir -pv "${CCACHE_DIR}"
    - ccache -z -M "${CCACHE_SIZE}"
    - CI/before_script.linux.sh
    - cov-analysis-linux64-*/bin/cov-configure --template --comptype prefix --compiler ccache
    # Remove the specific targets and build everything once we can do it under 3h
    - cov-analysis-linux64-*/bin/cov-build --dir cov-int cmake --build build -- -j $(nproc)
    - ccache -s
  after_script:
    - tar cfz cov-int.tar.gz cov-int
    - curl https://scan.coverity.com/builds?project=$COVERITY_SCAN_PROJECT_NAME
      --form token=$COVERITY_SCAN_TOKEN --form email=$GITLAB_USER_EMAIL
      --form file=@cov-int.tar.gz --form version="$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA"
      --form description="CI_COMMIT_SHORT_SHA / $CI_COMMIT_TITLE / $CI_COMMIT_REF_NAME:$CI_PIPELINE_ID"
  artifacts:
    paths:
      - /builds/OpenMW/openmw/cov-int/build-log.txt

Ubuntu_GCC:
  extends: .Ubuntu
  cache:
    key: Ubuntu_GCC.ubuntu_22.04.v1
  before_script:
    - CI/install_debian_deps.sh gcc openmw-deps openmw-deps-dynamic
  variables:
    CC: gcc
    CXX: g++
    CCACHE_SIZE: 3G
  # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks.
  timeout: 2h

Ubuntu_GCC_asan:
  extends: Ubuntu_GCC
  cache:
    key: Ubuntu_GCC_asan.ubuntu_22.04.v1
  variables:
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -g -O1 -fno-omit-frame-pointer -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak
    CMAKE_EXE_LINKER_FLAGS: -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak -fuse-ld=mold
    BUILD_OPENMW_ONLY: 1

Clang_Format:
  extends: .Ubuntu_Image
  stage: checks
  cache:
    key: Ubuntu_Clang_Format.ubuntu_22.04.v1
    paths:
      - apt-cache/
  variables:
    CLANG_FORMAT: clang-format-14
  before_script:
    - CI/install_debian_deps.sh openmw-clang-format
  script:
    - CI/check_cmake_format.sh
    - CI/check_file_names.sh
    - CI/check_clang_format.sh

Lupdate:
  extends: .Ubuntu_Image
  stage: checks
  cache:
    key: Ubuntu_lupdate.ubuntu_22.04.v1
    paths:
      - apt-cache/
  variables:
    LUPDATE: lupdate
  before_script:
    - CI/install_debian_deps.sh openmw-qt-translations
  script:
    - CI/check_qt_translations.sh

Teal:
  stage: checks
  extends: .Ubuntu_Image
  before_script:
    - apt-get update
    - apt-get -y install curl wget make build-essential libreadline-dev git-core zip unzip
  script:
    - CI/teal_ci.sh
  artifacts:
    paths:
      - teal_declarations.zip

Ubuntu_GCC_Debug:
  extends: .Ubuntu
  cache:
    key: Ubuntu_GCC_Debug.ubuntu_22.04.v2
  before_script:
    - CI/install_debian_deps.sh gcc openmw-deps openmw-deps-dynamic
  variables:
    CC: gcc
    CXX: g++
    CCACHE_SIZE: 3G
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -O0
    BUILD_SHARED_LIBS: 1
  # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks.
  timeout: 2h

Ubuntu_GCC_tests:
  extends: Ubuntu_GCC
  cache:
    key: Ubuntu_GCC_tests.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

.Ubuntu_GCC_tests_Debug:
  extends: Ubuntu_GCC
  cache:
    key: Ubuntu_GCC_tests_Debug.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -g -O0 -D_GLIBCXX_ASSERTIONS
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

Ubuntu_GCC_tests_asan:
  extends: Ubuntu_GCC
  cache:
    key: Ubuntu_GCC_tests_asan.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -g -O1 -fno-omit-frame-pointer -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak
    CMAKE_EXE_LINKER_FLAGS: -fsanitize=address -fsanitize=pointer-subtract -fsanitize=leak -fuse-ld=mold
    ASAN_OPTIONS: halt_on_error=1:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

Ubuntu_GCC_tests_ubsan:
  extends: Ubuntu_GCC
  cache:
    key: Ubuntu_GCC_tests_ubsan.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -g -O0 -fsanitize=undefined
    UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

.Ubuntu_GCC_tests_tsan:
  extends: Ubuntu_GCC
  cache:
    key: Ubuntu_GCC_tests_tsan.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -g -O2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=thread -fPIE
    CMAKE_EXE_LINKER_FLAGS: -pthread -pie -fsanitize=thread -fuse-ld=mold
    TSAN_OPTIONS: second_deadlock_stack=1:halt_on_error=1
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

Ubuntu_GCC_tests_coverage:
  extends: .Ubuntu_GCC_tests_Debug
  cache:
    key: Ubuntu_GCC_tests_coverage.ubuntu_22.04.v1
  variables:
    BUILD_WITH_CODE_COVERAGE: 1
  before_script:
    - CI/install_debian_deps.sh gcc openmw-deps openmw-deps-dynamic openmw-coverage
  coverage: /^\s*lines:\s*\d+.\d+\%/
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml
      junit: build/*_tests.xml

.Ubuntu_Static_Deps:
  extends: Ubuntu_Clang
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"
      changes:
        - "**/CMakeLists.txt"
        - "cmake/**/*"
        - "CI/**/*"
        - ".gitlab-ci.yml"
  cache:
    key: Ubuntu_Static_Deps.ubuntu_22.04.v1
    paths:
      - apt-cache/
      - ccache/
      - build/extern/fetched/
  before_script:
    - CI/install_debian_deps.sh clang openmw-deps openmw-deps-static
  variables:
    CI_OPENMW_USE_STATIC_DEPS: 1
    CC: clang
    CXX: clang++
    CXXFLAGS: -O0
  timeout: 3h

.Ubuntu_Static_Deps_tests:
  extends: .Ubuntu_Static_Deps
  cache:
    key: Ubuntu_Static_Deps_tests.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
    CC: clang
    CXX: clang++
    CXXFLAGS: -O0
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

Ubuntu_Clang:
  extends: .Ubuntu
  before_script:
    - CI/install_debian_deps.sh clang openmw-deps openmw-deps-dynamic
  cache:
    key: Ubuntu_Clang.ubuntu_22.04.v2
  variables:
    CC: clang
    CXX: clang++
    CCACHE_SIZE: 2G
  # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks.
  timeout: 3h

.Ubuntu_Clang_Tidy_Base:
  extends: Ubuntu_Clang
  before_script:
    - CI/install_debian_deps.sh clang clang-tidy openmw-deps openmw-deps-dynamic
  cache:
    key: Ubuntu_Clang_Tidy.ubuntu_22.04.v1
  variables:
    CMAKE_BUILD_TYPE: Debug
    CMAKE_CXX_FLAGS_DEBUG: -O0
    CI_CLANG_TIDY: 1
    CCACHE_BASEDIR: $CI_PROJECT_DIR
    CCACHE_DIR: $CI_PROJECT_DIR/ccache
  script:
    - mkdir -pv "${CCACHE_DIR}"
    - ccache -z -M "${CCACHE_SIZE}"
    - CI/before_script.linux.sh
    - cd build
    - find . -name *.o -exec touch {} \;
    - cmake --build . -- -j $(nproc) ${BUILD_TARGETS}
    - ccache -s
  artifacts:
    paths:
      - build/
    expire_in: 12h
  timeout: 3h

Ubuntu_Clang_Tidy_components:
  extends: .Ubuntu_Clang_Tidy_Base
  variables:
    BUILD_TARGETS: components components_qt oics osg-ffmpeg-videoplayer osgQt
  timeout: 3h

Ubuntu_Clang_Tidy_openmw:
  extends: .Ubuntu_Clang_Tidy_Base
  needs:
    - Ubuntu_Clang_Tidy_components
  variables:
    BUILD_TARGETS: openmw
  timeout: 3h

Ubuntu_Clang_Tidy_openmw-cs:
  extends: .Ubuntu_Clang_Tidy_Base
  needs:
    - Ubuntu_Clang_Tidy_components
  variables:
    BUILD_TARGETS: openmw-cs openmw-cs-tests
  timeout: 3h

Ubuntu_Clang_Tidy_other:
  extends: .Ubuntu_Clang_Tidy_Base
  needs:
    - Ubuntu_Clang_Tidy_components
  variables:
    BUILD_TARGETS: bsatool esmtool openmw-launcher openmw-iniimporter openmw-essimporter openmw-wizard niftest openmw_test_suite openmw-navmeshtool openmw-bulletobjecttool
  timeout: 3h

.Ubuntu_Clang_tests:
  extends: Ubuntu_Clang
  cache:
    key: Ubuntu_Clang_tests.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

Ubuntu_Clang_tests_Debug:
  extends: Ubuntu_Clang
  cache:
    key: Ubuntu_Clang_tests_Debug.ubuntu_22.04.v1
  variables:
    CCACHE_SIZE: 1G
    BUILD_TESTS_ONLY: 1
    CMAKE_BUILD_TYPE: Debug
  artifacts:
    paths: []
    name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
    when: always
    reports:
      junit: build/*_tests.xml

.Ubuntu_integration_tests_base:
  extends: .Ubuntu_Image
  stage: test
  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  cache:
    paths:
      - .cache/pip
      - apt-cache/
  before_script:
    - CI/install_debian_deps.sh $OPENMW_DEPS
    - pip3 install --user numpy matplotlib termtables click
  script:
    - CI/run_integration_tests.sh
  after_script:
    - if [[ -f /tmp/openmw-crash.log ]]; then cat /tmp/openmw-crash.log; fi

Ubuntu_Clang_integration_tests:
  extends: .Ubuntu_integration_tests_base
  needs:
    - Ubuntu_Clang
  cache:
    key: Ubuntu_Clang_integration_tests.ubuntu_22.04.v2
  variables:
    OPENMW_DEPS: openmw-integration-tests

Ubuntu_GCC_integration_tests_asan:
  extends: .Ubuntu_integration_tests_base
  needs:
    - Ubuntu_GCC_asan
  cache:
    key: Ubuntu_GCC_integration_tests_asan.ubuntu_22.04.v1
  variables:
    OPENMW_DEPS: openmw-integration-tests libasan6
    ASAN_OPTIONS: halt_on_error=1:strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_leaks=0

.MacOS:
  stage: build
  rules:
    - if: $CI_PROJECT_ID == "7107382"
  cache:
    paths:
    - ccache/
  script:
    - rm -fr build  # remove the build directory
    - CI/before_install.osx.sh
    - export CCACHE_BASEDIR="$(pwd)"
    - export CCACHE_DIR="$(pwd)/ccache"
    - mkdir -pv "${CCACHE_DIR}"
    - ccache -z -M "${CCACHE_SIZE}"
    - CI/before_script.osx.sh
    - cd build; make -j $(sysctl -n hw.logicalcpu) package
    - for dmg in *.dmg; do mv "$dmg" "${dmg%.dmg}_${CI_COMMIT_REF_NAME##*/}_${CI_JOB_ID}.dmg"; done
    - |
      if [[ -n "${AWS_ACCESS_KEY_ID}" ]]; then
        artifactDirectory="${CI_PROJECT_NAMESPACE//[\"<>|$'\t'\/\\?*]/_}/${CI_COMMIT_REF_NAME//[\"<>|$'\t'\/\\?*]/_}/${CI_COMMIT_SHORT_SHA//[\"<>|$'\t'\/\\?*]/_}-${CI_JOB_ID//[\"<>|$'\t'\/\\?*]/_}/"
        for dmg in *.dmg; do
          aws --endpoint-url https://rgw.ctrl-c.liu.se s3 cp "${dmg}" s3://openmw-artifacts/${artifactDirectory}
        done
      fi
    - ccache -s
  artifacts:
    paths:
      - build/OpenMW-*.dmg
      - "build/**/*.log"

macOS13_Xcode14_arm64:
  extends: .MacOS
  image: macos-12-xcode-14
  tags:
    - saas-macos-medium-m1
  cache:
    key: macOS12_Xcode14_arm64.v4
  variables:
    CCACHE_SIZE: 3G

.Windows_Ninja_Base:
  tags:
    - windows
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"
  before_script:
  - Get-Volume
  - Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
  - choco source add -n=openmw-proxy -s="https://repo.openmw.org/repository/Chocolatey/" --priority=1
  - choco source disable -n=chocolatey
  - choco install git --force --params "/GitAndUnixToolsOnPath" -y
  - choco install 7zip -y
  - choco install ccache -y
  - choco install vswhere -y
  - choco install ninja -y
  - choco install python -y
  - choco install awscli -y
  - refreshenv
  - |
    function Make-SafeFileName {
      param(
        [Parameter(Mandatory=$true)]
        [String]
        $FileName
      )
      [IO.Path]::GetInvalidFileNameChars() | ForEach-Object {
        $FileName = $FileName.Replace($_, '_')
      }
      return $FileName
    }
  stage: build
  script:
    - Get-Volume
    - $time = (Get-Date -Format "HH:mm:ss")
    - echo ${time}
    - echo "started by ${GITLAB_USER_NAME}"
    - $env:CCACHE_BASEDIR = Get-Location
    - $env:CCACHE_DIR = "$(Get-Location)\ccache"
    - New-Item -Type Directory -Force -Path $env:CCACHE_DIR
    - New-Item -Type File -Force -Path MSVC2019_64_Ninja\.cmake\api\v1\query\codemodel-v2
    - sh CI/before_script.msvc.sh -c $config -p Win64 -v 2019 -k -V -N -b -t -C $multiview -E
    - Get-Volume
    - cd MSVC2019_64_Ninja
    - .\ActivateMSVC.ps1
    - cmake --build . --config $config
    - ccache --show-stats
    - cd $config
    - echo "CI_COMMIT_REF_NAME ${CI_COMMIT_REF_NAME}`nCI_JOB_ID ${CI_JOB_ID}`nCI_COMMIT_SHA ${CI_COMMIT_SHA}" | Out-File -Encoding UTF8 CI-ID.txt
    - $artifactDirectory = "$(Make-SafeFileName("${CI_PROJECT_NAMESPACE}"))/$(Make-SafeFileName("${CI_COMMIT_REF_NAME}"))/$(Make-SafeFileName("${CI_COMMIT_SHORT_SHA}-${CI_JOB_ID}"))/"
    - Get-ChildItem -Recurse *.ilk | Remove-Item
    - |
      if (Get-ChildItem -Recurse *.pdb) {
        7z a -tzip "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}_${CI_JOB_ID}_symbols.zip"))" '*.pdb' CI-ID.txt
        if (Test-Path env:AWS_ACCESS_KEY_ID) {
          aws --endpoint-url https://rgw.ctrl-c.liu.se s3 cp "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}_${CI_JOB_ID}_symbols.zip"))" s3://openmw-artifacts/${artifactDirectory}
        }
        Push-Location ..
        ..\CI\Store-Symbols.ps1
        if (Test-Path env:AWS_ACCESS_KEY_ID) {
          aws --endpoint-url https://rgw.ctrl-c.liu.se s3 cp --recursive --exclude * --include *.ex_ --include *.dl_ --include *.pd_ .\SymStore s3://openmw-sym
        }
        7z a -tzip "..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}_${CI_JOB_ID}_sym_store.zip"))" '.\SymStore\*' $config\CI-ID.txt
        Pop-Location
        Get-ChildItem -Recurse *.pdb | Remove-Item
      }
    - 7z a -tzip "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}.zip"))" '*'
    - |
      if (Test-Path env:AWS_ACCESS_KEY_ID) {
        aws --endpoint-url https://rgw.ctrl-c.liu.se s3 cp "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}.zip"))" s3://openmw-artifacts/${artifactDirectory}
      }
    - if ($executables) { foreach ($exe in $executables.Split(',')) { & .\$exe } }
  after_script:
    - Get-Volume
    - Copy-Item C:\ProgramData\chocolatey\logs\chocolatey.log
  cache:
    key: ninja-v8
    paths:
    - ccache
    - deps
    - MSVC2019_64_Ninja/deps/Qt
  artifacts:
    when: always
    paths:
    - "*.zip"
    - "*.log"
    - MSVC2019_64_Ninja/*.log
    - MSVC2019_64_Ninja/*/*.log
    - MSVC2019_64_Ninja/*/*/*.log
    - MSVC2019_64_Ninja/*/*/*/*.log
    - MSVC2019_64_Ninja/*/*/*/*/*.log
    - MSVC2019_64_Ninja/*/*/*/*/*/*.log
    - MSVC2019_64_Ninja/*/*/*/*/*/*/*.log
    - MSVC2019_64_Ninja/*/*/*/*/*/*/*/*.log
  # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks.
  timeout: 2h

.Windows_Ninja_Release:
  extends:
    - .Windows_Ninja_Base
  variables:
    config: "Release"

.Windows_Ninja_Release_MultiView:
  extends:
    - .Windows_Ninja_Base
  variables:
    multiview: "-M"
    config: "Release"

.Windows_Ninja_Debug:
  extends:
    - .Windows_Ninja_Base
  variables:
    config: "Debug"

.Windows_Ninja_RelWithDebInfo:
  extends:
    - .Windows_Ninja_Base
  variables:
    config: "RelWithDebInfo"
    # Gitlab can't successfully execute following binaries due to unknown reason
    # executables: "openmw_test_suite.exe,openmw_detournavigator_navmeshtilescache_benchmark.exe"

.Windows_MSBuild_Base:
  tags:
    - windows
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"
  before_script:
  - Get-Volume
  - Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
  - choco source add -n=openmw-proxy -s="https://repo.openmw.org/repository/Chocolatey/" --priority=1
  - choco source disable -n=chocolatey
  - choco install git --force --params "/GitAndUnixToolsOnPath" -y
  - choco install 7zip -y
  - choco install ccache -y
  - choco install vswhere -y
  - choco install python -y
  - choco install awscli -y
  - refreshenv
  - |
    function Make-SafeFileName {
      param(
        [Parameter(Mandatory=$true)]
        [String]
        $FileName
      )
      [IO.Path]::GetInvalidFileNameChars() | ForEach-Object {
        $FileName = $FileName.Replace($_, '_')
      }
      return $FileName
    }
  stage: build
  script:
    - Get-Volume
    - $time = (Get-Date -Format "HH:mm:ss")
    - echo ${time}
    - echo "started by ${GITLAB_USER_NAME}"
    - $env:CCACHE_BASEDIR = Get-Location
    - $env:CCACHE_DIR = "$(Get-Location)\ccache"
    - New-Item -Type Directory -Force -Path $env:CCACHE_DIR
    - New-Item -Type File -Force -Path MSVC2019_64\.cmake\api\v1\query\codemodel-v2
    - sh CI/before_script.msvc.sh -c $config -p Win64 -v 2019 -k -V -b -t -C $multiview -E
    - cd MSVC2019_64
    - Get-Volume
    - cmake --build . --config $config
    - ccache --show-stats
    - cd $config
    - echo "CI_COMMIT_REF_NAME ${CI_COMMIT_REF_NAME}`nCI_JOB_ID ${CI_JOB_ID}`nCI_COMMIT_SHA ${CI_COMMIT_SHA}" | Out-File -Encoding UTF8 CI-ID.txt
    - $artifactDirectory = "$(Make-SafeFileName("${CI_PROJECT_NAMESPACE}"))/$(Make-SafeFileName("${CI_COMMIT_REF_NAME}"))/$(Make-SafeFileName("${CI_COMMIT_SHORT_SHA}-${CI_JOB_ID}"))/"
    - Get-ChildItem -Recurse *.ilk | Remove-Item
    - |
      if (Get-ChildItem -Recurse *.pdb) {
        7z a -tzip "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}_${CI_JOB_ID}_symbols.zip"))" '*.pdb' CI-ID.txt
        if (Test-Path env:AWS_ACCESS_KEY_ID) {
          aws --endpoint-url https://rgw.ctrl-c.liu.se s3 cp "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}_${CI_JOB_ID}_symbols.zip"))" s3://openmw-artifacts/${artifactDirectory}
        }
        Push-Location ..
        ..\CI\Store-Symbols.ps1
        if (Test-Path env:AWS_ACCESS_KEY_ID) {
          aws --endpoint-url https://rgw.ctrl-c.liu.se s3 cp --recursive --exclude * --include *.ex_ --include *.dl_ --include *.pd_ .\SymStore s3://openmw-sym
        }
        7z a -tzip "..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}_${CI_JOB_ID}_sym_store.zip"))" '.\SymStore\*' $config\CI-ID.txt
        Pop-Location
        Get-ChildItem -Recurse *.pdb | Remove-Item
      }
    - 7z a -tzip "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}.zip"))" '*'
    - |
      if (Test-Path env:AWS_ACCESS_KEY_ID) {
        aws --endpoint-url https://rgw.ctrl-c.liu.se s3 cp "..\..\$(Make-SafeFileName("OpenMW_MSVC2019_64_${config}_${CI_COMMIT_REF_NAME}.zip"))" s3://openmw-artifacts/${artifactDirectory}
      }
    - if ($executables) { foreach ($exe in $executables.Split(',')) { & .\$exe } }
  after_script:
    - Get-Volume
    - Copy-Item C:\ProgramData\chocolatey\logs\chocolatey.log
  cache:
    key: msbuild-v8
    paths:
    - ccache
    - deps
    - MSVC2019_64/deps/Qt
  artifacts:
    when: always
    paths:
    - "*.zip"
    - "*.log"
    - MSVC2019_64/*.log
    - MSVC2019_64/*/*.log
    - MSVC2019_64/*/*/*.log
    - MSVC2019_64/*/*/*/*.log
    - MSVC2019_64/*/*/*/*/*.log
    - MSVC2019_64/*/*/*/*/*/*.log
    - MSVC2019_64/*/*/*/*/*/*/*.log
    - MSVC2019_64/*/*/*/*/*/*/*/*.log
  # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks.
  timeout: 2h

.Windows_MSBuild_Release:
  extends:
    - .Windows_MSBuild_Base
  variables:
    config: "Release"

.Windows_MSBuild_Debug:
  extends:
    - .Windows_MSBuild_Base
  variables:
    config: "Debug"

Windows_MSBuild_RelWithDebInfo:
  extends:
    - .Windows_MSBuild_Base
  variables:
    config: "RelWithDebInfo"
    # Gitlab can't successfully execute following binaries due to unknown reason
    # executables: "openmw_test_suite.exe,openmw_detournavigator_navmeshtilescache_benchmark.exe"
  # temporarily enabled while we're linking these on the downloads page
  rules:
    # run this for both pushes and schedules so 'latest successful pipeline for branch' always includes it
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "schedule"

.Ubuntu_AndroidNDK_arm64-v8a:
  tags:
    - linux
  image: psi29a/android-ndk:focal-ndk22
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"
  variables:
    CCACHE_SIZE: 3G
  cache:
    key: Ubuntu__Focal_AndroidNDK_r22b_arm64-v8a.v2
    paths:
      - apt-cache/
      - ccache/
      - build/extern/fetched/
  before_script:
    - CI/install_debian_deps.sh android
  stage: build
  script:
    - df -h
    - export CCACHE_BASEDIR="`pwd`"
    - export CCACHE_DIR="`pwd`/ccache" && mkdir -pv "$CCACHE_DIR"
    - ccache -z -M "${CCACHE_SIZE}"
    - CI/before_install.android.sh
    - CI/before_script.android.sh
    - cd build
    - cmake --build . -- -j $(nproc)
    # - cmake --install .  # no one uses builds anyway, disable until 'no space left' is resolved
    - ccache -s
    - df -h
    - ls | grep -v -e '^extern$' -e '^install$' | xargs -I '{}' rm -rf './{}'
    - cd ..
    - df -h
    - du -sh build/
    # - du -sh build/install/ # no install dir because it's commented out above
    - du -sh apt-cache/
    - du -sh ccache/
    - du -sh build/extern/fetched/
  artifacts:
    paths:
      - build/install/
  # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks.
  timeout: 1h30m

.FindMissingMergeRequests:
  image: python:latest
  stage: build
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  cache:
    key: FindMissingMergeRequests.v1
    paths:
      - .cache/pip
  before_script:
    - pip3 install --user requests click discord_webhook
  script:
    - scripts/find_missing_merge_requests.py --project_id=$CI_PROJECT_ID --ignored_mrs_path=$CI_PROJECT_DIR/.resubmitted_merge_requests.txt

.flatpak:
    image: 'docker.io/bilelmoussaoui/flatpak-github-actions'
    stage: build
    script:
      - flatpak install -y flathub org.kde.Platform/x86_64/5.15-21.08
      - flatpak install -y flathub org.kde.Sdk/x86_64/5.15-21.08
      - flatpak-builder --ccache --force-clean --repo=repo build CI/org.openmw.OpenMW.devel.yaml
      - flatpak build-bundle ./repo openmw.flatpak org.openmw.OpenMW.devel
    cache:
      key: flatpak
      paths: 
        - ".flatpak-builder"
    artifacts:
      untracked: false
      paths:
        - "openmw.flatpak"
    # When CCache doesn't exist (e.g. first build on a fork), build takes more than 1h, which is the default for forks.
    # Flatpak Builds compile all dependencies aswell so need more time. Build results of libraries are cached
    timeout: 4h