Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid some repetition to speed up automatic builds #1006

Merged
merged 5 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Check
run: wolframscript -f Scripts/CheckPaclet.wls

- name: Build
run: wolframscript -f Scripts/BuildPaclet.wls

- name: UploadArtifact
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
path: ${{ env.PACLET_BUILD_DIR }}
- name: InstallTestDependencies

- name: Install Test Dependencies
run: |
apt-get update && apt-get install libgomp1 -y
wolframscript -f Scripts/InstallTestDependencies.wls

- name: Test
run: wolframscript -f Scripts/TestPaclet.wls
- name: UploadStackData

- name: Upload Stack Data
if: always() && env.PACLET_STACK_HISTORY
uses: actions/upload-artifact@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ExperimentalRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Build Paclet
run: wolframscript -f Scripts/BuildPaclet.wls

- name: Rename Paclet File
run: mv "${{ env.PACLET_PATH }}" "${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet"

Expand All @@ -52,7 +52,7 @@ jobs:
if ! gh release view experimental; then
gh release create experimental \
--target="${{ github.ref }}" \
--repo="${{ env.GITHUB_REPOSITORY }}" \
--repo="${{ github.repository }}" \
--title="Experimental Release" \
--notes="This is an experimental release that's always updated with the latest build from the main branch." \
--prerelease
Expand All @@ -61,4 +61,4 @@ jobs:
gh release upload experimental \
"${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet" \
--clobber \
--repo="${{ env.GITHUB_REPOSITORY }}"
--repo="${{ github.repository }}"
2 changes: 1 addition & 1 deletion .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Check
run: wolframscript -f Scripts/CheckPaclet.wls

- name: Build
run: wolframscript -f Scripts/BuildPaclet.wls

Expand Down
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,5 @@
"%[0-9A-F]{2}\\w+", // url encoded characters
"1\\:eJ.+" // compressed data
],
"[wolfram]": {
"files.trimTrailingWhitespace": true
}
"files.trimTrailingWhitespace": true
}
8 changes: 6 additions & 2 deletions Scripts/BuildMX.wls
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Needs[ "PacletTools`" -> "pt`" ];
Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];

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

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
Expand Down Expand Up @@ -152,8 +153,11 @@ If[ FileExistsQ @ $mxFile,
cicd`ConsoleLog[ "Copying files..." ];
tmp = cicd`ScriptConfirmBy[ copyTemporary @ $pacletDir, DirectoryQ ];
cicd`ScriptConfirmBy[ setPacletReleaseID[ tmp, releaseID @ $pacletDir ], StringQ ];
cicd`ConsoleLog[ "Inserting confirmation source info..." ];
cicd`ScriptConfirm @ expandTags @ tmp;

If[ $assertions,
cicd`ConsoleLog[ "Inserting confirmation source info..." ];
cicd`ScriptConfirm @ expandTags @ tmp
];

cicd`ConsoleLog[ "Loading paclet..." ];
PacletDirectoryUnload @ $pacletDir;
Expand Down
25 changes: 21 additions & 4 deletions Scripts/BuildPaclet.wls
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@ BeginPackage[ "Wolfram`ChatbookScripts`" ];
(* ::Section::Closed:: *)
(*Initialization*)
If[ ! TrueQ @ $loadedDefinitions, Get @ FileNameJoin @ { DirectoryName @ $InputFileName, "Common.wl" } ];
Get @ cFile @ FileNameJoin @ { DirectoryName @ $InputFileName, "UnformatFiles.wls" };
Get @ cFile @ FileNameJoin @ { DirectoryName @ $InputFileName, "BuildMX.wls" };

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*Arguments*)
$check = getBooleanArgument[ { "c", "check" }, True ];
$install = getBooleanArgument[ { "i", "install" }, False ];
$mx = getBooleanArgument[ { "m", "mx" }, True ];
$unformat = getBooleanArgument[ { "u", "unformat" }, True ];

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*Optional Dependencies*)
If[ $unformat, Get @ cFile @ FileNameJoin @ { $scriptDir, "UnformatFiles.wls" } ];
If[ $mx , Get @ cFile @ FileNameJoin @ { $scriptDir, "BuildMX.wls" } ];
If[ $check , Get @ cFile @ FileNameJoin @ { $scriptDir, "Resources", "CodeInspectorRules.wl" } ];

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*Other*)
Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];

(* ::**************************************************************************************************************:: *)
Expand All @@ -19,15 +36,15 @@ Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];
(*Build*)
result = checkResult @ cicd`BuildPaclet[
$defNB,
"Check" -> False,
"Check" -> $check,
"ExitOnFail" -> True,
"Target" -> "Submit"
];

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*Install*)
If[ MemberQ[ $scriptCommandLine, "-i"|"--install"|"--install=true" ],
If[ $install,
archive = cFile @ result[ "PacletArchive" ];
cicd`ConsoleNotice @ SequenceForm[ "Installing paclet file: ", archive ];
installed = cicd`ScriptConfirmBy[ PacletInstall[ archive, ForceVersionInstall -> True ], PacletObjectQ ];
Expand Down
124 changes: 1 addition & 123 deletions Scripts/CheckPaclet.wls
Original file line number Diff line number Diff line change
Expand Up @@ -3,129 +3,7 @@
BeginPackage[ "Wolfram`ChatbookScripts`" ];

If[ ! TrueQ @ $loadedDefinitions, Get @ FileNameJoin @ { DirectoryName @ $InputFileName, "Common.wl" } ];

Needs[ "CodeInspector`" -> "ci`" ];
Needs[ "CodeParser`" -> "cp`" ];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Config*)
$inGitHub := $inGitHub = StringQ @ Environment[ "GITHUB_ACTIONS" ];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Custom Rules*)
CodeInspector`AbstractRules`$DefaultAbstractRules = <|
CodeInspector`AbstractRules`$DefaultAbstractRules,
cp`CallNode[ cp`LeafNode[ Symbol, "Throw", _ ], { _ }, _ ] -> scanSingleArgThrow,
cp`LeafNode[ Symbol, _String? privateContextQ, _ ] -> scanPrivateContext,
cp`LeafNode[ Symbol, _String? globalSymbolQ, _ ] -> scanGlobalSymbol
|>;

CodeInspector`ConcreteRules`$DefaultConcreteRules = <|
CodeInspector`ConcreteRules`$DefaultConcreteRules,
cp`LeafNode[
Token`Comment,
_String? (StringStartsQ[ "(*"~~WhitespaceCharacter...~~"FIXME:" ]),
_
] -> scanFixMeComment
|>;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*scanSingleArgThrow*)
scanSingleArgThrow // ClearAll;
scanSingleArgThrow[ pos_, ast_ ] := Catch[
Replace[
Fold[ walkASTForCatch, ast, pos ],
{
cp`CallNode[ cp`LeafNode[ Symbol, "Throw", _ ], _, as_Association ] :>
ci`InspectionObject[
"NoSurroundingCatch",
"``Throw`` has no tag or surrounding ``Catch``",
"Error",
<| as, ConfidenceLevel -> 0.9 |>
],
___ :> { }
}
],
$tag
];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*walkASTForCatch*)
walkASTForCatch // ClearAll;

walkASTForCatch[ cp`CallNode[ cp`LeafNode[ Symbol, "Catch"|"Hold"|"HoldForm"|"HoldComplete", _ ], { _ }, _ ], _ ] :=
Throw[ { }, $tag ];

walkASTForCatch[ ast_, pos_ ] :=
Extract[ ast, pos ];

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*scanPrivateContext*)
scanPrivateContext // ClearAll;
scanPrivateContext[ pos_, ast_ ] :=
Enclose @ Module[ { node, name, as },
node = ConfirmMatch[ Extract[ ast, pos ], _[ _, _, __ ], "Node" ];
name = ConfirmBy[ node[[ 2 ]], StringQ, "Name" ];
as = ConfirmBy[ node[[ 3 ]], AssociationQ, "Metadata" ];
ci`InspectionObject[
"PrivateContextSymbol",
"The symbol ``" <> name <> "`` is in a private context",
"Warning",
<| as, ConfidenceLevel -> 0.9 |>
]
];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*privateContextQ*)
privateContextQ // ClearAll;
privateContextQ[ name_String ] /; StringStartsQ[ name, "System`Private`" ] := False;
privateContextQ[ name_String ] := StringContainsQ[ name, __ ~~ ("`Private`"|"`PackagePrivate`") ];
privateContextQ[ ___ ] := False;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*scanGlobalSymbol*)
scanGlobalSymbol // ClearAll;
scanGlobalSymbol[ pos_, ast_ ] :=
Enclose @ Module[ { node, name, as },
node = ConfirmMatch[ Extract[ ast, pos ], _[ _, _, __ ], "Node" ];
name = ConfirmBy[ node[[ 2 ]], StringQ, "Name" ];
as = ConfirmBy[ node[[ 3 ]], AssociationQ, "Metadata" ];
ci`InspectionObject[
"GlobalSymbol",
"The symbol ``" <> name <> "`` is in the global context",
"Error",
<| as, ConfidenceLevel -> 0.9 |>
]
];

(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*globalSymbolQ*)
globalSymbolQ // ClearAll;
globalSymbolQ[ name_String ] := StringStartsQ[ name, "Global`" ];
globalSymbolQ[ ___ ] := False;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*scanFixMeComment*)
scanFixMeComment // ClearAll;

scanFixMeComment[ pos_, ast_ ] /; $inGitHub :=
Enclose @ Module[ { node, comment, as },
node = ConfirmMatch[ Extract[ ast, pos ], _[ _, _, __ ], "Node" ];
comment = StringTrim @ StringTrim[ ConfirmBy[ node[[ 2 ]], StringQ, "Comment" ], { "(*", "*)" } ];
as = ConfirmBy[ node[[ 3 ]], AssociationQ, "Metadata" ];
ci`InspectionObject[ "FixMeComment", comment, "Remark", <| as, ConfidenceLevel -> 0.9 |> ]
];

scanFixMeComment[ pos_, ast_ ] := { };
Get @ cFile @ FileNameJoin @ { $scriptDir, "Resources", "CodeInspectorRules.wl" };

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
Expand Down
55 changes: 53 additions & 2 deletions Scripts/Common.wl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ $messageHistory = <| |>;
$stackHistory = <| |>;
$inputFileName = cFile @ Replace[ $InputFileName, "" :> NotebookFileName[ ] ];
$pacletDir = cDir @ DirectoryName[ $inputFileName, 2 ];
$scriptDir = DirectoryName @ $inputFileName;

Internal`AddHandler[ "Message", messageHandler ];

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

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Definitions*)
$scriptCommandLine := Replace[ $ScriptCommandLine, { } :> $CommandLine ];
(*Command Line Arguments*)
$scriptCommandLine := Select[ Flatten @ { Replace[ $ScriptCommandLine, { } :> $CommandLine ] }, StringQ ];

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*getBooleanArgument*)
getBooleanArgument // Attributes = { HoldRest };

getBooleanArgument[ name_ ] :=
getBooleanArgument[ name, False ];

getBooleanArgument[ name_String, default_ ] :=
getBooleanArgument[ { name, name }, default ];

getBooleanArgument[ { short_String, full_String }, default_ ] := Catch[
Module[ { named, interpreted, res },
If[ MemberQ[ $scriptCommandLine, "-"<>short | "--"<>full ], Throw[ True, $booleanTag ] ];
named = getNamedArgument @ full;
If[ ! StringQ @ named, Throw[ default, $booleanTag ] ];
interpreted = Interpreter[ "Boolean" ][ named ];
If[ BooleanQ @ interpreted,
interpreted,
res = default;
cicd`ConsoleError @ TemplateApply[
"The value \"`1`\" specified for \"`2`\" is not a valid boolean value. Using default value: \"`3`\".",
{ named, full, res }
];
res
]
],
$booleanTag
];

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*getNamedArgument*)
getNamedArgument // Attributes = { HoldRest };

getNamedArgument[ name_ ] :=
getNamedArgument[ name, Missing[ "NotSpecified" ] ];

getNamedArgument[ name_String, default_ ] :=
Module[ { arg },
arg = SelectFirst[ $scriptCommandLine, StringQ @ # && StringStartsQ[ #, "--"<>name<>"=" ] & ];
If[ StringQ @ arg,
StringDelete[ arg, StartOfString ~~ "--"<>name<>"=" ],
default
]
];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Definitions*)
$$ws = WhitespaceCharacter...;
$$id = "\"" ~~ Except[ "\"" ].. ~~ "\"";

Expand Down
Loading
Loading