From e1e3859535d5739a0a7187602547303bd7004cf3 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 28 Sep 2021 15:07:30 +0200 Subject: [PATCH 1/4] try-files and not-found-page --- README.md | 10 ++++++++++ action.yml | 39 +++++++++++++++++++++++---------------- index.js | 29 ++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index cf97e58..ae04a20 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,16 @@ This action requires the upload directory to be already available so you will ne Find out more about github token from [documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow). +### `try-files` + +Default value: `index.html` + +Define a list of space separated files that portal should try to serve in if uri points to a directory, ie `index.html /index.html`. + +### `not-found-page` + +Define a path to a file that will replace the default 404 Not Found error page, ie `404.html`. + ### `registry-seed` You can provide a seed (keep it secret, keep it safe) and this action will set corresponding skynet registry entry value to the deployed resolver skylink. diff --git a/action.yml b/action.yml index 9131afc..7f45933 100644 --- a/action.yml +++ b/action.yml @@ -1,35 +1,42 @@ -name: 'Skynet Deploy' -description: 'Deploy your static webapp to Skynet' +name: "Skynet Deploy" +description: "Deploy your static webapp to Skynet" branding: - icon: 'cloud' - color: 'green' + icon: "cloud" + color: "green" inputs: upload-dir: - description: 'Directory to upload' + description: "Directory to upload" required: true github-token: - description: 'Github token used for including the skylink url in pull request' + description: "Github token used for including the skylink url in pull request" required: true + try-files: + description: "Define a list of space separated files that portal should try to serve in if uri points to a directory" + required: false + default: "index.html" + not-found-page: + description: "Define a path to a file that will replace the default 404 Not Found error page" + required: false registry-seed: - description: 'Seed that generates registry private key (optional, only if you want to update the registry entry with skylink)' + description: "Seed that generates registry private key (optional, only if you want to update the registry entry with skylink)" required: false registry-datakey: - description: 'Registry datakey to use when updating the registry entry' + description: "Registry datakey to use when updating the registry entry" required: true - default: 'skylink.txt' + default: "skylink.txt" portal-url: - description: 'Skynet portal api url' + description: "Skynet portal api url" required: true - default: 'https://siasky.net' + default: "https://siasky.net" outputs: skylink: - description: 'Uploaded resource skylink' + description: "Uploaded resource skylink" skylink-url: - description: 'Uploaded resource skylink url' + description: "Uploaded resource skylink url" resolver-skylink: - description: 'Resolver skylink pointing to uploaded resource' + description: "Resolver skylink pointing to uploaded resource" resolver-skylink-url: - description: 'Resolver skylink url (as a subdomain)' + description: "Resolver skylink url (as a subdomain)" runs: - using: 'node12' + using: "node12" main: index.js diff --git a/index.js b/index.js index c74d974..7bebab8 100644 --- a/index.js +++ b/index.js @@ -15,13 +15,40 @@ function outputAxiosErrorMessage(error) { } } +function prepareUploadOptions() { + const options = {}; + + if (core.getInput("try-files")) { + try { + options.tryfiles = encodeURIComponent( + JSON.stringify(core.getInput("try-files").split(/\s+/)) + ); + } catch (error) { + throw new Error(`tryfiles input parsing error: ${error.message}`); + } + } + + if (core.getInput("not-found-page")) { + try { + options.errorpages = encodeURIComponent( + JSON.stringify({ 404: core.getInput("not-found-page") }) + ); + } catch (error) { + throw new Error(`not-found-page input parsing error: ${error.message}`); + } + } + + return options; +} + (async () => { try { // upload to skynet const nodeClient = new NodeSkynetClient(core.getInput("portal-url")); const skynetClient = new SkynetClient(core.getInput("portal-url")); const skylink = await nodeClient.uploadDirectory( - core.getInput("upload-dir") + core.getInput("upload-dir"), + prepareUploadOptions() ); // generate base32 skylink url from base64 skylink From f0c034f557fbd7a35893df12fc5c4aa3063e4772 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 28 Sep 2021 15:18:28 +0200 Subject: [PATCH 2/4] comment on transforming the inputs --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 7bebab8..f011bfe 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,8 @@ function prepareUploadOptions() { if (core.getInput("try-files")) { try { + // transform try-files input which is space separated list of file paths + // into an url encoded stringified array of those paths options.tryfiles = encodeURIComponent( JSON.stringify(core.getInput("try-files").split(/\s+/)) ); @@ -29,6 +31,9 @@ function prepareUploadOptions() { } if (core.getInput("not-found-page")) { + // transform not-found-page input which is a single file path into + // and url encoded stringified object with a 404 key and its value + // being the specified path try { options.errorpages = encodeURIComponent( JSON.stringify({ 404: core.getInput("not-found-page") }) From 51d9b00905df2cf9e5a0db4b3b78ad131fa82e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Tue, 28 Sep 2021 17:25:38 +0200 Subject: [PATCH 3/4] comment copy update Co-authored-by: Marcin S. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f011bfe..996ba2d 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,7 @@ function prepareUploadOptions() { if (core.getInput("not-found-page")) { // transform not-found-page input which is a single file path into - // and url encoded stringified object with a 404 key and its value + // a url encoded stringified object with a 404 key and its value // being the specified path try { options.errorpages = encodeURIComponent( From 15aed71bc42102cf30048f6af45104b2b0203cd1 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 28 Sep 2021 17:31:08 +0200 Subject: [PATCH 4/4] update upload options format after skynet-nodejs upgrade --- index.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 69342b3..94222fe 100644 --- a/index.js +++ b/index.js @@ -19,28 +19,15 @@ function prepareUploadOptions() { const options = {}; if (core.getInput("try-files")) { - try { - // transform try-files input which is space separated list of file paths - // into an url encoded stringified array of those paths - options.tryfiles = encodeURIComponent( - JSON.stringify(core.getInput("try-files").split(/\s+/)) - ); - } catch (error) { - throw new Error(`tryfiles input parsing error: ${error.message}`); - } + // transform try-files input which is space separated list + // of file paths into an array of those paths + options.tryFiles = core.getInput("try-files").split(/\s+/); } if (core.getInput("not-found-page")) { // transform not-found-page input which is a single file path into - // a url encoded stringified object with a 404 key and its value - // being the specified path - try { - options.errorpages = encodeURIComponent( - JSON.stringify({ 404: core.getInput("not-found-page") }) - ); - } catch (error) { - throw new Error(`not-found-page input parsing error: ${error.message}`); - } + // an object with a 404 key and its value being the specified path + options.errorPages = { 404: core.getInput("not-found-page") }; } return options;