-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathFastfile
More file actions
1437 lines (1194 loc) · 48.4 KB
/
Copy pathFastfile
File metadata and controls
1437 lines (1194 loc) · 48.4 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
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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright (Change Date see Readme), gematik GmbH
#
# Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the
# European Commission – subsequent versions of the EUPL (the "Licence").
# You may not use this work except in compliance with the Licence.
#
# You find a copy of the Licence in the "Licence" file or at
# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the Licence is distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
# In case of changes by gematik find details in the "Readme" file.
#
# See the Licence for the specific language governing permissions and limitations under the Licence.
#
# *******
#
# For additional notes and disclaimer from gematik and in case of changes by gematik find details in the "Readme" file.
#
require 'json'
xcodes(
version: ENV["FL_XCODE_VERSION"] || "26.2.0",
select_for_current_build_only: true,
update_list: false
)
fastlane_version "2.187.0"
# Figure out if a setting is truthy
def true?(obj)
if obj.nil?
raise "Object is nil. Not a valid boolean value"
end
obj.to_s.downcase == "true"
end
lane :resolve_dependencies do |options|
sh "rm -rf DerivedData/SourcePackages"
if File.exist? "../Package.swift"
spm(command: "resolve")
end
end
lane :generate_xcodeproj do |options|
sh("pushd ..; mint run xcodegen generate --spec project.yml; popd")
end
desc "Build and test (scan) the project for macOS"
desc "The lane to run by ci on every commit."
desc ""
desc "###Example:"
desc "```\nfastlane build_mac mac_schemes:ProjectScheme mac_sdk:\"macos11\" mac_destination:\"platform=macOS,arch=x86_64\" configuration:Release --env osx\n```"
desc "###Options"
desc " * **`project`**: The path to the Xcode project file. (`G_PROJECT`)"
desc " * **`schemes`**: The (shared) schemes to build for the mac build. If only one Scheme exists you can omit this and specify a scheme in a Scanfile (`G_MAC_SCHEMES`)"
desc " * **`mac_sdk`**: The SDK version to build against [default: macosx]. (`G_MAC_SDK`)"
desc ""
lane :build_mac do |options|
if options[:mac_sdk]
sdk = options[:mac_sdk]
elsif ENV["G_MAC_SDK"]
sdk = ENV["G_MAC_SDK"]
else
sdk = "macosx"
end
if options[:mac_destination]
destination = options[:mac_destination]
elsif ENV["G_MAC_DESTINATION"]
destination = ENV["G_MAC_DESTINATION"]
else
destination = "platform=macOS,arch=arm64"
end
if options[:schemes]
schemes = options[:schemes]
elsif ENV["G_MAC_SCHEMES"]
schemes = ENV["G_MAC_SCHEMES"]
else
scan(
sdk: sdk,
destination: destination,
output_directory: "./fastlane/test_output/mac"
)
end
if !schemes.nil?
schemes.split(",").each do |scheme|
scan(
scheme: scheme,
sdk: sdk,
destination: destination,
output_directory: "./fastlane/test_output/mac/#{scheme}"
)
end
end
end
desc "Build and test (scan) the project for iOS"
desc "The lane to run by ci on every commit."
desc ""
desc "###Example:"
desc "```\nbundle exec fastlane build_ios ios_schemes:ProjectScheme\n```"
desc "###Options"
desc " * **`schemes`**: The (shared) schemes to build for the iOS build. If only one Scheme exists you can omit this and specify a scheme in a Scanfile (`G_IOS_SCHEMES`)"
desc ""
lane :build_ios do |options|
reset_simulator_contents
if options[:schemes]
schemes = options[:schemes]
elsif ENV["G_IOS_SCHEMES"]
schemes = ENV["G_IOS_SCHEMES"]
else
scan(
output_directory: "./fastlane/test_output/ios"
)
end
if !schemes.nil?
schemes.split(",").each do |scheme|
scan(
scheme: scheme,
output_directory: "./fastlane/test_output/ios/#{scheme}"
)
end
end
end
lane :uitests_ios_setup do |options|
scheme = "UITests_iOS"
scan(
scheme: scheme,
configuration: "Debug",
build_for_testing: true,
output_directory: "./fastlane/test_output/uitests"
)
end
lane :uitests_ios do |options|
reset_simulator_contents
scan_result = scan(
scheme: "UITests_iOS",
configuration: "Debug",
prelaunch_simulator: true,
output_directory: "./fastlane/test_output/uitests",
number_of_retries: 2,
output_style: 'raw'
)
flaky_note_if_necessary(scan_result: scan_result)
trainer(
output_directory: "./fastlane/test_output/uitests",
output_remove_retry_attempts: true,
extension: ".junit"
)
end
desc "Pre-build AllIntegrationTest scheme."
lane :integration_tests_setup do
puts "Build IntegrationTests scheme for testing."
scan(
scheme: "AllIntegrationTests_iOS",
configuration: "Debug",
build_for_testing: true,
output_directory: "./fastlane/test_output/integration_tests_setup" # default is ./fastlane/test_output
)
end
desc "Test the integration of the app with external dependencies e.g. IDP/FD."
desc "Runs targets, that are excluded from normal CI builds."
lane :integration_tests do |options|
reset_simulator_contents
reset_test_outputs
if options[:app_conf]
app_conf = options[:app_conf]
elsif ENV["APP_CONF"]
app_conf = ENV["APP_CONF"]
else
app_conf = "NO_APP_CONF_INJECTED_INTO_FASTFILE_INTEGRATION_TESTS_LANE"
end
# Set environment variable to be read from `Swift.ProcessInfo.processInfo.environment`
ENV["APP_CONF"] = "#{app_conf}"
puts "========== Run the tests for env: #{app_conf} =========="
scan_result = scan(
scheme: "AllIntegrationTests_iOS",
configuration: "Debug",
test_without_building: true,
number_of_retries: 3,
output_directory: "./fastlane/test_output/#{app_conf}", # default is ./fastlane/test_output
output_style: 'raw'
)
flaky_note_if_necessary(scan_result: scan_result)
trainer(
output_directory: "./fastlane/test_output/#{app_conf}",
output_remove_retry_attempts: true,
extension: ".junit"
)
rescue => ex
jenkins_job_url = "https://jenkins.prod.ccs.gematik.solutions/job/e-Rezept-iOS-App-Integration_Tests/#{ENV['BUILD_NUMBER']}"
message = "Failed Integration Tests for configuration: #{app_conf} +++++ Reason: #{ex} +++++ Basic Junit report: #{jenkins_job_url}/artifact/fastlane/test_output/#{app_conf}/report.html +++++ Console log search for term: \\\"========== Run the tests for env: #{app_conf} ==========\\\" in: #{jenkins_job_url}/consoleFull"
notify_teams_channel(
channel_url: ENV["TEAMS_CHANNEL_URL_INT"],
stream: "Integration Tests",
success: false,
optional_message: message
) if is_ci
UI.error(message)
raise
end
desc "Lane that builds for macOS and iOS by calling `build_mac` and `build_ios`"
desc "See other lanes for configuration of options and/or ENV."
desc ""
desc "###Example:"
desc "```\nfastlane build_all skip_ios:true skip_macos:false --env osx\n```"
desc "###Options"
desc " * **`skip_ios`**: Whether to skip the ios build [default: false]. (`G_BUILD_IOS_SKIP`)"
desc " * **`skip_macos`**: Whether to skip the macos build [default: false]. (`G_BUILD_MAC_SKIP`)"
desc ""
lane :build_all do |options|
if !options[:skip_ios].nil?
skip_ios = options[:skip_ios]
elsif !ENV["G_BUILD_IOS_SKIP"].nil?
skip_ios = true?(ENV["G_BUILD_IOS_SKIP"])
else
skip_ios = false
end
if !options[:skip_macos].nil?
skip_macos = options[:skip_macos]
elsif !ENV["G_BUILD_MAC_SKIP"].nil?
skip_macos = true?(ENV["G_BUILD_MAC_SKIP"])
else
skip_macos = false
end
integration_tests_setup
uitests_ios_setup
build_mac options unless skip_macos
build_ios options unless skip_ios
end
desc "Lane that (auto) genarates API documentation from inline comments."
lane :generate_documentation do |options|
list_errors
list_requirements
# create sbom into documentations
sh "cd .. && snyk sbom --file=Package.swift --format=cyclonedx1.6+json > docs/sbom.json; cd -"
output = sh "cd .. && swift package describe --type json | jq \".targets[]|select(.type == \\\"library\\\").name\" | grep -v Test | sed \"s/\\\"//g\" | sort"
schemes = output.split("\n").map { |e| e.strip }
sh "mkdir -p ../build/docs"
sh "mkdir -p ../docs/technical"
# docc build
sh "cd .. && xcrun xcodebuild -project eRp-App.xcodeproj -derivedDataPath build/docsData -scheme eRpFeatures -destination 'platform=iOS Simulator,name=iPhone 17' -parallelizeTargets docbuild | cd -"
paths = schemes.map { |scheme|
"../build/docsData/Build/Products/Debug-iphonesimulator/#{scheme}.doccarchive"
}.join(" ")
sh "rm -rf ../build/docs/AllSchemes.doccarchive"
sh "$(xcrun --find docc) merge #{paths} --synthesized-landing-page-name \"E-Rezept App iOS Technical Dokumentation\" --output-path ../build/docs/AllSchemes.doccarchive"
sh "$(xcrun --find docc) process-archive transform-for-static-hosting \"../build/docs/AllSchemes.doccarchive\" --hosting-base-path /E-Rezept-App-iOS/technical/ --output-path ../docs/technical"
# generate landing page
generate_docs_index_html
end
desc "Lane that runs the static code analyzer for the project."
desc "CI builds should run this lane on every commit and fail the build when"
desc "the error/warning threshold exceeds the set limit."
desc "Currently swiftlint is used as static analyzer"
desc ""
desc "###Example:"
desc "```\nfastlane static_code_analysis swiftlint_config:\".swiftlint.yml\" code_analysis_fail_build:true code_analysis_strict:true --env ios12_xcode10\n```"
desc "###Options"
desc " * **`swiftlint_config`**: The SwiftLint configfile [default: .swiftlint.yml]. (`G_SWIFTLINT_CONFIG`)"
desc " * **`code_analysis_fail_build`**: Whether errors/warnings should trigger build failures or not [default: true]. (`G_CODE_ANALYSIS_FAIL_BUILD`)"
desc " * **`code_analysis_strict`**: Lint mode strict [default: true]. (`G_CODE_ANALYSIS_STRICT`)"
desc ""
lane :static_code_analysis do |options|
if options[:swiftlint_config]
config = options[:swiftlint_config]
elsif ENV["G_SWIFTLINT_CONFIG"]
config = ENV["G_SWIFTLINT_CONFIG"]
else
config = ".swiftlint.yml"
end
if !options[:code_analysis_fail_build].nil?
fail_build = options[:code_analysis_fail_build]
elsif !ENV["G_CODE_ANALYSIS_FAIL_BUILD"].nil?
fail_build = true?(ENV["G_CODE_ANALYSIS_FAIL_BUILD"])
else
fail_build = true
end
if !options[:code_analysis_strict].nil?
strict = options[:code_analysis_strict]
elsif !ENV["G_CODE_ANALYSIS_STRICT"].nil?
strict = true?(ENV["G_CODE_ANALYSIS_STRICT"])
else
strict = true
end
swiftlint(
config_file: config,
mode: :lint,
ignore_exit_status: !fail_build,
quiet: true,
strict: strict
)
end
desc "Lane that sets up the SPM dependencies and xcodeproj."
desc "This lane calls `resolve_dependencies`, `generate_xcodeproj`"
desc ""
desc "###Example:"
desc "```\nfastlane setup xcode:/Applications/Xcode-10.app configuration:Release --env ios12_xcode10\n```"
desc "###Options"
desc " * **`xcode`**: The path to the Xcode.app to use for this project [default: uses system xcodebuild configuration]. (`G_XCODE`)"
desc ""
lane :setup do |options|
resolve_dependencies options
generate_xcodeproj options
pull_environment_variables options
end
desc "Lane that the ci build should invoke directly to do a complete build/test/analysis."
desc "This lane calls `setup`, `static_code_analysis`, "
desc "`build_all`, `generate_documentation`. See these sub-lanes for option parameters"
desc "and ENV configuration options."
desc ""
desc "###Example:"
desc "```\nfastlane cibuild --env ios12_xcode10\n```"
desc ""
lane :cibuild do |options|
desc "Build and test all platforms"
setup options
static_code_analysis options
build_all options
generate_documentation options
end
lane :list_errors do |options|
sh "mkdir -p ../docs/errors"
# Generate error documentation using our custom action
result = generate_error_documentation(
sources_dir: "./Sources",
output_dir: "./docs/errors"
)
UI.success("📊 Generated documentation for #{result[:total_enums]} error enums with #{result[:total_cases]} total cases")
# Generate SVG from DOT file using Graphviz
if File.exist?("../docs/errors/errors.dot")
sh "cd .. && dot -Tsvg -Kdot docs/errors/errors.dot > docs/errors/error_graph.svg"
UI.success("✅ Generated error graph SVG")
end
# Copy additional static files for the error documentation
sh "cd .. && cp doc/errors/error_graph.html docs/errors/error_graph.html" if File.exist?("../doc/errors/error_graph.html")
sh "cd .. && cp doc/errors/error_graph.css docs/errors/error_graph.css" if File.exist?("../doc/errors/error_graph.css")
sh "cd .. && cp Templates/ERB/style.css docs/errors/style.css" if File.exist?("../Templates/ERB/style.css")
# Report any missing expected error codes
if result[:missing_codes] && result[:missing_codes].any?
UI.important("⚠️ Missing expected error codes: #{result[:missing_codes].join(', ')}")
end
UI.success("🎉 Error documentation generation complete!")
UI.message("📁 Files generated in docs/errors/:")
UI.message(" • errors.json - Structured error data for search interface")
UI.message(" • errors.dot - Graphviz DOT format for visualization")
UI.message(" • error_graph.svg - Visual error relationship graph")
UI.message(" • search.html - Interactive search interface")
end
lane :list_requirements do |options|
template_dir = File.join(File.dirname(__FILE__), 'Templates', 'ERB')
output_dir = File.join(File.dirname(__FILE__), 'docs', 'requirements')
output_docs_dir = File.join(File.dirname(__FILE__), 'build', 'docs', 'generated')
templates = [
'requirements.csv.erb',
'requirements.md.erb',
'requirements.html.erb',
'requirements_filtered.html.erb'
].map { |file| File.join(template_dir, file) }
audit_generator(
audit_afos_json: './fastlane/audit_afos.json',
erb_templates: templates,
output_directory: output_dir,
source_file_globs: ["Sources/**/*.swift", "Tests/**/*.swift", "App/**/*.swift"],
requirement_notes_glob: "doc/manual/requirement-notes.md"
)
sh "cd .. && mkdir -p #{output_docs_dir}"
sh "cd .. && mv #{output_dir}/requirements.md #{output_docs_dir}"
sh "cd .. && cp Templates/ERB/style.css #{output_dir}"
sh "cd .. && cp Templates/ERB/audit_style.css #{output_dir}"
sh "cd .. && cp Templates/ERB/prism.css #{output_dir}"
sh "cd .. && cp Templates/ERB/prism.js #{output_dir}"
`which pandoc`
if $?.success?
UI.message("Generating html using `pandoc`...")
sh "cd .. && pandoc -s -f markdown -t html --toc --css Templates/ERB/style.css build/docs/generated/requirements.md > requirements.md.html"
else
UI.message("`pandoc` not found, skipping html generation. To install pandoc run `brew install pandoc`.")
end
end
desc "Refresh FOSS.html with data from Package.resolved"
desc ""
desc "###Hint:"
desc "Generate a GitHub access token (Access public repositories) and call"
desc "```\nGITHUB_API_TOKEN=token_goes_here bundle exec fastlane compile_foss\n```"
desc ""
lane :compile_foss do
dependencies_yaml = YAML.load_file("../dependencies.yml")
# Dependencies from /eRp-App.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
dependencies_package_resolved = dependencies_package_resolved()
exclude_identities_from_package_resolved = dependencies_yaml["exclude_identities_from_package_resolved"]
dependencies_package_resolved = dependencies_package_resolved.filter { |dependency|
not exclude_identities_from_package_resolved.include? dependency[:identity]
}
# Merge all dependency arrays before proceeding
dependencies = dependencies_package_resolved
# Load license texts from respective repo URIs
dependencies.each { |entry|
UI.message("Load license text for #{entry[:name]}")
license = ""
if entry[:license_uri] && !entry[:license_uri].empty?
begin
URI.open(entry[:license_uri]).read().each_line{|line| license += "#{line.strip}\n" }
license = license.gsub(/\R{2}/, 'PARAGRAPH_BREAK')
license = license.gsub(/\R{1}/, ' ')
license = license.gsub(/PARAGRAPH_BREAK/, "</p>\n\n<p>")
rescue => e
UI.error("Failed to load license from #{entry[:license_uri]}: #{e.message}")
end
else
UI.important("IMPORTANT: No license URI available for #{entry[:name]}")
end
entry[:license] = "<p>#{license}</p>"
if dependencies_yaml["purpose"]["specific"][entry[:name]]
entry[:purpose] = dependencies_yaml["purpose"]["specific"][entry[:name]]
else
entry[:purpose] = dependencies_yaml["purpose"]["generic"]
end
entry
}
erb_path = File.join(File.dirname(__FILE__), '..', 'Templates', 'ERB', 'FOSS.html.erb')
erb_out_path = erb_path.sub('.erb','').sub('/Templates/ERB','/Sources/eRpApp/Resources/en-GB.lproj')
erb = ERB.new(File.read(erb_path))
File.open(erb_out_path, 'w+') do |file|
file.write(erb.result(binding))
end
end
def dependencies_package_resolved
require 'open-uri'
require 'json'
file = File.read('../eRp-App.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved')
data_hash = JSON.parse(file)
ENV['GITHUB_API_TOKEN'] = prompt(text: "GITHUB_API_TOKEN not set, please specify") unless ENV['GITHUB_API_TOKEN']
dependencies = data_hash['pins'].map do |pin|
UI.message("#{pin}")
identity = pin['identity']
location = pin['location']
version = pin['state']['version']
revision = pin['state']['revision']
dependency = {}
dependency[:name] = identity # TODO: better use repo_name here, it's often prettier than identity
dependency[:identity] = identity
dependency[:url] = location
# API curls for the license URI
license_uri = curl_license_url_from_github(location) if location.include? "github.com"
dependency[:license_uri] = license_uri
dependency[:version] = version||revision
if location.include? "github.com"
most_recent_version = curl_most_recent_tag(location)
if most_recent_version && most_recent_version != dependency[:version]
UI.important("Version mismatch for package #{identity}, NEW: '#{most_recent_version}' OLD: '#{dependency[:version]}'")
end
end
dependency
end
dependencies
end
require 'net/http'
require 'uri'
def make_github_api_request(repo_url)
uri = URI.parse(repo_url)
# Follow redirects with a maximum of 5 redirects
max_redirects = 5
redirects = 0
loop do
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{ENV['GITHUB_API_TOKEN']}" if ENV['GITHUB_API_TOKEN']
response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) { |http|
http.request(req)
}
case response
when Net::HTTPRedirection
if redirects >= max_redirects
UI.error("Too many redirects (#{max_redirects}) for #{repo_url}")
return {}
end
location = response['location']
uri = URI.parse(location)
redirects += 1
UI.message("Following redirect to: #{location}")
when Net::HTTPSuccess
UI.error("Bad credentials or authorisation") if response.body.include? "Bad credentials"
begin
return JSON.parse(response.body)
rescue JSON::ParserError => e
UI.error("Failed to parse JSON response from #{repo_url}: #{e.message}")
return {}
end
else
UI.error("HTTP error: #{response.code} #{response.message}")
return {}
end
end
end
def reset_test_outputs
sh "find ../DerivedData -iname \"*.xcresult\" -prune -exec rm -rf {} \\;"
end
def curl_license_url_from_github(repo_url)
repo_url = repo_url.gsub(".git", "")
repo_owner, repo_name = repo_url.split("/").last(2)
repo_url = "https://api.github.com/repos/#{repo_owner}/#{repo_name}/license"
data_hash = make_github_api_request(repo_url)
data_hash['download_url'] || ""
end
def curl_most_recent_tag(repo_url)
# Function to validate semver format
def valid_semver?(version)
version.match?(/^v?\d+\.\d+\.\d+$/)
end
# Function to compare semantic versions
def compare_versions(v1, v2)
segments1 = v1.split('.').map(&:to_i)
segments2 = v2.split('.').map(&:to_i)
segments1 <=> segments2
end
repo_url = repo_url.gsub(".git", "")
repo_owner, repo_name = repo_url.split("/").last(2)
download_url = ""
repo_url = "https://api.github.com/repos/#{repo_owner}/#{repo_name}/releases"
puts("Parsing versions for #{repo_url}")
data_hash = make_github_api_request(repo_url)
# Check if the response is an error (contains a message field) or empty
if data_hash.is_a?(Hash) && (data_hash.has_key?('message') || data_hash.empty?)
UI.error("Failed to get releases for #{repo_url}: #{data_hash['message'] || 'Empty response'}")
return nil
end
# Ensure we have an array response
unless data_hash.is_a?(Array)
UI.error("Unexpected response format for #{repo_url}")
return nil
end
# Extract names and sort them as semantic versions
versions = data_hash.map { |item| item['tag_name'] }.compact
if versions.length == 0
puts("Repository contains no releases, trying tags instead")
repo_url = "https://api.github.com/repos/#{repo_owner}/#{repo_name}/tags"
data_hash = make_github_api_request(repo_url)
# Check if the response is an error or empty
if data_hash.is_a?(Hash) && (data_hash.has_key?('message') || data_hash.empty?)
UI.error("Failed to get tags for #{repo_url}: #{data_hash['message'] || 'Empty response'}")
return nil
end
# Ensure we have an array response
unless data_hash.is_a?(Array)
UI.error("Unexpected response format for #{repo_url}")
return nil
end
# Extract names and sort them as semantic versions
versions = data_hash.map { |item| item['name'] }.compact
end
semantic_versions = versions.select { |name| valid_semver?(name) }.map { |name| name.sub(/^v/, '') }
sorted_versions = semantic_versions.sort { |a, b| compare_versions(b, a) }
sorted_versions.first
end
lane :build_test_version do |options|
build_archive_with_debug_screen
sign_adhoc
if is_ci
firebase_app_distribution(
ipa_path: "./distribution/eRPApp_#{build_version}_adhoc.ipa",
release_notes: "branch #{ENV['GIT_BRANCH']} - #{ENV['BUILD_NUMBER']}",
service_credentials_file: ENV["FIREBASE_SERVICE_ACCOUNT"]
)
add_mr_note_if_possible
notify_teams_channel(channel_url: ENV["TEAMS_CHANNEL_URL_CI"], stream: "CI Build")
end
sh "cd .. && mkdir -p artifacts/cibuild/ && rm -rf artifacts/cibuild/* && mv distribution artifacts/cibuild/; cd - "
end
lane :build_konnektathon_ru do |options|
clear_derived_data(derived_data_path: ENV['GYM_DERIVED_DATA_PATH'])
match(type: "appstore")
sh "cd .. && /usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString \\\"$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' ./App/Sources/Resources/Info.plist)\\\"\" ./Sources/Konny/Resources/Info.plist; cd -"
sh "cp -vR ../Sources/Konny/Resources ../App/Sources"
gym(
skip_build_archive: false,
skip_package_ipa: true,
export_method: "app-store",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
xcargs: "GEMATIK_SOURCE_VERSION=\"#{git_version}\" GEMATIK_BUNDLE_VERSION=\"#{build_version}\" GEM_PRODUCT_BUNDLE_IDENTIFIER=\"de.gematik.konny\" GEM_PROVISIONING_PROFILE_SPECIFIER=\"match AppStore de.gematik.konny\" SWIFT_ACTIVE_COMPILATION_CONDITIONS=\"\\$(inherited) ENABLE_DEBUG_VIEW DEFAULT_ENVIRONMENT_RU_DEV\"",
output_directory: "./distribution"
)
gym(
skip_build_archive: true,
export_method: "app-store",
output_name: "eRPApp_#{build_version}_store.ipa",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
output_directory: "./distribution"
)
match(type: "adhoc")
gym(
skip_build_archive: true,
export_method: "ad-hoc",
output_name: "eRPApp_#{build_version}_adhoc.ipa",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
output_directory: "./distribution",
include_bitcode: false,
export_options: {
uploadBitcode: false,
uploadSymbols: true,
compileBitcode: false
}
)
app_store_connect_api_key(
issuer_id: "69a6de92-74a9-47e3-e053-5b8c7c11a4d1"
)
upload_to_testflight(
ipa: "./distribution/eRPApp_#{build_version}_store.ipa",
skip_submission: true,
apple_id: '1575045048',
dev_portal_team_id: "A9FL89PFFL",
skip_waiting_for_build_processing: true
)
if is_ci
notify_teams_channel(channel_url: ENV["TEAMS_CHANNEL_URL_RELEASE"], stream: "Konny Version")
end
end
lane :build_drezept_ru do |options|
clear_derived_data(derived_data_path: ENV['GYM_DERIVED_DATA_PATH'])
match(type: "appstore")
sh "cd .. && /usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString \\\"$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' ./App/Sources/Resources/Info.plist)\\\"\" ./Sources/DerivedApps/dRezept/Resources/Info.plist; cd -"
sh "cp -vR ../Sources/DerivedApps/dRezept/Resources ../App/Sources"
gym(
skip_build_archive: false,
skip_package_ipa: true,
export_method: "app-store",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
xcargs: "GEMATIK_SOURCE_VERSION=\"#{git_version}\" GEMATIK_BUNDLE_VERSION=\"#{build_version}\" GEM_PRODUCT_BUNDLE_IDENTIFIER=\"de.gematik.drezept\" GEM_PROVISIONING_PROFILE_SPECIFIER=\"match AppStore de.gematik.drezept\" SWIFT_ACTIVE_COMPILATION_CONDITIONS=\"\\$(inherited) ENABLE_DEBUG_VIEW TEST_ENVIRONMENT DEFAULT_ENVIRONMENT_RU\"",
output_directory: "./distribution"
)
gym(
skip_build_archive: true,
export_method: "app-store",
output_name: "eRPApp_#{build_version}_store.ipa",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
output_directory: "./distribution"
)
match(type: "adhoc")
gym(
skip_build_archive: true,
export_method: "ad-hoc",
output_name: "eRPApp_#{build_version}_adhoc.ipa",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
output_directory: "./distribution",
include_bitcode: false,
export_options: {
uploadBitcode: false,
uploadSymbols: true,
compileBitcode: false
}
)
app_store_connect_api_key(
issuer_id: "69a6de92-74a9-47e3-e053-5b8c7c11a4d1"
)
upload_to_testflight(
ipa: "./distribution/eRPApp_#{build_version}_store.ipa",
skip_submission: true,
apple_id: '1589232632',
dev_portal_team_id: "A9FL89PFFL",
skip_waiting_for_build_processing: true
)
if is_ci
firebase_app_distribution(
app: "1:20059247872:ios:f38ae6092c9e2269f1cfe5",
ipa_path: "./distribution/eRPApp_#{build_version}_adhoc.ipa",
release_notes: "D-Rezept Version #{ENV['GIT_BRANCH']} - #{ENV['BUILD_NUMBER']}",
service_credentials_file: ENV["FIREBASE_SERVICE_ACCOUNT"]
)
notify_teams_channel(channel_url: ENV["TEAMS_CHANNEL_URL_INT"], stream: "D-Rezept Version")
end
end
lane :sign_adhoc do |options|
match(type: "adhoc")
gym(
skip_build_archive: true,
export_method: "ad-hoc",
output_name: "eRPApp_#{build_version}_adhoc.ipa",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
output_directory: "./distribution",
include_bitcode: false,
export_options: {
uploadBitcode: false,
uploadSymbols: true,
compileBitcode: false
}
)
end
lane :sign_appstore do |options|
match(type: "appstore")
gym(
skip_build_archive: true,
export_method: "app-store",
output_name: "eRPApp_#{build_version}_store.ipa",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
output_directory: "./distribution"
)
end
lane :build_archive do |options|
clear_derived_data(derived_data_path: ENV['GYM_DERIVED_DATA_PATH'])
match(type: "appstore")
gym(
skip_build_archive: false,
skip_package_ipa: true,
export_method: "app-store",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
xcargs: "GEMATIK_SOURCE_VERSION=\"#{git_version}\" GEMATIK_BUNDLE_VERSION=\"#{build_version}\""
)
end
lane :build_tu_archive do |options|
clear_derived_data(derived_data_path: ENV['GYM_DERIVED_DATA_PATH'])
match(type: "appstore")
gym(
skip_build_archive: false,
skip_package_ipa: true,
export_method: "app-store",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
xcargs: "GEMATIK_SOURCE_VERSION=\"#{git_version}\" GEMATIK_BUNDLE_VERSION=\"#{build_version}\" SWIFT_ACTIVE_COMPILATION_CONDITIONS=\"\\$(inherited) DEFAULT_ENVIRONMENT_TU\""
)
end
lane :build_ru_archive do |options|
clear_derived_data(derived_data_path: ENV['GYM_DERIVED_DATA_PATH'])
match(type: "appstore")
gym(
skip_build_archive: false,
skip_package_ipa: true,
export_method: "app-store",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
xcargs: "GEMATIK_SOURCE_VERSION=\"#{git_version}\" GEMATIK_BUNDLE_VERSION=\"#{build_version}\" SWIFT_ACTIVE_COMPILATION_CONDITIONS=\"\\$(inherited) DEFAULT_ENVIRONMENT_RU\""
)
end
lane :build_simulator_archive do |options|
clear_derived_data(derived_data_path: ENV['GYM_DERIVED_DATA_PATH'])
gym(
skip_codesigning: false,
skip_build_archive: false,
skip_package_ipa: true,
archive_path: "./distribution/eRPApp_simulator_#{build_version}.xcarchive",
xcargs: "GEMATIK_SOURCE_VERSION=\"#{git_version}\" GEMATIK_BUNDLE_VERSION=\"#{build_version}\" SWIFT_ACTIVE_COMPILATION_CONDITIONS=\"\\$(inherited) ENABLE_DEBUG_VIEW TEST_ENVIRONMENT\"",
destination: "generic/platform=iOS Simulator"
)
end
lane :build_archive_with_debug_screen do |options|
clear_derived_data(derived_data_path: ENV['GYM_DERIVED_DATA_PATH'])
# On CI if there is no match password available return with error
if is_ci and (ENV["MATCH_PASSWORD"].nil? or ENV["MATCH_PASSWORD"].empty?)
UI.error("No MATCH_PASSWORD available, cannot sign the app.")
return
end
match(type: "appstore")
gym(
skip_build_archive: false,
skip_package_ipa: true,
export_method: "app-store",
archive_path: "./distribution/eRPApp_#{build_version}.xcarchive",
xcargs: "GEMATIK_SOURCE_VERSION=\"#{git_version}\" GEMATIK_BUNDLE_VERSION=\"#{build_version}\" SWIFT_ACTIVE_COMPILATION_CONDITIONS=\"\\$(inherited) ENABLE_DEBUG_VIEW TEST_ENVIRONMENT\""
)
end
before_all do |lane, options|
load_keychain
GEMATIK_INTERNAL_ENVIRONMENT = File.exist? File.expand_path("../Gemfile.internal.lock")
end
after_all do |lane, options|
remove_keychain
end
error do |lane, exception, options|
remove_keychain
end
def load_keychain
remove_keychain
create_keychain(
name: "gematik",
password: "gematikpassword",
unlock: true,
timeout: 0
)
end
def remove_keychain
if File.exist? File.expand_path("~/Library/Keychains/gematik-db")
delete_keychain(name: "gematik")
end
end
def git_version()
short_hash = last_git_commit[:abbreviated_commit_hash]
dirty = sh("git diff --quiet || echo '-dirty'").strip!
"#{short_hash}#{dirty}"
end
def build_version()
ENV['BUILD_NUMBER'] || 'LOCAL_BUILD'
end
def jenkins_build_url()
ENV['BUILD_URL'] || 'NO_URL_AVAILABLE'
end
def randomWord(length)
return ('a'..'z').to_a.shuffle[0,length].join
end
def isDryRun(options)
if options[:dry_run]
dry_run = true
elsif !ENV['G_PUBLISH_DRY_RUN'].nil?
dry_run = true?(ENV['G_PUBLISH_DRY_RUN'])
else
dry_run = false
end
return dry_run
end
lane :update_changelog do |option|
from = option[:from]
new_version = option[:version]
new_version = current_version_number() unless new_version
old_version = sh("git tag | grep -E \"^[1-9]\\d*\.(?:0|[1-9]\\d*)\.(?:0|[1-9]\\d*)$\" | sort -Vr | head -n 1").strip! unless old_version
UI.message("Updating changelog from version '#{old_version}' to '#{new_version}'")
gitlab_login()
release_notes = sh("cd .. && glab changelog generate --from #{from} --version #{new_version}")
release_notes = release_notes.gsub(/^\#\# ([0-9\.]*) \(.*\)/, '# Release \1')
filename = "../ReleaseNotes.md"
lines = File.read(filename).lines
lines.unshift("\n")
lines.unshift(release_notes)
File.open(filename, "w") { |file| file.write(lines.join) }
UI.message("Release Notes:\n\n#{release_notes}")
end
lane :prepare_release do |option|
old_version = current_version_number()
if prompt(text: "bump minor version number?", boolean: true, ci_input: "false")
bump_minor_version
elsif prompt(text: "bump maintainance (patch) version number? (\"no\" means no bump at all)", boolean: true, ci_input: "false")
bump_patch_version
end
version = current_version_number()
# version changed -> generate changelog
if (old_version != version)
existing_tags = sh("git tag | grep -E \"^[1-9]\\d*\.(?:0|[1-9]\\d*)\.(?:0|[1-9]\\d*)$\" | sort -Vr").strip!
raise "Missing tag '#{old_version}'. Did you forget to tag the last version?" unless existing_tags.split("\n").include?(old_version)
update_changelog(
from: old_version,
version: version
)
end
compile_foss
pull_erp_shared_data