diff --git a/.github/workflows/release-static-production.yml b/.github/workflows/release-static-production.yml index c7276fb1c6f..84200346a6b 100644 --- a/.github/workflows/release-static-production.yml +++ b/.github/workflows/release-static-production.yml @@ -73,7 +73,6 @@ jobs: env: APP_ENV: production AMP_DOC_TOKEN: ${{ secrets.AMP_DOC_TOKEN }} - AMP_DEV_PIXI_APIS_KEY: ${{ secrets.AMP_DEV_PIXI_APIS_KEY }} run: | npx gulp buildPrepare @@ -167,7 +166,7 @@ jobs: environment: Production env: APP_ENV: production - CLOUDSDK_CORE_DISABLE_PROMPTS: 1 + NETLIFY_DEPLOY_TOKEN: ${{ secrets.NETLIFY_DEPLOY_TOKEN }} steps: - name: Cloning repository uses: actions/checkout@v2 diff --git a/.github/workflows/test-pixi.yaml b/.github/workflows/test-pixi.yaml index b872b7ea384..ca57209ec3a 100644 --- a/.github/workflows/test-pixi.yaml +++ b/.github/workflows/test-pixi.yaml @@ -1,12 +1,6 @@ --- name: 'Test: Pixi' -on: - push: - paths: - - 'package.json' - - 'pixi/**' - jobs: test: runs-on: ubuntu-latest diff --git a/gulpfile.js/build.js b/gulpfile.js/build.js index 0ffffc3689b..60746dffb12 100644 --- a/gulpfile.js/build.js +++ b/gulpfile.js/build.js @@ -517,7 +517,6 @@ function nunjucksEnv() { } function optimizeFiles(cb) { - const logger = require('@lib/utils/log')('AMP Optimizer'); return gulp .src(`${project.paths.PAGES_DEST}/**/*.html`) .pipe( @@ -530,14 +529,7 @@ function optimizeFiles(cb) { }); }) ) - .pipe( - gulp.dest((f) => { - logger.log( - `staticified ${path.relative(project.absolute('.'), f.path)}` - ); - return f.base; - }) - ) + .pipe(gulp.dest((f) => f.base)) .on('end', cb); } diff --git a/gulpfile.js/deploy-static.js b/gulpfile.js/deploy-static.js index 0d3d68e4ff0..a17f0a1e0ea 100644 --- a/gulpfile.js/deploy-static.js +++ b/gulpfile.js/deploy-static.js @@ -17,12 +17,37 @@ 'use strict'; const {sh} = require('@lib/utils/sh.js'); -const {GROW_BUILD_DEST} = require('@lib/utils/project').paths; +const {DIST, PAGES_DEST} = require('@lib/utils/project').paths; +const {NETLIFY_DEPLOY_TOKEN} = process.env; +const SITES = [ + { + NAME: 'amp.dev', + ID: 'e571c70e-d23f-4cbf-ac4e-802bb08e5261', + DIR: PAGES_DEST, + }, + { + NAME: 'playground.amp.dev', + ID: 'acead270-9404-4dde-81e4-aec0e6884869', + DIR: `${DIST}/playground`, + }, + { + NAME: 'preview.amp.dev', + ID: 'caf28d42-024a-4efb-b266-b00cf10847a3', + DIR: `${DIST}/examples`, + }, +]; async function staticDeploy() { - return sh('npx netlify deploy --prod --site amp-dev-static', { - workingDir: GROW_BUILD_DEST, - }); + for (const SITE of SITES) { + console.log(`attempting to deploy ${SITE.DIR}`); + + await sh( + `npx netlify deploy --prod --auth ${NETLIFY_DEPLOY_TOKEN} --site ${SITE.ID}`, + { + workingDir: SITE.DIR, + } + ); + } } exports.staticDeploy = staticDeploy; diff --git a/gulpfile.js/staticify.js b/gulpfile.js/staticify.js index b76b22a4f71..e11be5c57ad 100644 --- a/gulpfile.js/staticify.js +++ b/gulpfile.js/staticify.js @@ -19,10 +19,8 @@ const Cheerio = require('cheerio'); const Vinyl = require('vinyl'); const config = require('@lib/config'); -const filter = require('gulp-filter'); const gulp = require('gulp'); const nunjucks = require('nunjucks'); -const path = require('path'); const through = require('through2'); const {project} = require('@lib/utils'); const {survey} = require('@lib/templates/SurveyFilter.js'); @@ -37,18 +35,20 @@ const { FORMAT_WEBSITES, SUPPORTED_FORMATS, } = require('@lib/amp/formatHelper.js'); +const coursesPath = '/documentation/courses'; +const coursesRegex = new RegExp(`^(.+)(?:${coursesPath})(.*)$`); const getUpdatedURL = (u, requestedFormat, forcedFormat) => { return u.replace( - /(.*documentation\/[^/]+)[\/.]([^?]+)(?:\?(?:[^=]*)=(.*))?/, - (match, section, page) => { + /(.*documentation\/[^/]+)[\/.]([^?]+)?(?:\?(?:[^=]*)=(.*))?/, + (match, section, page, embeddedQueryFormat) => { if (page === 'html') { page = 'index.html'; } - const hasFormat = forcedFormat || requestedFormat; + const hasFormat = forcedFormat || embeddedQueryFormat || requestedFormat; const fmt = hasFormat ? `${hasFormat}/` : ''; - return `${section}/${fmt}${page}`; + return `${section}/${fmt}${page || ''}`; } ); }; @@ -98,13 +98,8 @@ async function staticify(done) { const f = (cb) => { const env = nunjucksEnv(); - const f = filter([`${project.paths.PAGES_DEST}/**/*html`, 'index'], { - restore: true, - }); - return gulp - .src(`${project.paths.PAGES_DEST}/**/*.html`) - .pipe(f) + .src(`${project.paths.PAGES_DEST}/**/*html`) .pipe( // Render a static version of all of our pages @@ -133,29 +128,33 @@ async function staticify(done) { // Rewrite links inside of each of the pages const $ = Cheerio.load(file.contents.toString()); + const $links = $('a.nav-link, a.ap-m-format-toggle-link'); - $('a.nav-link, a.ap-m-format-toggle-link').each(function () { + $links.each(function () { // eslint-disable-next-line no-invalid-this const $this = $(this); const origURL = $this.attr('href'); + const updatedURL = getUpdatedURL(origURL, format); - $this.attr('href', getUpdatedURL(origURL, format)); + $this.attr('href', updatedURL); }); const renderedPage = $.root().html(); - if ( - format === FORMAT_WEBSITES && - !file.path.endsWith('tools.html') - ) { - // covering the case where /documentation/tools.html, which matches differently than all other paths - const defaultFormatVersion = new Vinyl({ - path: getUpdatedURL(file.path), - contents: Buffer.from(renderedPage), - }); + // we need to render a "default" version for the URLs, and treat the "website" version as such + if (format === FORMAT_WEBSITES) { + const {path} = file; + let contents = Buffer.from(renderedPage); + + if (file.path.endsWith('tools.html')) { + // In addition to the tools pages for each format, we need to render a seperate main version that + // shows all of them. Rather than render its twice, we can just toggle a classname. + $('.ap-a-pill').addClass('active'); + contents = Buffer.from($.root().html()); + } // eslint-disable-next-line no-invalid-this - this.push(defaultFormatVersion); + this.push(new Vinyl({path, contents})); } file.path = getUpdatedURL(file.path, format); @@ -164,14 +163,7 @@ async function staticify(done) { callback(null, file); }) ) - .pipe( - gulp.dest((f) => { - logger.log( - `staticified ${path.relative(project.absolute('.'), f.path)}` - ); - return f.base; - }) - ) + .pipe(gulp.dest((file) => file.base)) .on('end', cb); }; @@ -183,9 +175,6 @@ async function staticify(done) { }); const generatedLevels = ['beginner', 'advanced'].map((level) => { - const coursesPath = '/documentation/courses'; - const coursesRegex = new RegExp(`^(.+)(?:${coursesPath})(.*)$`); - const f = (cb) => { const env = nunjucksEnv(); @@ -198,8 +187,11 @@ async function staticify(done) { requestPath: `${file.path.replace(requestPathRegex, '')}/`, level, format: FORMAT_WEBSITES, + requestedFormat: FORMAT_WEBSITES, }; + logger.log(`trying to rendering ${file.path}`); + env.renderString(srcHTML, configObj, (err, result) => { if (err) { return callback(err); @@ -215,8 +207,10 @@ async function staticify(done) { let renderedPage = file.contents.toString(); const $ = Cheerio.load(renderedPage); + const $links = $('.nav-link'); + const $levelToggle = $('.toggle-button input'); - $('.nav-link').each(function () { + $links.each(function () { // eslint-disable-next-line no-invalid-this const $this = $(this); const origURL = $this.attr('href'); @@ -228,7 +222,18 @@ async function staticify(done) { $this.attr('href', updatedURL); }); - renderedPage = $.root().html(); + const originalToggleLink = $levelToggle.attr('on'); + + if (originalToggleLink) { + const updatedToggleLink = originalToggleLink.replace( + /(^[^\/]+\/[^\/]+\/[^\/]+\/)([^?]+)+\?level=([^']+)(.+)$/, + (match, prefix, coursePath, level, suffix) => + `${prefix}${level}/${coursePath}${suffix}` + ); + $levelToggle.attr('on', updatedToggleLink); + + renderedPage = $.root().html(); + } if (level === 'beginner') { // eslint-disable-next-line no-invalid-this @@ -300,8 +305,8 @@ async function staticify(done) { return new Promise((resolve, reject) => { gulp.series( - gulp.parallel(...generatedFormats), gulp.parallel(...generatedLevels), + gulp.parallel(...generatedFormats), (seriesDone) => { seriesDone(); resolve(); diff --git a/netlify/configs/playground.amp.dev/netlify.toml b/netlify/configs/playground.amp.dev/netlify.toml index afd40589418..e55e30f06d6 100644 --- a/netlify/configs/playground.amp.dev/netlify.toml +++ b/netlify/configs/playground.amp.dev/netlify.toml @@ -2,6 +2,7 @@ base = "." # Directory to change to before starting a build. # This is where we will look for package.json/.nvmrc/etc. + publish = "." [[headers]] for = "/*" diff --git a/package.json b/package.json index 4e6ee6c14b6..822a2c9e366 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "gcp-metadata": "4.3.1", "google-spreadsheet": "3.1.15", "gulp-file": "0.4.0", - "gulp-filter": "7.0.0", "helmet-csp": "3.4.0", "http-proxy": "1.18.1", "iltorb": "2.4.5", diff --git a/pages/content/amp-dev/documentation/tools.html b/pages/content/amp-dev/documentation/tools.html index cf078f1d2ee..a6676f57b07 100644 --- a/pages/content/amp-dev/documentation/tools.html +++ b/pages/content/amp-dev/documentation/tools.html @@ -61,8 +61,7 @@ diff --git a/platform/lib/utils/ampOptimizer.js b/platform/lib/utils/ampOptimizer.js index b480e5423a9..926d4fddfdf 100644 --- a/platform/lib/utils/ampOptimizer.js +++ b/platform/lib/utils/ampOptimizer.js @@ -14,7 +14,6 @@ * limitations under the License. */ -const imageOptimizer = require('@lib/utils/imageOptimizer'); const HeadDedupTransformer = require('@lib/utils/HeadDedupTransformer'); const AmpOptimizer = require('@ampproject/toolbox-optimizer'); const CssTransformer = require('@lib/utils/cssTransformer'); @@ -22,7 +21,6 @@ const signale = require('signale'); const optimizerConfig = { imageBasePath: 'pages', - imageOptimizer, autoExtensionImport: true, extensionVersions: { 'amp-base-carousel': '0.1', diff --git a/playground/netlify.toml b/playground/netlify.toml index afd40589418..e55e30f06d6 100644 --- a/playground/netlify.toml +++ b/playground/netlify.toml @@ -2,6 +2,7 @@ base = "." # Directory to change to before starting a build. # This is where we will look for package.json/.nvmrc/etc. + publish = "." [[headers]] for = "/*"