1
+ #!/usr/bin/env wolframscript
2
+
3
+ BeginPackage[ "Wolfram`ChatbookScripts`" ];
4
+
5
+ If[ ! TrueQ @ $loadedDefinitions, Get @ FileNameJoin @ { DirectoryName @ $InputFileName, "Common.wl" } ];
6
+
7
+ Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];
8
+
9
+ (* ::**************************************************************************************************************:: *)
10
+ (* ::Section::Closed:: *)
11
+ (*Definitions*)
12
+
13
+ (* ::**************************************************************************************************************:: *)
14
+ (* ::Subsection::Closed:: *)
15
+ (*incrementPacletVersion*)
16
+ (* :!CodeAnalysis::BeginBlock:: *)
17
+ (* :!CodeAnalysis::Disable::SuspiciousSessionSymbol:: *)
18
+ (* :!CodeAnalysis::Disable::LeakedVariable:: *)
19
+ incrementPacletVersion[ dir_ ] := Enclose[
20
+ Catch @ Module[
21
+ { cs, file, string, version, newVersion, new },
22
+
23
+ cs = ConfirmBy[ #1, StringQ, #2 ] &;
24
+ file = cs[ FileNameJoin @ { dir, "PacletInfo.wl" }, "PacletInfo" ];
25
+ string = cs[ ReadString @ file, "ReadString" ];
26
+ version = cs[ PacletObject[ Flatten @ File @ dir ][ "Version" ], "Version" ];
27
+
28
+ If[ StringEndsQ[ version, "." ~~ "0".. ~~ EndOfString ],
29
+ Print[ "Skipping paclet version update: ", version ];
30
+ Throw @ version
31
+ ];
32
+
33
+ newVersion = cs[
34
+ StringReplace[
35
+ version,
36
+ "." ~~ v: DigitCharacter.. ~~ EndOfString :> "." <> ToString[ ToExpression @ v + 1 ]
37
+ ],
38
+ "NewVersion"
39
+ ];
40
+
41
+ ConfirmAssert[ PacletNewerQ[ newVersion, version ], "PacletNewerQ" ];
42
+
43
+ new = cs[
44
+ StringReplace[
45
+ string,
46
+ pre: ("\"Version\"" ~~ $$ws ~~ "->" ~~ $$ws) ~~ "\"" ~~ version ~~ "\"" :>
47
+ pre <> "\"" <> newVersion <> "\""
48
+ ],
49
+ "UpdatedPacletInfo"
50
+ ];
51
+
52
+ Print[ "Incrementing version: ", version, " -> ", newVersion ];
53
+ Confirm[ WithCleanup[ BinaryWrite[ file, new ], Close @ file ], "WritePacletInfo" ];
54
+
55
+ ConfirmMatch[
56
+ PacletObject[ Flatten @ File @ dir ][ "Version" ],
57
+ newVersion,
58
+ "PacletObject"
59
+ ]
60
+ ],
61
+ Function[
62
+ Print[ "::error::Failed to increment paclet version." ];
63
+ Print[ " ", ToString[ #, InputForm ] ];
64
+ If[ StringQ @ Environment[ "GITHUB_ACTION" ], Exit[ 1 ] ]
65
+ ]
66
+ ];
67
+ (* :!CodeAnalysis::EndBlock:: *)
68
+
69
+ (* ::**************************************************************************************************************:: *)
70
+ (* ::Section::Closed:: *)
71
+ (*Run*)
72
+ result = cicd`ScriptConfirmBy[ incrementPacletVersion @ $pacletDir, StringQ ];
73
+
74
+ EndPackage[ ];
75
+
76
+ Wolfram`ChatbookScripts`result
0 commit comments