From a8bdd918c8a8f322b057c2d2545e0ae16046ce76 Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 22:39:28 +0900 Subject: [PATCH 01/16] ci: support multi languages --- preview/action.yaml | 9 +++++---- preview/scripts/edit-description.js | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/preview/action.yaml b/preview/action.yaml index 279a10f..410bec5 100644 --- a/preview/action.yaml +++ b/preview/action.yaml @@ -10,7 +10,7 @@ inputs: project-slug: description: "Project's slug on Read the Docs" required: true - project-language: + project-languages: description: "Project's language on Read the Docs" default: "en" required: false @@ -18,7 +18,8 @@ inputs: description: "Template message to use for the PR body" default: | ---- - :books: Documentation preview :books:: {docs-pr-index-url} + :books: Documentation preview :books:: + {docs-pr-index-url} required: false platform: description: "Read the Docs Community or Read the Docs for Business (community or business)" @@ -26,7 +27,7 @@ inputs: required: false single-version: description: "Site is a single version project, so link to the top level." - default: 'false' + default: 'false' required: false runs: @@ -43,7 +44,7 @@ runs: script: | const inputs = { "project-slug": "${{ inputs.project-slug }}", - "project-language": "${{ inputs.project-language }}", + "project-languages": "${{ inputs.project-languages }}", "message-template": `${{ inputs.message-template }}`, "platform": "${{ inputs.platform }}", "single-version": "${{ inputs.single-version }}", diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index b4b739e..c5d54d5 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -1,7 +1,7 @@ module.exports = async ({inputs, github, context}) => { const PR_NUMBER = context.issue.number; const RTD_PROJECT_SLUG = inputs["project-slug"]; - const RTD_PROJECT_LANGUAGE = inputs["project-language"]; + const RTD_PROJECT_LANGUAGES = inputs["project-languages"].split(","); const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"]; @@ -15,12 +15,20 @@ module.exports = async ({inputs, github, context}) => { } else { // Log warning here? } - const RTD_PROJECT_DOMAIN = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/`; - if (RTD_SINGLE_VERSION === "true") { - RTD_URL = RTD_PROJECT_DOMAIN; - } else { - RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`; + let RTD_URLS = []; + + for (let i = 0; i < RTD_PROJECT_LANGUAGES.length; i++) { + const RTD_PROJECT_LANGUAGE = RTD_PROJECT_LANGUAGES[i]; + const RTD_PROJECT_DOMAIN = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/`; + + if (RTD_SINGLE_VERSION === "true") { + RTD_URL = RTD_PROJECT_DOMAIN; + } else { + RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`; + } + + RTD_URLS.push(RTD_URL); } const MESSAGE_SEPARATOR_START = `\r\n\r\n\r\n`; @@ -33,7 +41,10 @@ module.exports = async ({inputs, github, context}) => { pull_number: context.issue.number, }); - const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URL); + + const body_message = RTD_URLS.forEach((url) => { + return MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", url); + }).join("\r\n"); let body = ""; if (pull.body) { From 6379747e49e88dd6c138d459d94355973bd77b30 Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 22:55:31 +0900 Subject: [PATCH 02/16] Update edit-description.js --- preview/scripts/edit-description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index c5d54d5..dbe629f 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -42,7 +42,7 @@ module.exports = async ({inputs, github, context}) => { }); - const body_message = RTD_URLS.forEach((url) => { + const body_message = RTD_URLS.map((url) => { return MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", url); }).join("\r\n"); From 5de90223815c76b922347a773f4fd6e7d7d74da2 Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 23:00:13 +0900 Subject: [PATCH 03/16] Update action.yaml --- preview/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/preview/action.yaml b/preview/action.yaml index 410bec5..11dda6a 100644 --- a/preview/action.yaml +++ b/preview/action.yaml @@ -35,8 +35,8 @@ runs: steps: - uses: actions/checkout@v3 with: - repository: "readthedocs/actions" - ref: "v1" + repository: "Yaminyam/actions" + ref: "main" - name: "Comment on Pull Request with Read the Docs' preview links" uses: actions/github-script@v6 From 4e1d177940564474d0fba259a5712e902eaee84d Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 23:10:06 +0900 Subject: [PATCH 04/16] Update deit-description.js --- preview/scripts/edit-description.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index dbe629f..7ba37a9 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -42,9 +42,7 @@ module.exports = async ({inputs, github, context}) => { }); - const body_message = RTD_URLS.map((url) => { - return MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", url); - }).join("\r\n"); + const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URLS.join("\r\n")); let body = ""; if (pull.body) { From 730616bede80aa683658fc3554465e5efc47b31f Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 23:38:49 +0900 Subject: [PATCH 05/16] Maintain existing compatibility of arguments --- preview/action.yaml | 4 ++-- preview/scripts/edit-description.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/preview/action.yaml b/preview/action.yaml index 11dda6a..c703cc7 100644 --- a/preview/action.yaml +++ b/preview/action.yaml @@ -10,7 +10,7 @@ inputs: project-slug: description: "Project's slug on Read the Docs" required: true - project-languages: + project-language: description: "Project's language on Read the Docs" default: "en" required: false @@ -44,7 +44,7 @@ runs: script: | const inputs = { "project-slug": "${{ inputs.project-slug }}", - "project-languages": "${{ inputs.project-languages }}", + "project-language": "${{ inputs.project-language }}", "message-template": `${{ inputs.message-template }}`, "platform": "${{ inputs.platform }}", "single-version": "${{ inputs.single-version }}", diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 7ba37a9..cf44062 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -1,7 +1,7 @@ module.exports = async ({inputs, github, context}) => { const PR_NUMBER = context.issue.number; const RTD_PROJECT_SLUG = inputs["project-slug"]; - const RTD_PROJECT_LANGUAGES = inputs["project-languages"].split(","); + const RTD_PROJECT_LANGUAGES = inputs["project-language"].split(","); const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"]; From 43de417b2700d2babdb03129f4e60b2e80aa59e6 Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 23:50:00 +0900 Subject: [PATCH 06/16] Improving readability through bullets --- preview/action.yaml | 3 +-- preview/scripts/edit-description.js | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/preview/action.yaml b/preview/action.yaml index c703cc7..a20746d 100644 --- a/preview/action.yaml +++ b/preview/action.yaml @@ -18,8 +18,7 @@ inputs: description: "Template message to use for the PR body" default: | ---- - :books: Documentation preview :books:: - {docs-pr-index-url} + :books: Documentation preview :books:: {docs-pr-index-url} required: false platform: description: "Read the Docs Community or Read the Docs for Business (community or business)" diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index cf44062..869920e 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -26,6 +26,9 @@ module.exports = async ({inputs, github, context}) => { RTD_URL = RTD_PROJECT_DOMAIN; } else { RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`; + if (RTD_PROJECT_LANGUAGE > 1) { + RTD_URL = '\n* ' + RTD_URL + } } RTD_URLS.push(RTD_URL); From fb148787c8a46d782da4d8fe662b3002690e8c4b Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 23:56:47 +0900 Subject: [PATCH 07/16] fix urls join --- preview/scripts/edit-description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 869920e..09965a2 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -45,7 +45,7 @@ module.exports = async ({inputs, github, context}) => { }); - const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URLS.join("\r\n")); + const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URLS.join()); let body = ""; if (pull.body) { From 653009b4d455225cad4ce6ce2703fbafbddd27c3 Mon Sep 17 00:00:00 2001 From: siontama Date: Tue, 7 Mar 2023 23:59:34 +0900 Subject: [PATCH 08/16] Update edit-description.js --- preview/scripts/edit-description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 09965a2..22ee88f 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -27,7 +27,7 @@ module.exports = async ({inputs, github, context}) => { } else { RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`; if (RTD_PROJECT_LANGUAGE > 1) { - RTD_URL = '\n* ' + RTD_URL + RTD_URL = "\r\n* " + RTD_URL } } From e917711b21ee185dd90230fb99861eaaddee2aff Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 00:00:44 +0900 Subject: [PATCH 09/16] Update edit-description.js --- preview/scripts/edit-description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 22ee88f..70b8161 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -26,7 +26,7 @@ module.exports = async ({inputs, github, context}) => { RTD_URL = RTD_PROJECT_DOMAIN; } else { RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`; - if (RTD_PROJECT_LANGUAGE > 1) { + if (RTD_PROJECT_LANGUAGES.length > 1) { RTD_URL = "\r\n* " + RTD_URL } } From fb1fb6d6d5507ab3e1161ef9f11989600a4a940c Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 10:27:07 +0900 Subject: [PATCH 10/16] Update edit-description.js --- preview/scripts/edit-description.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 70b8161..62a05ea 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -18,22 +18,23 @@ module.exports = async ({inputs, github, context}) => { let RTD_URLS = []; - for (let i = 0; i < RTD_PROJECT_LANGUAGES.length; i++) { - const RTD_PROJECT_LANGUAGE = RTD_PROJECT_LANGUAGES[i]; - const RTD_PROJECT_DOMAIN = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/`; + if (RTD_SINGLE_VERSION === "true") { + RTD_URL = RTD_PROJECT_DOMAIN; + RTD_URLS.push(RTD_URL); + } else { + for (let i = 0; i < RTD_PROJECT_LANGUAGES.length; i++) { + const RTD_PROJECT_LANGUAGE = RTD_PROJECT_LANGUAGES[i]; + const RTD_PROJECT_DOMAIN = `https://${RTD_PROJECT_SLUG}--${PR_NUMBER}.${RTD_DOMAIN}/`; - if (RTD_SINGLE_VERSION === "true") { - RTD_URL = RTD_PROJECT_DOMAIN; - } else { RTD_URL = RTD_PROJECT_DOMAIN + `${RTD_PROJECT_LANGUAGE}/${PR_NUMBER}/`; if (RTD_PROJECT_LANGUAGES.length > 1) { - RTD_URL = "\r\n* " + RTD_URL + RTD_URL = "\r\n* " + RTD_URL; } + RTD_URLS.push(RTD_URL); } - - RTD_URLS.push(RTD_URL); } + const MESSAGE_SEPARATOR_START = `\r\n\r\n\r\n`; const MESSAGE_SEPARATOR_END = `\r\n`; const MESSAGE_TEMPLATE = inputs["message-template"]; @@ -45,7 +46,7 @@ module.exports = async ({inputs, github, context}) => { }); - const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URLS.join()); + const body_message = MESSAGE_TEMPLATE.replace("{docs-pr-index-url}", RTD_URLS.join('')); let body = ""; if (pull.body) { From b8c07162f22e85764946bf1beb01fb5aa8e9b2f0 Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 12:40:35 +0900 Subject: [PATCH 11/16] multi argument test --- preview/scripts/edit-description.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 62a05ea..d69f580 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -5,6 +5,8 @@ module.exports = async ({inputs, github, context}) => { const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"]; + github.core.debug(`Language: ${inputs["project-language"]}`); + let RTD_DOMAIN = ""; let RTD_URL = ""; From 31d862f6e5186369850549ed318cef28915d77ac Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 12:44:21 +0900 Subject: [PATCH 12/16] multi argument test --- preview/scripts/edit-description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index d69f580..8b7dc74 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -5,7 +5,7 @@ module.exports = async ({inputs, github, context}) => { const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"]; - github.core.debug(`Language: ${inputs["project-language"]}`); + github.core.info(`Language: ${inputs["project-language"]}`); let RTD_DOMAIN = ""; let RTD_URL = ""; From c50097f2b12a68096746d14bcf17c002908f8b3c Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 13:15:43 +0900 Subject: [PATCH 13/16] multi argument test --- preview/action.yaml | 1 + preview/scripts/edit-description.js | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/preview/action.yaml b/preview/action.yaml index a20746d..71ebf14 100644 --- a/preview/action.yaml +++ b/preview/action.yaml @@ -48,5 +48,6 @@ runs: "platform": "${{ inputs.platform }}", "single-version": "${{ inputs.single-version }}", } + console.log("Inputs: ", inputs); const script = require("./preview/scripts/edit-description.js"); await script({inputs, github, context}); diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 8b7dc74..62a05ea 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -5,8 +5,6 @@ module.exports = async ({inputs, github, context}) => { const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"]; - github.core.info(`Language: ${inputs["project-language"]}`); - let RTD_DOMAIN = ""; let RTD_URL = ""; From 478e23e9b7ef3ba813e5e399cdbe2fa17ac4db03 Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 13:39:27 +0900 Subject: [PATCH 14/16] multi argument test --- preview/scripts/edit-description.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 62a05ea..ae83663 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -5,6 +5,8 @@ module.exports = async ({inputs, github, context}) => { const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"]; + github.log.debug(`Language: ${inputs["project-language"]}`); + let RTD_DOMAIN = ""; let RTD_URL = ""; From 962f9e650956075208ffaa17bf629a1dd3afe3a1 Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 13:48:11 +0900 Subject: [PATCH 15/16] multi argument test --- preview/scripts/edit-description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index ae83663..301f20e 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -1,7 +1,7 @@ module.exports = async ({inputs, github, context}) => { const PR_NUMBER = context.issue.number; const RTD_PROJECT_SLUG = inputs["project-slug"]; - const RTD_PROJECT_LANGUAGES = inputs["project-language"].split(","); + const RTD_PROJECT_LANGUAGES = inputs["project-language"].split("\n"); const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"]; From 113a39687e519bf2fc6b3c5bec9cef0b31beaa77 Mon Sep 17 00:00:00 2001 From: siontama Date: Wed, 8 Mar 2023 13:49:43 +0900 Subject: [PATCH 16/16] multi argument test --- preview/scripts/edit-description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preview/scripts/edit-description.js b/preview/scripts/edit-description.js index 301f20e..ae83663 100644 --- a/preview/scripts/edit-description.js +++ b/preview/scripts/edit-description.js @@ -1,7 +1,7 @@ module.exports = async ({inputs, github, context}) => { const PR_NUMBER = context.issue.number; const RTD_PROJECT_SLUG = inputs["project-slug"]; - const RTD_PROJECT_LANGUAGES = inputs["project-language"].split("\n"); + const RTD_PROJECT_LANGUAGES = inputs["project-language"].split(","); const RTD_PLATFORM = inputs["platform"]; const RTD_SINGLE_VERSION = inputs["single-version"];