From 0da5641054e5f365e7361c33e487bc3210f0408e Mon Sep 17 00:00:00 2001 From: siriwatknp Date: Thu, 17 Nov 2022 13:10:13 +0700 Subject: [PATCH 1/9] flip the logic --- docs/next.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/next.config.js b/docs/next.config.js index 116fe8d5211d1f..15f8f0f7c44494 100644 --- a/docs/next.config.js +++ b/docs/next.config.js @@ -170,7 +170,7 @@ module.exports = withDocsInfra({ const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`; pages2.forEach((page) => { - if (page.pathname.startsWith('/experiments') && process.env.DEPLOY_ENV !== 'production') { + if (page.pathname.startsWith('/experiments') && process.env.DEPLOY_ENV === 'production') { return; } // The blog is not translated From ed1a3fb0578982ed531a5803edfd87e26646624d Mon Sep 17 00:00:00 2001 From: siriwatknp Date: Fri, 18 Nov 2022 12:04:16 +0700 Subject: [PATCH 2/9] fix docs infra config --- docs/nextConfigDocsInfra.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/nextConfigDocsInfra.js b/docs/nextConfigDocsInfra.js index 6b8271940508ff..feafa0d56dfeb8 100644 --- a/docs/nextConfigDocsInfra.js +++ b/docs/nextConfigDocsInfra.js @@ -5,16 +5,30 @@ if (process.env.CONTEXT === 'deploy-preview') { DEPLOY_ENV = 'pull-request'; } +/** + * =================================================================================== + * Fun facts about the `process.env.CONTEXT`: + * + * - It is defined by Netlify environment variables (https://docs.netlify.com/configure-builds/environment-variables/#build-metadata) + * - `process.env.CONTEXT === 'production'` does not mean mui.com build, it is the site configuration. + * For example, the `master` branch of the Core team is considered a `production` build on Netlify based on https://app.netlify.com/sites/material-ui/settings/deploys#branches. + * + * - Each team has different site https://app.netlify.com/teams/mui/sites. Make sure to checkout the right site before making any changes. + * + */ if (process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-deploy') { DEPLOY_ENV = 'production'; } if ( - process.env.CONTEXT === 'branch-deploy' && - (process.env.HEAD === 'master' || process.env.HEAD === 'next') + process.env.HEAD === 'master' || + (process.env.CONTEXT === 'branch-deploy' && process.env.HEAD === 'next') ) { DEPLOY_ENV = 'staging'; } +/** + * ==================================================================================== + */ process.env.DEPLOY_ENV = DEPLOY_ENV; From 5944341c126e4197f22920a66010df5006c4cd01 Mon Sep 17 00:00:00 2001 From: siriwatknp Date: Fri, 18 Nov 2022 12:12:12 +0700 Subject: [PATCH 3/9] update logic --- docs/nextConfigDocsInfra.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/nextConfigDocsInfra.js b/docs/nextConfigDocsInfra.js index feafa0d56dfeb8..1e849f1db5914c 100644 --- a/docs/nextConfigDocsInfra.js +++ b/docs/nextConfigDocsInfra.js @@ -20,9 +20,14 @@ if (process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-depl DEPLOY_ENV = 'production'; } +if (process.env.CONTEXT === 'production' && process.env.HEAD === 'master') { + // For the Core team site, visit https://app.netlify.com/sites/material-ui/settings/deploys#branches for the config details. + DEPLOY_ENV = 'staging'; +} + if ( - process.env.HEAD === 'master' || - (process.env.CONTEXT === 'branch-deploy' && process.env.HEAD === 'next') + process.env.CONTEXT === 'branch-deploy' && + (process.env.HEAD === 'master' || process.env.HEAD === 'next') ) { DEPLOY_ENV = 'staging'; } From 6baa60c639ac0ab62429a78983fa7587f9e448cb Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 20 Nov 2022 16:33:02 +0100 Subject: [PATCH 4/9] simplification --- docs/nextConfigDocsInfra.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/docs/nextConfigDocsInfra.js b/docs/nextConfigDocsInfra.js index 1e849f1db5914c..296de19a2a0a5f 100644 --- a/docs/nextConfigDocsInfra.js +++ b/docs/nextConfigDocsInfra.js @@ -1,3 +1,14 @@ +/** + * See the docs of the Netlify environment variables: + * https://docs.netlify.com/configure-builds/environment-variables/#build-metadata. + * + * A few comments: + * - process.env.CONTEXT === 'production' means that the branch in Netlify was configured as production. + * For example, the `master` branch of the Core team is considered a `production` build on Netlify based + * on https://app.netlify.com/sites/material-ui/settings/deploys#branches. + * - Each team has different site https://app.netlify.com/teams/mui/sites. + * The following logic must be compatible with all of them. + */ let DEPLOY_ENV = 'development'; // Same as process.env.PULL_REQUEST_ID @@ -5,28 +16,13 @@ if (process.env.CONTEXT === 'deploy-preview') { DEPLOY_ENV = 'pull-request'; } -/** - * =================================================================================== - * Fun facts about the `process.env.CONTEXT`: - * - * - It is defined by Netlify environment variables (https://docs.netlify.com/configure-builds/environment-variables/#build-metadata) - * - `process.env.CONTEXT === 'production'` does not mean mui.com build, it is the site configuration. - * For example, the `master` branch of the Core team is considered a `production` build on Netlify based on https://app.netlify.com/sites/material-ui/settings/deploys#branches. - * - * - Each team has different site https://app.netlify.com/teams/mui/sites. Make sure to checkout the right site before making any changes. - * - */ if (process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-deploy') { DEPLOY_ENV = 'production'; } -if (process.env.CONTEXT === 'production' && process.env.HEAD === 'master') { - // For the Core team site, visit https://app.netlify.com/sites/material-ui/settings/deploys#branches for the config details. - DEPLOY_ENV = 'staging'; -} - +// The 'master' and 'next' branches are NEVER a production environment. We use these branches for staging. if ( - process.env.CONTEXT === 'branch-deploy' && + (process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-deploy') && (process.env.HEAD === 'master' || process.env.HEAD === 'next') ) { DEPLOY_ENV = 'staging'; From 17cad3ad42fa797e5f8fca55072e8416615c17ce Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 20 Nov 2022 16:39:17 +0100 Subject: [PATCH 5/9] explain why --- docs/next.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/next.config.js b/docs/next.config.js index 15f8f0f7c44494..a5cc3aeb0f1180 100644 --- a/docs/next.config.js +++ b/docs/next.config.js @@ -170,6 +170,7 @@ module.exports = withDocsInfra({ const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`; pages2.forEach((page) => { + // The experiments pages are only meant for experiments, they shouldn't leak to production. if (page.pathname.startsWith('/experiments') && process.env.DEPLOY_ENV === 'production') { return; } From ee6d89ea72e6e3012f4ac2dc0b658e3112f79d79 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 20 Nov 2022 16:43:10 +0100 Subject: [PATCH 6/9] in case there is another page that starts with the same prefix but is about something unrelated --- docs/next.config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/next.config.js b/docs/next.config.js index a5cc3aeb0f1180..de65ad6f342b8b 100644 --- a/docs/next.config.js +++ b/docs/next.config.js @@ -171,7 +171,10 @@ module.exports = withDocsInfra({ pages2.forEach((page) => { // The experiments pages are only meant for experiments, they shouldn't leak to production. - if (page.pathname.startsWith('/experiments') && process.env.DEPLOY_ENV === 'production') { + if ( + (page.pathname.startsWith('/experiments/') || page.pathname === '/experiments') && + process.env.DEPLOY_ENV === 'production' + ) { return; } // The blog is not translated From a664817343296f02d7f41934c65e4c99823ed141 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 20 Nov 2022 16:48:01 +0100 Subject: [PATCH 7/9] the pages have no Date: Sun, 20 Nov 2022 16:48:57 +0100 Subject: [PATCH 8/9] make it clearer --- docs/pages/experiments/index.js | 7 ++----- docs/public/_headers | 3 --- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/docs/pages/experiments/index.js b/docs/pages/experiments/index.js index bac1aa877e6c4d..afe54ab28568c3 100644 --- a/docs/pages/experiments/index.js +++ b/docs/pages/experiments/index.js @@ -56,13 +56,10 @@ export default function Experiments({ experiments }) {
    - All the files under /experiments are committed to git. + The files under /experiments/* are committed to git. - URLs start with /experiments/* are deployed only on the pull request. - - - /experiments/* are not included in docsearch indexing. + These URLs (start with /experiments/*) are not accessible in production.
diff --git a/docs/public/_headers b/docs/public/_headers index 3359623bc2fedb..d4afc703021d50 100644 --- a/docs/public/_headers +++ b/docs/public/_headers @@ -7,9 +7,6 @@ /favicon.ico Content-Type: image/x-icon -/experiments/* - X-Robots-Tag: noindex - /* Strict-Transport-Security: max-age=31536000; includeSubDomains; preload # Block usage in iframes. From d157ec55e8a42f408a43872cfb0d676f88ba6018 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 20 Nov 2022 19:44:07 +0100 Subject: [PATCH 9/9] prettier --- docs/pages/experiments/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/pages/experiments/index.js b/docs/pages/experiments/index.js index afe54ab28568c3..b16f134d1c0d74 100644 --- a/docs/pages/experiments/index.js +++ b/docs/pages/experiments/index.js @@ -59,7 +59,8 @@ export default function Experiments({ experiments }) { The files under /experiments/* are committed to git. - These URLs (start with /experiments/*) are not accessible in production. + These URLs (start with /experiments/*) are not accessible in + production.