Skip to content

Commit aa2f134

Browse files
authored
Merge pull request #1006 from WolframResearch/feature/faster-builds
Avoid some repetition to speed up automatic builds
2 parents e609f09 + e1ed62e commit aa2f134

File tree

11 files changed

+219
-149
lines changed

11 files changed

+219
-149
lines changed

.github/workflows/Build.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,23 @@ jobs:
3232
- name: Checkout
3333
uses: actions/checkout@v4
3434

35-
- name: Check
36-
run: wolframscript -f Scripts/CheckPaclet.wls
37-
3835
- name: Build
3936
run: wolframscript -f Scripts/BuildPaclet.wls
4037

41-
- name: UploadArtifact
38+
- name: Upload Artifact
4239
uses: actions/upload-artifact@v4
4340
with:
4441
path: ${{ env.PACLET_BUILD_DIR }}
45-
46-
- name: InstallTestDependencies
42+
43+
- name: Install Test Dependencies
4744
run: |
4845
apt-get update && apt-get install libgomp1 -y
4946
wolframscript -f Scripts/InstallTestDependencies.wls
50-
47+
5148
- name: Test
5249
run: wolframscript -f Scripts/TestPaclet.wls
53-
54-
- name: UploadStackData
50+
51+
- name: Upload Stack Data
5552
if: always() && env.PACLET_STACK_HISTORY
5653
uses: actions/upload-artifact@v4
5754
with:

.github/workflows/ExperimentalRelease.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: Build Paclet
4343
run: wolframscript -f Scripts/BuildPaclet.wls
44-
44+
4545
- name: Rename Paclet File
4646
run: mv "${{ env.PACLET_PATH }}" "${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet"
4747

@@ -52,7 +52,7 @@ jobs:
5252
if ! gh release view experimental; then
5353
gh release create experimental \
5454
--target="${{ github.ref }}" \
55-
--repo="${{ env.GITHUB_REPOSITORY }}" \
55+
--repo="${{ github.repository }}" \
5656
--title="Experimental Release" \
5757
--notes="This is an experimental release that's always updated with the latest build from the main branch." \
5858
--prerelease
@@ -61,4 +61,4 @@ jobs:
6161
gh release upload experimental \
6262
"${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet" \
6363
--clobber \
64-
--repo="${{ env.GITHUB_REPOSITORY }}"
64+
--repo="${{ github.repository }}"

.github/workflows/Release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Check
3636
run: wolframscript -f Scripts/CheckPaclet.wls
37-
37+
3838
- name: Build
3939
run: wolframscript -f Scripts/BuildPaclet.wls
4040

.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,5 @@
108108
"%[0-9A-F]{2}\\w+", // url encoded characters
109109
"1\\:eJ.+" // compressed data
110110
],
111-
"[wolfram]": {
112-
"files.trimTrailingWhitespace": true
113-
}
111+
"files.trimTrailingWhitespace": true
114112
}

Scripts/BuildMX.wls

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Needs[ "PacletTools`" -> "pt`" ];
1515
Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];
1616

1717
Wolfram`ChatbookInternal`$BuildingMX = True;
18+
$assertions = getBooleanArgument[ { "a", "assertions" }, True ];
1819

1920
(* ::**************************************************************************************************************:: *)
2021
(* ::Section::Closed:: *)
@@ -152,8 +153,11 @@ If[ FileExistsQ @ $mxFile,
152153
cicd`ConsoleLog[ "Copying files..." ];
153154
tmp = cicd`ScriptConfirmBy[ copyTemporary @ $pacletDir, DirectoryQ ];
154155
cicd`ScriptConfirmBy[ setPacletReleaseID[ tmp, releaseID @ $pacletDir ], StringQ ];
155-
cicd`ConsoleLog[ "Inserting confirmation source info..." ];
156-
cicd`ScriptConfirm @ expandTags @ tmp;
156+
157+
If[ $assertions,
158+
cicd`ConsoleLog[ "Inserting confirmation source info..." ];
159+
cicd`ScriptConfirm @ expandTags @ tmp
160+
];
157161

158162
cicd`ConsoleLog[ "Loading paclet..." ];
159163
PacletDirectoryUnload @ $pacletDir;

Scripts/BuildPaclet.wls

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,25 @@ BeginPackage[ "Wolfram`ChatbookScripts`" ];
66
(* ::Section::Closed:: *)
77
(*Initialization*)
88
If[ ! TrueQ @ $loadedDefinitions, Get @ FileNameJoin @ { DirectoryName @ $InputFileName, "Common.wl" } ];
9-
Get @ cFile @ FileNameJoin @ { DirectoryName @ $InputFileName, "UnformatFiles.wls" };
10-
Get @ cFile @ FileNameJoin @ { DirectoryName @ $InputFileName, "BuildMX.wls" };
9+
10+
(* ::**************************************************************************************************************:: *)
11+
(* ::Subsection::Closed:: *)
12+
(*Arguments*)
13+
$check = getBooleanArgument[ { "c", "check" }, True ];
14+
$install = getBooleanArgument[ { "i", "install" }, False ];
15+
$mx = getBooleanArgument[ { "m", "mx" }, True ];
16+
$unformat = getBooleanArgument[ { "u", "unformat" }, True ];
17+
18+
(* ::**************************************************************************************************************:: *)
19+
(* ::Subsection::Closed:: *)
20+
(*Optional Dependencies*)
21+
If[ $unformat, Get @ cFile @ FileNameJoin @ { $scriptDir, "UnformatFiles.wls" } ];
22+
If[ $mx , Get @ cFile @ FileNameJoin @ { $scriptDir, "BuildMX.wls" } ];
23+
If[ $check , Get @ cFile @ FileNameJoin @ { $scriptDir, "Resources", "CodeInspectorRules.wl" } ];
24+
25+
(* ::**************************************************************************************************************:: *)
26+
(* ::Subsection::Closed:: *)
27+
(*Other*)
1128
Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];
1229

1330
(* ::**************************************************************************************************************:: *)
@@ -19,15 +36,15 @@ Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];
1936
(*Build*)
2037
result = checkResult @ cicd`BuildPaclet[
2138
$defNB,
22-
"Check" -> False,
39+
"Check" -> $check,
2340
"ExitOnFail" -> True,
2441
"Target" -> "Submit"
2542
];
2643

2744
(* ::**************************************************************************************************************:: *)
2845
(* ::Subsection::Closed:: *)
2946
(*Install*)
30-
If[ MemberQ[ $scriptCommandLine, "-i"|"--install"|"--install=true" ],
47+
If[ $install,
3148
archive = cFile @ result[ "PacletArchive" ];
3249
cicd`ConsoleNotice @ SequenceForm[ "Installing paclet file: ", archive ];
3350
installed = cicd`ScriptConfirmBy[ PacletInstall[ archive, ForceVersionInstall -> True ], PacletObjectQ ];

Scripts/CheckPaclet.wls

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -3,129 +3,7 @@
33
BeginPackage[ "Wolfram`ChatbookScripts`" ];
44

55
If[ ! TrueQ @ $loadedDefinitions, Get @ FileNameJoin @ { DirectoryName @ $InputFileName, "Common.wl" } ];
6-
7-
Needs[ "CodeInspector`" -> "ci`" ];
8-
Needs[ "CodeParser`" -> "cp`" ];
9-
10-
(* ::**************************************************************************************************************:: *)
11-
(* ::Section::Closed:: *)
12-
(*Config*)
13-
$inGitHub := $inGitHub = StringQ @ Environment[ "GITHUB_ACTIONS" ];
14-
15-
(* ::**************************************************************************************************************:: *)
16-
(* ::Section::Closed:: *)
17-
(*Custom Rules*)
18-
CodeInspector`AbstractRules`$DefaultAbstractRules = <|
19-
CodeInspector`AbstractRules`$DefaultAbstractRules,
20-
cp`CallNode[ cp`LeafNode[ Symbol, "Throw", _ ], { _ }, _ ] -> scanSingleArgThrow,
21-
cp`LeafNode[ Symbol, _String? privateContextQ, _ ] -> scanPrivateContext,
22-
cp`LeafNode[ Symbol, _String? globalSymbolQ, _ ] -> scanGlobalSymbol
23-
|>;
24-
25-
CodeInspector`ConcreteRules`$DefaultConcreteRules = <|
26-
CodeInspector`ConcreteRules`$DefaultConcreteRules,
27-
cp`LeafNode[
28-
Token`Comment,
29-
_String? (StringStartsQ[ "(*"~~WhitespaceCharacter...~~"FIXME:" ]),
30-
_
31-
] -> scanFixMeComment
32-
|>;
33-
34-
(* ::**************************************************************************************************************:: *)
35-
(* ::Subsection::Closed:: *)
36-
(*scanSingleArgThrow*)
37-
scanSingleArgThrow // ClearAll;
38-
scanSingleArgThrow[ pos_, ast_ ] := Catch[
39-
Replace[
40-
Fold[ walkASTForCatch, ast, pos ],
41-
{
42-
cp`CallNode[ cp`LeafNode[ Symbol, "Throw", _ ], _, as_Association ] :>
43-
ci`InspectionObject[
44-
"NoSurroundingCatch",
45-
"``Throw`` has no tag or surrounding ``Catch``",
46-
"Error",
47-
<| as, ConfidenceLevel -> 0.9 |>
48-
],
49-
___ :> { }
50-
}
51-
],
52-
$tag
53-
];
54-
55-
(* ::**************************************************************************************************************:: *)
56-
(* ::Subsubsection::Closed:: *)
57-
(*walkASTForCatch*)
58-
walkASTForCatch // ClearAll;
59-
60-
walkASTForCatch[ cp`CallNode[ cp`LeafNode[ Symbol, "Catch"|"Hold"|"HoldForm"|"HoldComplete", _ ], { _ }, _ ], _ ] :=
61-
Throw[ { }, $tag ];
62-
63-
walkASTForCatch[ ast_, pos_ ] :=
64-
Extract[ ast, pos ];
65-
66-
(* ::**************************************************************************************************************:: *)
67-
(* ::Subsection::Closed:: *)
68-
(*scanPrivateContext*)
69-
scanPrivateContext // ClearAll;
70-
scanPrivateContext[ pos_, ast_ ] :=
71-
Enclose @ Module[ { node, name, as },
72-
node = ConfirmMatch[ Extract[ ast, pos ], _[ _, _, __ ], "Node" ];
73-
name = ConfirmBy[ node[[ 2 ]], StringQ, "Name" ];
74-
as = ConfirmBy[ node[[ 3 ]], AssociationQ, "Metadata" ];
75-
ci`InspectionObject[
76-
"PrivateContextSymbol",
77-
"The symbol ``" <> name <> "`` is in a private context",
78-
"Warning",
79-
<| as, ConfidenceLevel -> 0.9 |>
80-
]
81-
];
82-
83-
(* ::**************************************************************************************************************:: *)
84-
(* ::Subsubsection::Closed:: *)
85-
(*privateContextQ*)
86-
privateContextQ // ClearAll;
87-
privateContextQ[ name_String ] /; StringStartsQ[ name, "System`Private`" ] := False;
88-
privateContextQ[ name_String ] := StringContainsQ[ name, __ ~~ ("`Private`"|"`PackagePrivate`") ];
89-
privateContextQ[ ___ ] := False;
90-
91-
(* ::**************************************************************************************************************:: *)
92-
(* ::Subsection::Closed:: *)
93-
(*scanGlobalSymbol*)
94-
scanGlobalSymbol // ClearAll;
95-
scanGlobalSymbol[ pos_, ast_ ] :=
96-
Enclose @ Module[ { node, name, as },
97-
node = ConfirmMatch[ Extract[ ast, pos ], _[ _, _, __ ], "Node" ];
98-
name = ConfirmBy[ node[[ 2 ]], StringQ, "Name" ];
99-
as = ConfirmBy[ node[[ 3 ]], AssociationQ, "Metadata" ];
100-
ci`InspectionObject[
101-
"GlobalSymbol",
102-
"The symbol ``" <> name <> "`` is in the global context",
103-
"Error",
104-
<| as, ConfidenceLevel -> 0.9 |>
105-
]
106-
];
107-
108-
(* ::**************************************************************************************************************:: *)
109-
(* ::Subsubsection::Closed:: *)
110-
(*globalSymbolQ*)
111-
globalSymbolQ // ClearAll;
112-
globalSymbolQ[ name_String ] := StringStartsQ[ name, "Global`" ];
113-
globalSymbolQ[ ___ ] := False;
114-
115-
(* ::**************************************************************************************************************:: *)
116-
(* ::Subsection::Closed:: *)
117-
(*scanFixMeComment*)
118-
scanFixMeComment // ClearAll;
119-
120-
scanFixMeComment[ pos_, ast_ ] /; $inGitHub :=
121-
Enclose @ Module[ { node, comment, as },
122-
node = ConfirmMatch[ Extract[ ast, pos ], _[ _, _, __ ], "Node" ];
123-
comment = StringTrim @ StringTrim[ ConfirmBy[ node[[ 2 ]], StringQ, "Comment" ], { "(*", "*)" } ];
124-
as = ConfirmBy[ node[[ 3 ]], AssociationQ, "Metadata" ];
125-
ci`InspectionObject[ "FixMeComment", comment, "Remark", <| as, ConfidenceLevel -> 0.9 |> ]
126-
];
127-
128-
scanFixMeComment[ pos_, ast_ ] := { };
6+
Get @ cFile @ FileNameJoin @ { $scriptDir, "Resources", "CodeInspectorRules.wl" };
1297

1308
(* ::**************************************************************************************************************:: *)
1319
(* ::Section::Closed:: *)

Scripts/Common.wl

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ $messageHistory = <| |>;
3838
$stackHistory = <| |>;
3939
$inputFileName = cFile @ Replace[ $InputFileName, "" :> NotebookFileName[ ] ];
4040
$pacletDir = cDir @ DirectoryName[ $inputFileName, 2 ];
41+
$scriptDir = DirectoryName @ $inputFileName;
4142

4243
Internal`AddHandler[ "Message", messageHandler ];
4344

@@ -105,9 +106,59 @@ messageString[ ___ ] := "-- Message text not found --";
105106

106107
(* ::**************************************************************************************************************:: *)
107108
(* ::Section::Closed:: *)
108-
(*Definitions*)
109-
$scriptCommandLine := Replace[ $ScriptCommandLine, { } :> $CommandLine ];
109+
(*Command Line Arguments*)
110+
$scriptCommandLine := Select[ Flatten @ { Replace[ $ScriptCommandLine, { } :> $CommandLine ] }, StringQ ];
111+
112+
(* ::**************************************************************************************************************:: *)
113+
(* ::Subsection::Closed:: *)
114+
(*getBooleanArgument*)
115+
getBooleanArgument // Attributes = { HoldRest };
116+
117+
getBooleanArgument[ name_ ] :=
118+
getBooleanArgument[ name, False ];
119+
120+
getBooleanArgument[ name_String, default_ ] :=
121+
getBooleanArgument[ { name, name }, default ];
122+
123+
getBooleanArgument[ { short_String, full_String }, default_ ] := Catch[
124+
Module[ { named, interpreted, res },
125+
If[ MemberQ[ $scriptCommandLine, "-"<>short | "--"<>full ], Throw[ True, $booleanTag ] ];
126+
named = getNamedArgument @ full;
127+
If[ ! StringQ @ named, Throw[ default, $booleanTag ] ];
128+
interpreted = Interpreter[ "Boolean" ][ named ];
129+
If[ BooleanQ @ interpreted,
130+
interpreted,
131+
res = default;
132+
cicd`ConsoleError @ TemplateApply[
133+
"The value \"`1`\" specified for \"`2`\" is not a valid boolean value. Using default value: \"`3`\".",
134+
{ named, full, res }
135+
];
136+
res
137+
]
138+
],
139+
$booleanTag
140+
];
110141

142+
(* ::**************************************************************************************************************:: *)
143+
(* ::Subsection::Closed:: *)
144+
(*getNamedArgument*)
145+
getNamedArgument // Attributes = { HoldRest };
146+
147+
getNamedArgument[ name_ ] :=
148+
getNamedArgument[ name, Missing[ "NotSpecified" ] ];
149+
150+
getNamedArgument[ name_String, default_ ] :=
151+
Module[ { arg },
152+
arg = SelectFirst[ $scriptCommandLine, StringQ @ # && StringStartsQ[ #, "--"<>name<>"=" ] & ];
153+
If[ StringQ @ arg,
154+
StringDelete[ arg, StartOfString ~~ "--"<>name<>"=" ],
155+
default
156+
]
157+
];
158+
159+
(* ::**************************************************************************************************************:: *)
160+
(* ::Section::Closed:: *)
161+
(*Definitions*)
111162
$$ws = WhitespaceCharacter...;
112163
$$id = "\"" ~~ Except[ "\"" ].. ~~ "\"";
113164

0 commit comments

Comments
 (0)