Refactored tasks
h3rald h3rald@h3rald.com
Thu, 21 Jan 2021 18:39:16 +0100
10 files changed,
420 insertions(+),
311 deletions(-)
M
next-release.md
→
next-release.md
@@ -1,4 +1,5 @@
* Added support for Scheme-style block comments using hashpipe style: `#| ... |#`. * Implemented support for documentation comments (`;;` or `#|| ... ||#`) placed right after an operator definition. * **BREAKING CHANGE** -- **?** is now used as a sigil for **help**, not **dget**. -* Added **help** (and also **?** alias and **?** sigil), **symbol-help**, **sigil-help** -- UNDOCUMENTED!+* Added **help** (and also **?** alias and **?** sigil), **symbol-help**, **sigil-help** -- UNDOCUMENTED! +* Refactored tasks as required modules.
M
run.min
→
run.min
@@ -22,8 +22,12 @@ (taskspec size 1 >) (taskspec 1 get @subtask) when
"tasks/$#.min" (task) =% :task-file +task-file require :tasklist + +"tasklist/$#" (subtask) =% invoke + ; Load task module -task-file load +;task-file load ; Execute task -"$#-tasks" (task) =% eval subtask ^ +;"$#-tasks" (task) =% eval subtask ^
M
tasks/_helpers.min
→
tasks/_helpers.min
@@ -2,9 +2,10 @@
"min.yml" fread from-yaml :config ".env.yml" fread from-yaml :env -; Module symbols -{} ( - :prog (prog which "" ==) ("$# is not available" (prog) =% error 1 exit) when -) %required -+helpers+ symbol required + ('sym :prog ==>) + ( + (prog which "" ==) ("$# is not available" (prog) =% error 1 exit) when + ) +) ::
M
tasks/build.min
→
tasks/build.min
@@ -1,117 +1,180 @@
#!/usr/bin/env min -"_helpers" load -'helpers import +"_helpers" require :helpers 'helpers import ( - :target-os - :variant - :stage - "-d:release" :d-stage - (stage "dev" ==) - ("-d:dev" @d-stage) - when - " " :d-variant - "min" :o-variant - (variant length 0 >) ( - "-d:$# " (variant) =% @d-variant - "$#min" (variant) =% @o-variant - ) when - "nim" required - "Building $# - $# (x64)" (o-variant target-os) =% notice - "" :musl - "musl-gcc" which :musl-gcc - (musl-gcc length 0 >) - ("--gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc" @musl) - when - "nim c $# -d:ssl $# --cpu:amd64 --os:$# $#-o:$# min" (d-stage musl target-os d-variant o-variant) =% puts ! - {} - target-os %os - config /version %version - o-variant %exe - (stage "dev" !=) - (pack) - when -) :cz + symbol cz + ('sym :stage 'sym :variant 'sym :target-os ==>) + ( + "-d:release" :d-stage + (stage "dev" ==) + ("-d:dev" @d-stage) + when + " " :d-variant + "min" :o-variant + (variant length 0 >) ( + "-d:$# " (variant) =% @d-variant + "$#min" (variant) =% @o-variant + ) when + "nim" required + "Building $# - $# (x64)" (o-variant target-os) =% notice! + "" :musl + "musl-gcc" which :musl-gcc + (musl-gcc length 0 >) + ("--gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc" @musl) + when + "nim c $# -d:ssl $# --cpu:amd64 --os:$# $#-o:$# min" (d-stage musl target-os d-variant o-variant) =% puts ! pop + {} + target-os %os + config /version %version + o-variant %exe + (stage "dev" !=) + (pack) + when + ) +) :: +;; Builds and packs a min executable. + +#| Tasks |# + ( - :vdata - vdata /exe :exe - (vdata /os "windows" ==) ("$#.exe" (exe) =% @exe) when - "$exe:_v$version:_$os:_x64.zip" :fn - fn vdata dpairs % ":" "" replace @fn - "Compressing: $#" (fn) =% notice - (exe) => fn zip -) :pack + symbol guide + (==>) + ( + "hastyscribe" required + "Building - guide" notice! + "hastyscribe Min_DeveloperGuide.md --field/version=$#" (version) =% ! + !"cp Min_DeveloperGuide.htm site/output/guide.dev.html" + ) +) :: +;; Builds the developer guide. ( - "hastyscribe" required - "Building - guide" notice - "hastyscribe Min_DeveloperGuide.md --field/version=$#" (version) =% ! - !"cp Min_DeveloperGuide.htm site/output/guide.dev.html" -) :build-guide + symbol site + (==>) + ( + "hastysite" required + "Building - site" notice! + !"cd site && hastysite build && cd .." + ) +) :: +;; Builds the min site. + ( - "hastysite" required - "Building - site" notice - "cd site && hastysite build && cd .." ! -) :build-site + symbol pack + (dict :vdata ==>) + ( + vdata /exe :exe + (vdata /os "windows" ==) ("$#.exe" (exe) =% @exe) when + "$exe:_v$version:_$os:_x64.zip" :fn + fn vdata dpairs % ":" "" replace @fn + "Compressing: $#" (fn) =% notice! + (exe) => fn zip + ) +) :: +;; Compresses a min executable. + ( - config /version :min-version - "tasks/templates/min.vim" fread :template - timestamp "dd MMM YYYY" tformat :date - min-symbols " " join :symbols - "min.vim" :out-file - "Building - min.vim" notice - template ("date" date "version" min-version "symbols" symbols) =% out-file fwrite -) :build-vim + symbol vim + (==>) + ( + config /version :min-version + "tasks/templates/min.vim" fread :template + timestamp "dd MMM YYYY" tformat :date + min-symbols " " join :symbols + "min.vim" :out-file + "Building - min.vim" notice! + template ("date" date "version" min-version "symbols" symbols) =% out-file fwrite + ) +) :: +;; Generates the min.vim file. -; Module symbols -{} ( - "" "lite" os cz -) %lite + symbol docs + (==>) + ( + guide + site + ) +) :: +;; Generate the min development guide and site. + ( - "" "mini" os cz -) %mini -( - "dev" "" os cz -) %dev + symbol lite + (==>) + ("" "lite" os cz) +) :: +;; Builds litemin on the current OS. + ( - "" "" os cz -) %default + symbol mini + (==>) + ("" "mini" os cz) +) :: +;; Builds minimin on the current OS. ( - "" "" "linux" cz -) %linux + symbol dev + (==>) + ("dev" "" os cz) +) :: +;; Builds min (dev version) on the current OS. ( - "" "lite" "linux" cz -) %linux-lite + symbol default + (==>) + ("" "" os cz) +) :: +;; Builds min on the current OS. ( - "" "mini" "linux" cz -) %linux-mini + symbol linux + (==>) + ("" "" "linux" cz) +) :: +;; Builds min for Linux. ( - "" "" "macosx" cz -) %macosx + symbol linux-lite + (==>) + ("" "lite" "linux" cz) +) :: +;; Builds litemin for Linux. ( - "" "lite" "macosx" cz -) %macosx-lite + symbol linux-mini + (==>) + ("" "" "linux-mini" cz) +) :: +;; Builds minimin for Linux. ( - "" "mini" "macosx" cz -) %macosx-mini + symbol macosx + (==>) + ("" "" "macosx" cz) +) :: +;; Builds min for macOS. ( - "" "" "windows" cz -) %windows + symbol macosx-lite + (==>) + ("" "lite" "macosx" cz) +) :: +;; Builds litemin for macOS. ( - "" "lite" "windows" cz -) %windows-lite + symbol macosx-mini + (==>) + ("" "" "macosx-mini" cz) +) :: +;; Builds minimin for macOS. ( - "" "mini" "windows" cz -) %windows-mini -'build-guide %guide -'build-site %site + symbol windows + (==>) + ("" "" "windows" cz) +) :: +;; Builds min for Windows. ( - build-guide - build-site -) %docs + symbol windows-lite + (==>) + ("" "lite" "windows" cz) +) :: +;; Builds litemin for Windows. ( - build-vim -) %vim -+build-tasks + symbol windows-mini + (==>) + ("" "" "windows-mini" cz) +) :: +;; Builds minimin for Windows.
M
tasks/clean.min
→
tasks/clean.min
@@ -1,9 +1,15 @@
#!/usr/bin/env min -{} +#| Tasks |# + ( - "Cleaning up build files" notice - . ls ("(\.(htm|zip|exe)|[\/\\]min)$" match) filter =files - files 'rm foreach -) %default -+clean-tasks + symbol default + (==>) + ( + "Cleaning up build files" notice! + . ls ("(\.(htm|zip|exe)|[\/\\]min)$" match) filter =files + files 'rm foreach + "Done." notice! + ) +) :: +;; Deletes min build files
M
tasks/github.min
→
tasks/github.min
@@ -1,7 +1,6 @@
#!/usr/bin/env min -"_helpers" load -'helpers import +"_helpers" require :helpers 'helpers import "next-release.md" fread escape :release-body "tasks/templates/draft-release.json" fread :draft-release-template@@ -16,106 +15,144 @@ "token $#" (token) =% %Authorization
:headers ( - response to-json "response.json" fwrite - response /status :status - (status 300 >) ( - response /body from-json :body - body /message :message - status string @status - "Error $#: $#" (status message) =% error status int exit - ) when -) :handle-errors + symbol handle-errors + (dict :response ==>) + ( + response to-json "response.json" fwrite + response /status :status + (status 300 >) ( + response /body from-json :body + body /message :message + status string @status + "Error $#: $#" (status message) =% error status int exit + ) when + ) +) :: +;; Handles HTTP errors. + ( - :data - data /endpoint :endpoint - "api" :subdomain - (data ?subdomain) (data /subdomain @subdomain) when - "https://$#.github.com/repos/h3rald/min$#" (subdomain endpoint) =% :url - {} - url %url - data /method %method - (data ?headers) - (data /headers %headers) - (headers %headers) - if - (data ?body) (data /body %body) when - request :response - response /status :status - response /body :body - handle-errors - (body length 0 >) (body from-json) ({}) if -) :gh-req + symbol gh-req + (dict :data ==> dict :result) + ( + data /endpoint :endpoint + "api" :subdomain + (data ?subdomain) (data /subdomain @subdomain) when + "https://$#.github.com/repos/h3rald/min$#" (subdomain endpoint) =% :url + {} + url %url + data /method %method + (data ?headers) + (data /headers %headers) + (headers %headers) + if + (data ?body) (data /body %body) when + request :response + response /status :status + response /body :body + response handle-errors + (body length 0 >) (body from-json) ({}) if @result + ) +) :: +;; Execute a request using the Github API. ( - :data - data /id :id - {} - "/releases/$#/assets" (id) =% %endpoint - "GET" %method - gh-req -) :get-assets + symbol get-assets + (dict :data ==> dict :result) + ( + data /id :id + {} + "/releases/$#/assets" (id) =% %endpoint + "GET" %method + gh-req @result + ) +) :: +;; Retrieve the assets from an existing Github release. ( - config get-assets =assets - config /id :id - assets (/id) map =assets-ids - assets-ids ( - :asset - {} - "/releases/assets/$#" (asset) =% %endpoint - "DELETE" %method - gh-req - ) foreach -) :delete-assets + symbol delete-assets + (==>) + ( + config get-assets =assets + config /id :id + assets (/id) map =assets-ids + assets-ids ( + :asset + {} + "/releases/assets/$#" (asset) =% %endpoint + "DELETE" %method + gh-req pop + ) foreach + ) +) :: +;; Delete all assets from an existing Github release. + +#| Tasks |# -; Module symbols -{} ( - {} + symbol draft + (==>) + ( + {} "/releases" %endpoint "POST" %method draft-release-body %body - gh-req /id string :id - ; Save Release ID to min.yml - config id %id to-yaml "min.yml" fwrite - "Draft release v$# ($#) created successfully" (min-version id) =% notice -) %draft + gh-req /id string :id + ; Save Release ID to min.yml + config id %id to-yaml "min.yml" fwrite + "Draft release v$# ($#) created successfully" (min-version id) =% notice! + ) +) :: +;; Creates a new draft release on Github. + ( - config /id :id + symbol update + (==>) + ( + config /id :id {} "/releases/$#" (id) =% %endpoint "PATCH" %method draft-release-body %body gh-req /id string :id - "Draft release v$# ($#) updated successfully" (min-version id) =% notice -) %update -( - config get-assets =assets - assets size :total - "are" :verb - (total 1 ==) ("is" @verb) when - "There $# $# assets in release v$#" (verb total min-version) =% notice - assets (/name () cons "- $#" swap % notice) foreach - assets -) %assets + "Draft release v$# ($#) updated successfully" (min-version id) =% notice! + ) +) :: +;; Updates the text of the current draft Github release. + ( - config /id :id - config delete-assets - . ls ("\.zip$" match) filter + symbol assets + (==>) ( - filename :file - "Uploading: $#" (file) =% notice - file fread :body - headers "application/zip" %Content-Type :asset-headers - {} - "/releases/$#/assets?name=$#" (id file) =% %endpoint - asset-headers %headers - "uploads" %subdomain - "POST" %method - body %body - gh-req - ) foreach -) %upload -+github-tasks - + config get-assets =assets + assets size :total + "are" :verb + (total 1 ==) ("is" @verb) when + "There $# $# assets in release v$#" (verb total min-version) =% notice! + assets (/name () cons "- $#" swap % notice!) foreach + ) +) :: +;; Retrieve a list of all the assets of the current draft Github release. +( + symbol upload + (==>) + ( + config /id :id + config delete-assets + . ls ("\.zip$" match) filter + ( + filename :file + "Uploading: $#" (file) =% notice! + file fread :body + headers "application/zip" %Content-Type :asset-headers + {} + "/releases/$#/assets?name=$#" (id file) =% %endpoint + asset-headers %headers + "uploads" %subdomain + "POST" %method + body %body + gh-req pop + ) foreach + ) +) :: +;; Uploads all assets to the current draft Github release, deleting any existing asset.
M
tasks/h3rald.min
→
tasks/h3rald.min
@@ -1,7 +1,6 @@
#!/usr/bin/env min -"_helpers" load -'helpers import +"_helpers" require :helpers 'helpers import config /version :min-version "Min_DeveloperGuide.htm" :guide-file@@ -10,23 +9,31 @@ "../h3rald/contents/min.md" :h3rald-min-md
"version:\\s+\\d+\\.\\d+\\.\\d+" :min-v-reg "version: $#" (min-version) =% :min-v-rep -; Module symbols -{} ( - "Updating min Developer Guide and project on H3RALD.com..." notice - guide-file h3rald-guide cp - h3rald-min-md fread "s/$#/$#/m" (min-v-reg min-v-rep) =% regex 0 get :updated-contents - updated-contents h3rald-min-md fwrite - "Done." notice -) %update + symbol update + (==>) + ( + "Updating min Developer Guide and project on H3RALD.com..." notice! + guide-file h3rald-guide cp + h3rald-min-md fread "s/$#/$#/m" (min-v-reg min-v-rep) =% regex 0 get :updated-contents + updated-contents h3rald-min-md fwrite + "Done." notice! + ) +) :: +;; Updates the min Developer Guide and project page on H3RALD.com + ( - "git" required - "hastysite" required - "Pulling content and rebuilding H3RALD.com web site..." notice - ; Assuming min and h3rald are siblings - .. cd "h3rald" cd - "git pull" ! - "hastysite build" ! - .. cd "min" cd -) %build -+h3rald-tasks + symbol build + (==>) + ( + "git" required + "hastysite" required + "Pulling content and rebuilding H3RALD.com web site..." notice! + ; Assuming min and h3rald are siblings + .. cd "h3rald" cd + "git pull" ! + "hastysite build" ! + .. cd "min" cd + ) +) :: +;; Builds H3RALD.com web site
M
tasks/release.min
→
tasks/release.min
@@ -1,29 +1,27 @@
#!/usr/bin/env min -"build" load -"github" load -"ssh" load +"build" require :build +"github" require :github -; Module symbols -{} -( - build-tasks ^guide - build-tasks ^site - build-tasks ^vim - build-tasks ^windows - build-tasks ^windows-lite - build-tasks ^windows-mini - build-tasks ^linux - build-tasks ^linux-lite - build-tasks ^linux-mini - build-tasks ^macosx - build-tasks ^macosx-lite - build-tasks ^macosx-mini - github-tasks ^update - github-tasks ^upload -) %default +#| Tasks |# ( - ssh-tasks ^build - ssh-tasks ^h3rald -) %sites -+release-tasks + symbol default + (==>) + ( + *build/guide + *build/site + *build/vim + *build/windows + *build/windows-lite + *build/windows-mini + *build/linux + *build/linux-lite + *build/linux-mini + *build/macosx + *build/macosx-lite + *build/macosx-mini + *github/update + *github/upload + ) +) :: +;; Builds min executables and updates the current draft Github release.
D
tasks/ssh.min
@@ -1,40 +0,0 @@
-#!/usr/bin/env min - -"_helpers" load -'helpers import - -env /ssh-host :host -env /ssh-min-dir :min-dir -"cd " min-dir suffix :min-cd - -( - "export PATH=~/bin:~/.nimble/bin:$PATH" - min-cd -) :init - -; Module symbols -{} -( - "ssh" required - "ssh - h3rald ($#)" (host) =% notice - ( - init - "min run h3rald:update" - "min run h3rald:build" - ) => "; " join :cmds - "ssh $# \"$#\"" (host cmds) =% !! -) %h3rald -( - "ssh" required - "ssh - build ($#)" (host) =% notice - ( - init - "git pull" - "nifty upgrade" - "min run build" - "min run build:guide" - "min run build:site" - ) => "; " join :cmds - "ssh $# \"$#\"" (host cmds) =% !! -) %build -+ssh-tasks
M
tasks/version.min
→
tasks/version.min
@@ -5,44 +5,76 @@ "site/settings.json" :json-site-cfg
yaml-cfg fread from-yaml :config config /version :old-version + ( - :new-version - config new-version %version @config - config to-yaml yaml-cfg fwrite -) :update-yaml-config + symbol update-yaml-config + ('sym :new-version ==>) + ( + config new-version %version @config + config to-yaml yaml-cfg fwrite + ) +) :: +;; Sets the version in the min.yml file to new-version. + ( - :new-version - json-site-cfg fread from-json :site-config - site-config new-version %version @site-config - site-config to-json json-site-cfg fwrite -) :update-site-config + symbol update-site-config + ('sym :new-version ==>) + ( + json-site-cfg fread from-json :site-config + site-config new-version %version @site-config + site-config to-json json-site-cfg fwrite + ) +) :: +;; Updates the version of the web site to new-version. + +#| Tasks |# -; Module tasks -{} ( - "" :new-version - false :valid-semver - (valid-semver not) + symbol set + (==>) ( - "New version" ask @new-version - new-version semver? @valid-semver - ) while - new-version update-yaml-config - new-version update-site-config -) %set + "" :new-version + false :valid-semver + (valid-semver not) + ( + "New version" ask @new-version + new-version semver? @valid-semver + ) while + new-version update-yaml-config + new-version update-site-config + ) +) :: +;; Asks and sets the new min version where appropriate. + ( - old-version semver-inc-major :new-version - new-version update-yaml-config - new-version update-site-config -) %major + symbol major + (==>) + ( + old-version semver-inc-major :new-version + new-version update-yaml-config + new-version update-site-config + ) +) :: +;; Increments the min major version. + ( - old-version semver-inc-minor :new-version - new-version update-yaml-config - new-version update-site-config -) %minor + symbol minor + (==>) + ( + old-version semver-inc-minor :new-version + new-version update-yaml-config + new-version update-site-config + ) +) :: +;; Increments the min minor version. + ( - old-version semver-inc-patch :new-version - new-version update-yaml-config - new-version update-site-config -) %patch -+version-tasks+ symbol patch + (==>) + ( + old-version semver-inc-patch :new-version + new-version update-yaml-config + new-version update-site-config + ) +) :: +;; Increments the min patch version.