Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rhennigan committed Mar 31, 2022
0 parents commit 699ce62
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Container image that runs your code
FROM wolframresearch/wolframengine:13.0.0

COPY ["src", "/src/"]

USER root
RUN chmod +x /src/main.sh

ENTRYPOINT ["/src/main.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Rick Hennigan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# submit-paclet
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Submit Paclet'
description: 'Submit a paclet using its definition notebook file'
branding:
icon: 'upload-cloud'
color: 'orange'
inputs:
definition_notebook:
description: 'Path to the definition notebook'
required: false
default: './ResourceDefinition.nb'
paclet_cicd_version:
description: 'Version of PacletCICD to use'
required: false
default: 'latest'
resource_system_base:
description: 'Specifies the location of the resource system'
required: false
default: 'https://www.wolframcloud.com/obj/resourcesystem/api/1.0'
runs:
using: 'docker'
image: 'Dockerfile'
104 changes: 104 additions & 0 deletions src/install_dependencies.wls
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env wolframscript
(* ::Package:: *)

(* :!CodeAnalysis::BeginBlock:: *)
(* :!CodeAnalysis::Disable::SuspiciousSessionSymbol:: *)

print[ a___ ] := WriteString[ "stdout", a, "\n" ];

getInput[ name_String ] :=
Module[ { val },
val = Environment[ "INPUT_" <> name ];
print[ name, "=", val ];
val
];

$pacletsRoot = "https://www.wolframcloud.com/obj/rhennigan/Paclets";

pacletInstall[ n_String -> v_String ] := pacletInstall[ n <> "-" <> v ];

pacletInstall[ url_String? urlQ ] := Enclose[
Module[ { installed },
print[ "Installing paclet from: ", url ];
installed = PacletInstall[ url, ForceVersionInstall -> True ];
If[ PacletObjectQ @ installed,
print[ "Paclet installed to: ", installed[ "Location" ] ],
print[ "::error:: Paclet installation failed: ", installed ];
Exit[ 1 ]
]
],
Function[
print[ "::error:: Paclet installation failed: ", url ];
Exit[ 1 ]
]
];

pacletInstall[ spec_String ] := Enclose[
Module[ { url, zip, tmp, pacs, dir, downloaded, installed },
url = URLBuild @ { $pacletsRoot, spec <> ".paclet" };
ConfirmAssert @ StringQ @ url;
print[ "Installing paclet from: ", url ];
If[ StringEndsQ[ url, ".zip" ],
zip = Confirm @ URLDownload @ url;
Confirm @ ExtractArchive[ zip, tmp = CreateDirectory[ ] ];
pacs = FileNames[ "PacletInfo." ~~ ("m"|"wl"), tmp, Infinity ];
dir = DirectoryName @ Confirm @ First[ pacs, $Failed ];
downloaded = CreatePacletArchive @ dir,
downloaded = url
];
installed = PacletInstall[ downloaded, ForceVersionInstall -> True ];
If[ PacletObjectQ @ installed,
print[ "Paclet installed to: ", installed[ "Location" ] ],
print[ "::error:: Paclet installation failed: ", installed ];
Exit[ 1 ]
]
],
Function[
print[ "::error:: Paclet installation failed: ", spec ];
Exit[ 1 ]
]
];


urlQ[ url_String ] := StringQ @ URLParse[ url, "Scheme" ];
urlQ[ ___ ] := False;


toPacletCICDURL[ "latest" ] :=
Part[
URLExecute[
"https://api.github.com/repos/rhennigan/PacletCICD/releases/latest",
"RawJSON"
],
"assets",
1,
"browser_download_url"
];

toPacletCICDURL[ vers_String ] :=
If[ StringMatchQ[ vers, (DigitCharacter..~~".")...~~(DigitCharacter..) ],
TemplateApply[
"https://github.com/rhennigan/PacletCICD/releases/download/v`1`/Wolfram__PacletCICD-`1`.paclet",
{ vers }
],
TemplateApply[
"https://github.com/rhennigan/PacletCICD/archive/refs/heads/`1`.zip",
vers
]
];

pacletInstall[ "DefinitionNotebookClient" -> "1.9.0" ];
pacletInstall[ "PacletResource" -> "0.10.0" ];
pacletInstall[ "ResourceSystemClient" -> "1.24.0" ];

pacVer = getInput[ "PACLET_CICD_VERSION" ];
pacURL = toPacletCICDURL @ pacVer;

If[ ! StringQ @ pacURL,
Print[ "Could not determine URL for specified version" ];
Exit[ 1 ]
];

pacletInstall @ pacURL;

(* :!CodeAnalysis::EndBlock:: *)
13 changes: 13 additions & 0 deletions src/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

export SCRIPT_DIR=$(dirname ${0})

echo "::group::Installing dependencies..."
wolframscript ${SCRIPT_DIR}/install_dependencies.wls
echo "::endgroup::"

echo "::group::Submitting Paclet..."
wolframscript ${SCRIPT_DIR}/submit_paclet.wls
echo "::endgroup::"
76 changes: 76 additions & 0 deletions src/submit_paclet.wls
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env wolframscript
(* ::Package:: *)

(* :!CodeAnalysis::BeginBlock:: *)
(* :!CodeAnalysis::Disable::SuspiciousSessionSymbol:: *)

(* ::**********************************************************************:: *)
(* ::Section::Closed:: *)
(*Initialization*)
print[ a___ ] := WriteString[ "stdout", a, "\n" ];

print[ "Loading Wolfram`PacletCICD` from ", FindFile[ "Wolfram`PacletCICD`" ] ];

Needs[ "Wolfram`PacletCICD`" ];

getInput[ name_String ] :=
Module[ { val },
val = Environment[ "INPUT_" <> name ];
print[ name, "=", val ];
val
];

print[ "Submitting paclet..." ];

(* ::**********************************************************************:: *)
(* ::Section::Closed:: *)
(*Inputs*)

(* ::**********************************************************************:: *)
(* ::Subsection::Closed:: *)
(*Definition Notebook*)
defNB = getInput[ "DEFINITION_NOTEBOOK" ];
If[ ! FileExistsQ @ ExpandFileName @ defNB,
print[ "::error::Definition notebook not found: ", defNB ];
Exit[ 1 ]
];

(* ::**********************************************************************:: *)
(* ::Subsection::Closed:: *)
(*ResourceSystemBase*)
rsBase = getInput[ "RESOURCE_SYSTEM_BASE" ];
rsTestURL = URLBuild @ { rsBase, "TestSystem" };
rsBaseTest = URLFetch[ rsTestURL, { "StatusCode", "Content" } ];
If[ ! MatchQ[ rsBaseTest, { 200, _String } ],
print[ "::error::Invalid ResourceSystemBase: ", rsBase ];
print[ "::error::ResourceSystemBase test output: ", rsBaseTest ];
Exit[ 1 ]
];

Needs[ "ResourceSystemClient`" -> None ];
$ResourceSystemBase = rsBase;

(* ::**********************************************************************:: *)
(* ::Section::Closed:: *)
(*Run*)
result =
Block[
{
Print = print,
DefinitionNotebookClient`BeginConsoleGroup,
DefinitionNotebookClient`EndConsoleGroup
},
Wolfram`PacletCICD`SubmitPaclet[
File @ defNB,
"ConsoleType" -> "GitHub"
]
];

print @ result;

If[ MatchQ[ result, _Wolfram`PacletCICD`SubmitPaclet ],
print[ "::error::Wolfram`PacletCICD`SubmitPaclet not defined" ];
Exit[ 1 ]
];

(* :!CodeAnalysis::EndBlock:: *)

0 comments on commit 699ce62

Please sign in to comment.