diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8579a34 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bc3d0ca --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..937b62d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# submit-paclet \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..a75029d --- /dev/null +++ b/action.yml @@ -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' diff --git a/src/install_dependencies.wls b/src/install_dependencies.wls new file mode 100644 index 0000000..d8b15d5 --- /dev/null +++ b/src/install_dependencies.wls @@ -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:: *) \ No newline at end of file diff --git a/src/main.sh b/src/main.sh new file mode 100644 index 0000000..b7a03af --- /dev/null +++ b/src/main.sh @@ -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::" \ No newline at end of file diff --git a/src/submit_paclet.wls b/src/submit_paclet.wls new file mode 100644 index 0000000..4461b74 --- /dev/null +++ b/src/submit_paclet.wls @@ -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:: *) \ No newline at end of file