Source file ShellPrepareCi.ml
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
type ci = GitHub
let ci = ref GitHub
let majmin = ref None
let registry =
SecPackageRegistry.create
~show:(fun _distcore item -> MlFront_Core.FilePath.to_string item)
()
let quick_error msg =
let lines = String.split_on_char '\n' msg in
Format.eprintf "@[<v 1>FATAL: The prepare failed.@;%a@]@."
Format.(pp_print_list ~pp_sep:pp_print_cut pp_print_string)
lines;
exit 1
let left_pad s =
let lines = String.split_on_char '\n' s in
String.concat "\n" (List.map (fun line -> " " ^ line) lines)
let anon_fun s =
match !majmin with
| None -> majmin := Some s
| Some _ -> raise (Arg.Bad "Too many arguments")
let speclist ~usage_msg =
[
( "--ci",
Arg.String
(function
| "github" -> ci := GitHub
| _ -> raise (Arg.Bad "Invalid CI provider")),
"" );
( "-help",
Arg.Unit
(fun () ->
print_endline usage_msg;
exit 0),
"" );
( "--help",
Arg.Unit
(fun () ->
print_endline usage_msg;
exit 0),
"" );
]
let zerorangeplus =
MlFront_Thunk.ThunkLexers.Ranges.Raw_range Fmlib_parse.Position.(start, start)
(** The GitHub Secrets name for the public build key or secret build key.
Works with:
- GitHub. "HTTP 422: Secret names can only contain alphanumeric characters
([a-z], [A-Z], [0-9]) or underscores (_). Spaces are not allowed. Must
start with a letter ([a-z], [A-Z]) or underscores (_)." *)
let distributionkey_secretname ~majmin = function
| `PublicKey ->
Printf.sprintf "distribute_%Ld_%Ld_pubkey" (fst majmin) (snd majmin)
| `SecretKey ->
Printf.sprintf "distribute_%Ld_%Ld_seckey" (fst majmin) (snd majmin)
let read_dot_terminated_text () =
let rec read_lines acc =
try
match input_line stdin with
| "." -> List.rev acc
| line -> read_lines (line :: acc)
with End_of_file -> List.rev acc
in
let lines = read_lines [] in
if lines = [] then None else Some (String.concat "\n" lines)
let rec process_prepare_ci_version_command ~usage_msg ~random_seed module_or
args =
let current = ref 1 in
(try
Arg.parse_argv ~current
(Array.of_list ("mlfront-shell" :: "prepare-version" :: args))
(speclist ~usage_msg) anon_fun usage_msg
with
| Arg.Bad msg ->
prerr_endline msg;
exit 1
| Arg.Help msg ->
prerr_endline msg;
exit 0);
let major, minor =
match !majmin with
| None ->
prerr_endline "Missing MAJOR.MINOR version argument";
exit 1
| Some majmin ->
match MlFront_Thunk.ThunkDist.InternalUse.parse_major_minor majmin with
| Ok v -> v
| Error m ->
prerr_endline m;
exit 1
in
let majmin = (major, minor) in
let rng = SecCore.get_rng ~random_seed () in
let pkg_opt, registry = SecDist.scan_dist_dir module_or in
let dist_core =
match pkg_opt with
| None -> SecPackageRegistry.create_dist_core ()
| Some pkg ->
match SecPackageRegistry.characterize ~majmin pkg registry with
| `Exists (_dist_core, dist_file) ->
quick_error
(Printf.sprintf "The version %Ld.%Ld already exists in `%s`" major
minor
(MlFront_Core.FilePath.to_string dist_file))
| `Superseded latest ->
quick_error
(Printf.sprintf
"Version %Ld.%Ld has been superseded by the latest released \
version %s"
major minor
(MlFront_Thunk.ThunkSemver64.to_string latest))
| `Continued dist_core -> dist_core
| `Error msg -> quick_error msg
| `NoMatchingContinuation ->
let next_versions =
SecPackageRegistry.get_next_versions_desc registry pkg
|> List.map (fun (major, minor) ->
Printf.sprintf "%Ld.%Ld" major minor)
in
quick_error
(Printf.sprintf
"There are no distribution files with %Ld.%Ld as a continuation. \
The versions that you can prepare are: %s"
major minor
(String.concat ", " next_versions))
in
let idrange, library_id, version = fill_id ~majmin dist_core.id in
let dist_core : MlFront_Thunk.ThunkDist.DistCore.t =
let producer, `SecretKey seckey =
fill_producer ~library_id ~majmin ~rng dist_core.producer
in
let license = fill_license dist_core.license in
let continuations =
fill_continuations ~library_id ~majmin ~seckey ~rng
dist_core.continuations
in
{
id = Some (idrange, library_id, version);
producer;
license;
continuations;
}
in
MlFront_Thunk.ThunkDist.pp_core Format.std_formatter dist_core;
Format.pp_print_flush Format.std_formatter ();
prerr_newline ();
flush stdout;
let dist_file_fp =
MlFront_Core.FilePath.append_exn
(Printf.sprintf "%s.dist.json"
(MlFront_Thunk.ThunkSemver64.to_string version))
SecDist.dist_dir_fp
in
MlFront_Thunk_IoDisk.ThunkIoDisk.make_directory_recursively
~return:(function `Error msg -> quick_error msg | `Created -> ())
SecDist.dist_dir_fp;
let dist_json =
Format.asprintf "%a" MlFront_Thunk.ThunkDist.pp_core dist_core
in
ShellCore.save_file ~contents:dist_json dist_file_fp;
match !ci with
| GitHub -> do_github ~library_id ~majmin dist_core
and do_github ~library_id ~majmin dist_core =
let workflow_dir = MlFront_Core.FilePath.of_string_exn ".github/workflows" in
let workflow_file =
MlFront_Core.FilePath.append_exn
(Printf.sprintf "distribute-%Ld.%Ld.yml" (fst majmin) (snd majmin))
workflow_dir
in
let producer_github_slsa_v1_l2, producer_github_slsa_v1_l3 =
match (dist_core : MlFront_Thunk.ThunkDist.DistCore.t) with
| {
id = _;
producer =
{
producer_openbsd_signify = _;
producer_github_slsa_v1_l2;
producer_github_slsa_v1_l3;
};
license = _;
continuations = _;
} ->
(producer_github_slsa_v1_l2, producer_github_slsa_v1_l3)
in
let caller_github_repository =
match producer_github_slsa_v1_l3 with
| Some
{
github_slsa_v1_l3_caller = _range, `Repository repo;
github_slsa_v1_l3_signer = _;
} ->
Some repo
| Some
{
github_slsa_v1_l3_caller = _, `Organization _;
github_slsa_v1_l3_signer = _;
}
| None ->
match producer_github_slsa_v1_l2 with
| Some { github_slsa_v1_l2_repository = _range, repo } -> Some repo
| None -> None
in
let gh_secret_instructions =
match caller_github_repository with
| Some repo ->
let keypairname' = keypairname ~library_id ~majmin in
Printf.sprintf
{|
You can set these secrets now with the GitHub CLI!
1. Download GitHub CLI from https://cli.github.com/.
2. Create the dk-distribution environment with:
gh api --method PUT -H "Accept: application/vnd.github+json" repos/%s/environments/dk-distribution
3. Run the following, then copy and paste the text
("untrusted comment: ...|RW...") of the PUBLIC key
`%s`:
gh secret set --repo %s --env dk-distribution %s
4. Run the following, then copy and paste the text
("untrusted comment: ...|RW...") of the SECRET key
`%s`:
gh secret set --repo %s --env dk-distribution %s
|}
repo keypairname' repo
(distributionkey_secretname ~majmin `PublicKey)
keypairname' repo
(distributionkey_secretname ~majmin `SecretKey)
| None -> ""
in
if not (Sys.file_exists (MlFront_Core.FilePath.show workflow_file)) then begin
let workflow_contents =
let library_name = MlFront_Core.LibraryId.full_name library_id in
let majmin_dot = Printf.sprintf "%Ld.%Ld" (fst majmin) (snd majmin) in
let majmin_under = Printf.sprintf "%Ld_%Ld" (fst majmin) (snd majmin) in
String.trim
@@ Printf.sprintf
{|
name: %s@%s.x
on:
push:
tags:
- '%s.*' # build if tag is pushed
workflow_dispatch: # allow manual triggering from GitHub Actions page
jobs:
distribute:
runs-on: ubuntu-latest # or windows-latest or macos-latest
if: github.ref_type == 'tag' && startsWith(github.ref_name, '%s.')
permissions:
id-token: write
contents: write # for action-gh-release
attestations: write
# The secrets created by `dk0/mlfront-shell -- prepare-version --ci github VERSION`
# are tied to this `dk-distribution` environment only.
environment: dk-distribution
steps:
- name: Harden Runner # Optional but recommended
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
with: { egress-policy: audit }
- name: Checkout project
uses: actions/checkout@v5
- name: Distribute Modules
uses: diskuv/dk-distribute@v1
with:
id: %s@${{ github.ref_name }}
# faster but less safe? use-cache: true
pubkey: ${{ secrets.distribute_%s_pubkey }}
seckey: ${{ secrets.distribute_%s_seckey }}
# CHANGE THE `slots` FIELD!
# vvvvvvvv
slots: |
Debug.Agnostic
Release.Agnostic
# CHANGE THE `forms` FIELD!
# vvvvvvvv
forms: |
%s.Change.Me.Including.Version@1.2.3
%s.This.Should.Be.One.Of.Your.Forms@4.5.6
- name: Generate artifact attestation
id: attest
uses: actions/attest-build-provenance@v3
with: { subject-path: dk-dist/* }
- name: Release ${{ github.workflow }}
uses: softprops/action-gh-release@f38efdea4c5ffe13e9424b0aa2833bee28f1e34c # v2. Oct. 6, 2025
with: { files: dk-dist/* }
|}
library_name majmin_dot majmin_dot majmin_dot library_name
majmin_under majmin_under library_name library_name
in
MlFront_Thunk_IoDisk.ThunkIoDisk.make_directory_recursively
~return:(function `Error msg -> quick_error msg | `Created -> ())
workflow_dir;
ShellCore.save_file ~contents:workflow_contents workflow_file
end;
let keypairname' = keypairname ~library_id ~majmin in
Printf.eprintf
{|
------------
Your workflow `%s`
requires two GitHub secrets set in a `dk-distribution` environment
to sign the distributions:
- `%s` - the public key for `%s`
- `%s` - the secret key for `%s`
%s
Full docs at https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets#creating-secrets-for-an-environment.
%!|}
(MlFront_Core.FilePath.to_string workflow_file)
(distributionkey_secretname ~majmin `PublicKey)
keypairname'
(distributionkey_secretname ~majmin `SecretKey)
keypairname' gh_secret_instructions
and fill_id ~majmin :
(MlFront_Thunk.ThunkLexers.Ranges.range_plus
* MlFront_Core.LibraryId.t
* MlFront_Thunk.ThunkSemver64.t)
option ->
MlFront_Thunk.ThunkLexers.Ranges.range_plus
* MlFront_Core.LibraryId.t
* MlFront_Thunk.ThunkSemver64.t = function
| Some (range, library_id, id) -> (range, library_id, id)
| None -> (
let rec ask () =
Printf.printf
{|
-----------------
Define Library Id
-----------------
The library id is the hierarchical base of all the modules that your
distributions export. It is in the three-part form `VendorQualifier_Unit`
like `FooBar_Baz` or `FooBar_FizzBizz`.
To share your modules with others and avoid naming conflicts, your library
id must be registered and have a distribution key (we'll generate one for
you later).
Good "Vendors" and "Qualifiers" relate to your domain or real name.
Reserved "Vendors" include:
`Commons`, `Std`, `Dk`, `Ml`, `Our`, `Thunk`, `Zz`
A good "Unit" is either `Std`, or is related to your product or project.
Enter library id (leave blank to quit): %!|};
flush stdout;
try
match String.trim (input_line stdin) with
| "" ->
prerr_endline "exited";
exit 1
| answer -> (
print_endline answer;
match MlFront_Core.LibraryId.parse answer with
| Some id -> id
| None ->
print_endline
"The library id must be in the form VendorQualifier_Unit";
ask ())
with End_of_file ->
prerr_endline "exited";
exit 1
in
let library_id = ask () in
let major = fst majmin in
let minor = snd majmin in
match MlFront_Thunk.ThunkSemver64.from_parts major minor 0L [] [] with
| None ->
Printf.eprintf "unexpected unparseable version %Ld.%Ld\n%!" major
minor;
exit 1
| Some version -> (zerorangeplus, library_id, version))
and fill_producer ~library_id ~majmin ~rng :
MlFront_Thunk.ThunkDist.DistCore.producer ->
MlFront_Thunk.ThunkDist.DistCore.producer * [ `SecretKey of string ] =
function
| {
producer_openbsd_signify = None;
producer_github_slsa_v1_l2 = _;
producer_github_slsa_v1_l3 = _;
} ->
ask_producer ~what:"current version" ~library_id ~majmin ~rng ()
| {
producer_openbsd_signify = Some { openbsd_signify_public_key };
producer_github_slsa_v1_l2 = _;
producer_github_slsa_v1_l3 = _;
} as producer ->
let rec ask () =
Printf.printf
{|
To sign the next versions for auth with public key:
%s
you must enter the secret key for `%s-%Ld.%Ld`, followed by a dot `.`
on a line by itself.
Please enter the secret key (`quit` to exit): %!|}
(left_pad (String.trim (snd openbsd_signify_public_key)))
(MlFront_Core.LibraryId.full_name library_id)
(fst majmin) (snd majmin);
match read_dot_terminated_text () with
| None ->
Printf.eprintf "quit\n%!";
exit 1
| Some answer -> (
Printf.eprintf "received secret key\n%!";
Assumptions.build_keys_have_no_pipes_and_store_pipe_separated ();
let answer = String.map (function '|' -> '\n' | c -> c) answer in
let seckey = String.trim answer ^ "\n" in
let probe_message =
Printf.sprintf "%Ld %Ld" (Random.bits64 ()) (Random.bits64 ())
in
match
let probe_signature =
MlFront_Signify.Signify.sign_message_exn ~seckey
~message:probe_message ()
in
MlFront_Signify.Signify.verify_message
~pubkey:(snd openbsd_signify_public_key)
~message:probe_message ~signature_:probe_signature ()
with
| Error (`Msg msg) ->
Printf.eprintf "secret key error: %s\n\n------\n%!" msg;
ask ()
| Ok _ -> `SecretKey seckey
| exception Invalid_argument msg ->
Printf.eprintf "secret key error: %s\n\n------\n%!" msg;
ask ())
in
let packed_seckey = ask () in
(producer, packed_seckey)
and fill_license :
MlFront_Thunk.ThunkDist.DistCore.license ->
MlFront_Thunk.ThunkDist.DistCore.license = function
| { spdx = None; plaintext = None; markdown = None } -> ask_license ()
| license -> license
and fill_continuations ~library_id ~majmin ~seckey ~rng
(kont : MlFront_Thunk.ThunkDist.DistCore.continuations) :
MlFront_Thunk.ThunkDist.DistCore.continuations =
match majmin with
| maj, min ->
let kont =
fill_continuations_version ~what:"next minor version bump" ~library_id
~majmin:(maj, Int64.succ min)
~rng kont
in
let next_even n =
if Int64.rem n 2L = 0L then Int64.(succ (succ n)) else Int64.succ n
in
let kont =
fill_continuations_version ~what:"next even minor version bump"
~library_id
~majmin:(maj, next_even min)
~rng kont
in
let kont =
fill_continuations_version ~what:"next major version bump" ~library_id
~majmin:(Int64.succ maj, 0L)
~rng kont
in
let signature_ =
let canonical_continuations_to_sign_id =
MlFront_Thunk.ThunkDist.canonical_continuations_to_sign_id
kont.continuations_to_sign
in
MlFront_Signify.Signify.sign_message_exn ~seckey
~message:canonical_continuations_to_sign_id ()
in
let kont =
{
kont with
continuations_attestation =
Some
{
continuations_attestation_openbsd_signify =
Some
{
openbsd_signify_signature =
Some (zerorangeplus, signature_);
};
};
}
in
let kont =
{
kont with
continuations_to_sign = List.rev kont.continuations_to_sign;
}
in
kont
and fill_continuations_version ~what ~library_id ~majmin ~rng :
MlFront_Thunk.ThunkDist.DistCore.continuations ->
MlFront_Thunk.ThunkDist.DistCore.continuations = function
| { continuations_attestation = _; continuations_to_sign } as continuations
when List.exists
(fun ({ majmin = _range, major, minor; _ } :
MlFront_Thunk.ThunkDist.DistCore.continuation_to_sign) ->
Int64.equal major (fst majmin) && Int64.equal minor (snd majmin))
continuations_to_sign ->
continuations
| { continuations_attestation; continuations_to_sign } ->
let producer, _seckey =
producer_of_openbsd_signify ~what ~library_id ~majmin ~rng ()
in
{
continuations_attestation;
continuations_to_sign =
{ majmin = (zerorangeplus, fst majmin, snd majmin); producer }
:: continuations_to_sign;
}
and keypairname ~library_id ~majmin =
Printf.sprintf "%s-%Ld.%Ld"
(MlFront_Core.LibraryId.full_name library_id)
(fst majmin) (snd majmin)
and pipe_separate_secret s =
let s = MlFront_Thunk.ThunkLexers.Characters.dos2unix s in
if String.contains s '|' then failwith "The secret contains a pipe"
else String.map (function '\n' -> '|' | c -> c) (String.trim s)
and create_openbsd_signify_key_pair ~what ~library_id ~majmin ~rng () :
MlFront_Thunk.ThunkDist.DistCore.openbsd_signify_producer
* [ `SecretKey of string ] =
let keypairname' = keypairname ~library_id ~majmin in
let `PublicKey pubkey, (`SecretKey seckey as packed_seckey) =
let = keypairname' in
SecCore.generate_build_keypair ~comment ~rng ()
in
let majmin_s = Printf.sprintf "%Ld.%Ld" (fst majmin) (snd majmin) in
let rec ask () =
let title =
let title = Printf.sprintf "Key Pair for %s %s" what majmin_s in
let title_len = String.length title in
Printf.sprintf "%s\n%s\n%s"
(String.make title_len '-')
title
(String.make title_len '-')
in
Printf.printf
{|
%s
STORE the following key pair safely (ex. secure password manager) -or-
PRINT it and store it in two or more safe places.
-- name of keypair --
%s
-- public key %s --
%s
-- secret key %s --
%s
Did you securely store the keypair above?
Y. Yes, I have saved the keypair
Q. Quit
Enter Y or Q: %!|}
title keypairname' majmin_s
(Assumptions.build_keys_have_no_pipes_and_store_pipe_separated ();
pipe_separate_secret pubkey)
majmin_s
(Assumptions.build_keys_have_no_pipes_and_store_pipe_separated ();
pipe_separate_secret seckey);
try
match String.trim (input_line stdin) with
| answer when String.equal "Y" answer || String.equal "y" answer ->
print_endline answer;
( MlFront_Thunk.ThunkDist.DistCore.
{ openbsd_signify_public_key = (zerorangeplus, pubkey) },
packed_seckey )
| answer when String.equal "Q" answer || String.equal "q" answer ->
print_endline answer;
prerr_endline "exited";
exit 1
| "" ->
prerr_endline "exited";
exit 1
| _ -> ask ()
with End_of_file ->
prerr_endline "exited";
exit 1
in
ask ()
and producer_of_openbsd_signify ~what ~library_id ~majmin ~rng () =
let producer_openbsd_signify, seckey =
create_openbsd_signify_key_pair ~what ~library_id ~majmin ~rng ()
in
( MlFront_Thunk.ThunkDist.DistCore.
{
producer_openbsd_signify = Some producer_openbsd_signify;
producer_github_slsa_v1_l2 = None;
producer_github_slsa_v1_l3 = None;
},
seckey )
and ask_producer ~what ~library_id ~majmin ~rng () :
MlFront_Thunk.ThunkDist.DistCore.producer * [ `SecretKey of string ] =
let p, seckey =
producer_of_openbsd_signify ~what ~library_id ~majmin ~rng ()
in
let producer = ref p in
let rec ask () =
print_string
{|
----------------------------------------------
CI Identity Information for You (the Producer)
----------------------------------------------
1. (simple; most common) Enter GitHub SLSA v1 Level 2 details.
https://docs.github.com/en/actions/how-tos/secure-your-work/use-artifact-attestations/use-artifact-attestations#generating-artifact-attestations-for-your-builds
Details to attest (prove) that your builds have no tampering of values
after GitHub Actions finishes.
2. (most secure) Enter GitHub SLSA v1 Level 3 details.
https://docs.github.com/en/actions/how-tos/secure-your-work/use-artifact-attestations/increase-security-rating
Details to attest (prove) that there will be no tampering of values
during your builds by using a known, vetted GitHub Actions script.
C. Continue without CI identity
Q. Quit
Enter 1, 2, C or Q: |};
flush stdout;
try
match String.trim (input_line stdin) with
| answer when String.equal "1" answer -> begin
print_endline answer;
match ask_github_slsa_v1_l2 () with
| None -> ask ()
| Some github_repository ->
MlFront_Thunk.ThunkDist.DistCore.
{
!producer with
producer_github_slsa_v1_l2 =
Some
{
github_slsa_v1_l2_repository =
(zerorangeplus, github_repository);
};
}
end
| answer when String.equal "2" answer -> begin
print_endline answer;
match ask_github_slsa_v1_l3 () with
| None -> ask ()
| Some (org, github_signer_workflow) ->
MlFront_Thunk.ThunkDist.DistCore.
{
!producer with
producer_github_slsa_v1_l3 =
Some
{
github_slsa_v1_l3_caller = (zerorangeplus, org);
github_slsa_v1_l3_signer =
(zerorangeplus, github_signer_workflow);
};
}
end
| answer when String.equal "C" answer || String.equal "c" answer ->
!producer
| answer when String.equal "Q" answer || String.equal "q" answer ->
print_endline answer;
prerr_endline "exited";
exit 1
| "" ->
prerr_endline "exited";
exit 1
| _ -> ask ()
with End_of_file ->
prerr_endline "exited";
exit 1
in
let producer = ask () in
(producer, seckey)
and ask_github_slsa_v1_l2 () =
let ask () =
print_newline ();
print_string "Enter GitHub repository (ex. \"owner/repo\"): ";
flush stdout;
try
match String.trim (input_line stdin) with
| "" -> None
| answer ->
print_endline answer;
Some answer
with End_of_file -> None
in
ask ()
and ask_organization_or_repo () :
[ `Organization of string | `Repository of string ] option =
let ask () =
print_newline ();
print_string
"Enter GitHub organization (ex. \"owner\") or repository (ex. \
\"owner/repo\" or \"host/owner/repo\"): ";
flush stdout;
try
match String.trim (input_line stdin) with
| "" -> None
| answer ->
let org_or_repo = String.trim answer in
if String.contains org_or_repo '/' then Some (`Repository org_or_repo)
else Some (`Organization org_or_repo)
with End_of_file -> None
in
ask ()
and ask_signer_repo_or_workflow () :
[ `Repository of string | `Workflow of string ] option =
let ask () =
print_newline ();
print_string
"Enter GitHub signer repository (ex. \
\"REUSABLE_ORGANIZATION_NAME/REUSABLE_REPOSITORY_NAME\") or GitHub \
signer workflow (ex. \
\"REUSABLE_ORGANIZATION_NAME/REUSABLE_REPOSITORY_NAME/.github/workflows/reusable.yml\"): ";
flush stdout;
try
match String.trim (input_line stdin) with
| "" -> None
| answer ->
let repo_or_workflow = String.trim answer in
if
String.ends_with ~suffix:".yml" repo_or_workflow
|| String.ends_with ~suffix:".yaml" repo_or_workflow
then Some (`Workflow repo_or_workflow)
else Some (`Repository repo_or_workflow)
with End_of_file -> None
in
ask ()
and ask_github_slsa_v1_l3 () :
([ `Organization of string | `Repository of string ]
* [ `Repository of string | `Workflow of string ])
option =
let ask () =
match ask_organization_or_repo () with
| None -> None
| Some org ->
match ask_signer_repo_or_workflow () with
| None -> None
| Some github_signer_workflow -> Some (org, github_signer_workflow)
in
ask ()
and ask_license () : MlFront_Thunk.ThunkDist.DistCore.license =
let rec ask () =
print_string
{|
--------------------------------
Define Your Distribution License
--------------------------------
1. Enter SPDX license (ex. "Apache-2.0"). Strongly permissive licenses
like BlueOak-1.0.0, BSD-2-Clause-Patent and Apache-2.0 will not
prompt your users to accept the license.
2. Enter plain license text
3. Enter license text in Markdown format
Q. Quit
Enter 1, 2, 3 or Q: |};
flush stdout;
try
match String.trim (input_line stdin) with
| answer when String.equal "1" answer -> begin
print_endline answer;
match ask_spdx_license () with
| None -> ask ()
| Some spdx ->
{
MlFront_Thunk.ThunkDist.DistCore.spdx =
Some (zerorangeplus, spdx);
plaintext = None;
markdown = None;
}
end
| answer when String.equal "2" answer -> begin
print_endline answer;
match ask_plain_license () with
| None -> ask ()
| Some plaintext ->
{
MlFront_Thunk.ThunkDist.DistCore.spdx = None;
plaintext = Some (zerorangeplus, plaintext);
markdown = None;
}
end
| answer when String.equal "3" answer -> begin
print_endline answer;
match ask_markdown_license () with
| None -> ask ()
| Some markdown ->
{
MlFront_Thunk.ThunkDist.DistCore.spdx = None;
plaintext = None;
markdown = Some (zerorangeplus, markdown);
}
end
| answer when String.equal "Q" answer || String.equal "q" answer ->
print_endline answer;
prerr_endline "exited";
exit 1
| "" ->
prerr_endline "exited";
exit 1
| _ -> ask ()
with End_of_file ->
prerr_endline "exited";
exit 1
in
ask ()
and ask_spdx_license () =
let ask () =
print_string
"Enter SPDX license identifier (ex. \"Apache-2.0\"; \"q\" to quit): ";
flush stdout;
try
match String.trim (input_line stdin) with
| "" -> None
| ("Q" | "q") as quit ->
print_endline quit;
prerr_endline "exited";
exit 1
| answer ->
print_endline answer;
Some answer
with End_of_file -> None
in
ask ()
and ask_plain_license () =
let ask () =
print_endline
"Enter plain license text. End with a single dot (.) on a line by itself:";
read_dot_terminated_text ()
in
ask ()
and ask_markdown_license () =
let ask () =
print_endline
"Enter license text in Markdown format. End with a single dot (.) on a \
line by itself:";
read_dot_terminated_text ()
in
ask ()