From b17a14eabd165efd55727d6e9bb39581b008b749 Mon Sep 17 00:00:00 2001 From: Vicente Canales Date: Wed, 24 Apr 2024 11:00:20 -0400 Subject: [PATCH 1/5] Playground Previews: use correct github proxy URL Changing where we make the call to download the theme, to make sure that we're using stable code. Additionally, add child theme handling. Discussion around this: - https://github.com/Automattic/themes/pull/7719 - https://github.com/stoph/github-proxy/pull/3 --- .github/scripts/create-preview-links.js | 42 +++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/.github/scripts/create-preview-links.js b/.github/scripts/create-preview-links.js index 807373bb..338d99ae 100644 --- a/.github/scripts/create-preview-links.js +++ b/.github/scripts/create-preview-links.js @@ -19,7 +19,7 @@ function createBlueprint(themeSlug, branch) { step: 'installTheme', themeZipFile: { resource: 'url', - url: `https://github-proxy.com/partial/Wordpress/community-themes/${themeSlug}?branch=${branch}`, + url: `https://github-proxy.com/proxy.php?action=partial&repo=Wordpress/community-themes&directory=${themeSlug}&branch=${branch}`, }, }, { @@ -44,6 +44,27 @@ function getThemeName(themeSlug) { return themeName; } +/* + * This function reads the `style.css` file of a theme and returns the name of the parent theme. + * If the theme is not a child theme, it returns an empty string. + * + * @param {string} themeSlug - The slug of the theme to get the parent theme name of. + * @returns {string} - The name of the parent theme as defined in the `style.css` file. + */ +function getParentThemeName(themeSlug) { + const styleCss = fs.readFileSync(`${themeSlug}/style.css`, 'utf8'); + const parentTheme = styleCss.match(/Template:(.*)/i); + const isChildTheme = parentTheme && '' !== parentTheme[1].trim(); + + if (!isChildTheme) { + return ''; + } + + return parentTheme && '' !== parentTheme[1].trim() + ? parentTheme[1].trim() + : ''; +} + /* * This function creates a comment on a PR with preview links for the changed themes. * It is used by `preview-theme` workflow. @@ -56,25 +77,40 @@ async function createPreviewLinksComment(github, context, changedThemeSlugs) { const changedThemes = changedThemeSlugs.split(' '); const previewLinks = changedThemes .map((themeSlug) => { + const parentThemeName = getParentThemeName(themeSlug); + const note = parentThemeName + ? ` (child theme of **${parentThemeName}**)` + : ''; + return `- [Preview changes for **${getThemeName( themeSlug )}**](https://playground.wordpress.net/#${createBlueprint( themeSlug, context.payload.pull_request.head.ref - )})`; + )})${note}`; }) .join('\n'); + + const includesChildThemes = changedThemes.some( + (themeSlug) => '' !== getParentThemeName(themeSlug) + ); + const comment = ` I've detected changes to the following themes in this PR: ${changedThemes .map((themeSlug) => getThemeName(themeSlug)) .join(', ')}. You can preview these changes by following the links below: + ${previewLinks} I will update this comment with the latest preview links as you push more changes to this PR. - **⚠️ Note:** The preview sites are created using [WordPress Playground](https://wordpress.org/playground/). You can add content, edit settings, and test the themes as you would on a real site, but please note that changes are not saved between sessions. +${ + includesChildThemes + ? '\n**⚠️ Note:** Child themes are dependent on their parent themes. You will have to install the parent theme as well for the preview to work correctly.' + : '' +} `; const repoData = { From 6c668b5b82689f6a537c766165e320e9908e4f7e Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 24 Apr 2024 17:08:15 +0200 Subject: [PATCH 2/5] change on a child theme --- atlas/patterns/hidden-404.php | 1 + 1 file changed, 1 insertion(+) diff --git a/atlas/patterns/hidden-404.php b/atlas/patterns/hidden-404.php index 96beb939..3a0bd4c9 100644 --- a/atlas/patterns/hidden-404.php +++ b/atlas/patterns/hidden-404.php @@ -4,6 +4,7 @@ * Slug: atlas/hidden-404 * Inserter: no */ +//test ?> From 5dca499affcdf843c1d648293ee7b6aec39ea6c6 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 24 Apr 2024 17:11:24 +0200 Subject: [PATCH 3/5] pushed another test --- blue-note/patterns/black-image-with-text.php | 1 + 1 file changed, 1 insertion(+) diff --git a/blue-note/patterns/black-image-with-text.php b/blue-note/patterns/black-image-with-text.php index f3991e4e..fc71a9e8 100644 --- a/blue-note/patterns/black-image-with-text.php +++ b/blue-note/patterns/black-image-with-text.php @@ -5,6 +5,7 @@ * Categories: text * Block Types: core/quote */ +//another test ?>
From 305addbb4559107874354e5922ae05b50fb5ced8 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Wed, 24 Apr 2024 17:17:49 +0200 Subject: [PATCH 4/5] remove tests --- atlas/patterns/hidden-404.php | 1 - blue-note/patterns/black-image-with-text.php | 1 - 2 files changed, 2 deletions(-) diff --git a/atlas/patterns/hidden-404.php b/atlas/patterns/hidden-404.php index 3a0bd4c9..96beb939 100644 --- a/atlas/patterns/hidden-404.php +++ b/atlas/patterns/hidden-404.php @@ -4,7 +4,6 @@ * Slug: atlas/hidden-404 * Inserter: no */ -//test ?> diff --git a/blue-note/patterns/black-image-with-text.php b/blue-note/patterns/black-image-with-text.php index fc71a9e8..f3991e4e 100644 --- a/blue-note/patterns/black-image-with-text.php +++ b/blue-note/patterns/black-image-with-text.php @@ -5,7 +5,6 @@ * Categories: text * Block Types: core/quote */ -//another test ?>
From d6e0e3c06bed764c0dba7094c1ecf0751bca0837 Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 24 Apr 2024 17:18:44 +0200 Subject: [PATCH 5/5] Update .github/scripts/create-preview-links.js --- .github/scripts/create-preview-links.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/create-preview-links.js b/.github/scripts/create-preview-links.js index 338d99ae..c07ceeea 100644 --- a/.github/scripts/create-preview-links.js +++ b/.github/scripts/create-preview-links.js @@ -105,6 +105,7 @@ You can preview these changes by following the links below: ${previewLinks} I will update this comment with the latest preview links as you push more changes to this PR. + **⚠️ Note:** The preview sites are created using [WordPress Playground](https://wordpress.org/playground/). You can add content, edit settings, and test the themes as you would on a real site, but please note that changes are not saved between sessions. ${ includesChildThemes