Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

implement "up-to-date" build design #1545

Merged
merged 17 commits into from Oct 7, 2021
Merged

implement "up-to-date" build design #1545

merged 17 commits into from Oct 7, 2021

Conversation

samthor
Copy link
Contributor

@samthor samthor commented Oct 5, 2021

This is a major PR changing the way we pull in external data to the site. It mostly implements the internal named design doc.

  • We have a subfolder named external/ which itself contains data/ (dynamically fetched), build/ (run to build data/) and fallback/ (provides consistent data for CI).
  • The Cloud Build task will be run every ~hour, and populates a Cloud Storage bucket with external data on success
  • Normal users of the site, as part of npm run dev, will have this folder synchronized to external/data/
  • If you want to instead test external data or change its build, you can run npm run build-external; this will also prevent sync until you later run npm run sync-external to clear a boolean

The idea is that external data breakages, while important (and will alert the team, because we alert on Cloud Build failures of any type), shouldn't stop regular deploy for our authors. They'll always get a "last known good" during local dev, or as part of our regular site deploy.

This only moves tweet generation to this approach. After this PR goes in, I'll add:

  • Chrome release data
  • Types information for Extensions
  • ... future external content.

@chrome-devrel-review-bot
Copy link
Collaborator

chrome-devrel-review-bot commented Oct 5, 2021

Hello! This is an automated review by our custom reviewbot. It updates automatically when code or GitHub comments in this pull request are created or updated.

Requested changes

If there are any common problems with the content files you created or modified, they will be listed here.

external/README.md

  • This file passed all of our automated Markdown audits.

@netlify
Copy link

netlify bot commented Oct 5, 2021

✔️ Deploy Preview for developer-chrome-com ready!

🔨 Explore the source changes: 3119d3b

🔍 Inspect the deploy log: https://app.netlify.com/sites/developer-chrome-com/deploys/615f666b98b30100081ece55

😎 Browse the preview: https://deploy-preview-1545--developer-chrome-com.netlify.app

@google-cla google-cla bot added the cla: yes label Oct 5, 2021
external/build-external.js Outdated Show resolved Hide resolved
external/build-external.js Outdated Show resolved Hide resolved
const childProcess = require('child_process');
const crypto = require('crypto');

async function run() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I see any await, couldn't this just be script.... Like, nothing in the run function, i.e. no run function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but this matches the other files, and it makes it easier if it ever needs to do async work. What do you think?

external/build-external.js Outdated Show resolved Hide resolved
external/maybe-sync-external.js Outdated Show resolved Hide resolved
external/maybe-sync-external.js Show resolved Hide resolved
// We have to cast this to unknown first as Typescript gets very literal about the underlying type
// of the JSON.
let tweets = /** @type {TwitterTweet[]} */ (
/** @type {unknown} */ (require('../../external/data/tweets.json'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use the cache tool here to point to the external tweets if there isn't a local one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings on this but I'm happy to be disagreed with. I think there's a big advantage in not having to have conditionals here—the code always just pulls something in.

But I've added an eslint rule to allow this to be missing and that's awkward too.

WDYT?

Copy link
Contributor

@robdodson robdodson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good :) Deferring to Ewa and Michael for final sign off.

.cloudbuild/external.yaml Outdated Show resolved Hide resolved
@samthor
Copy link
Contributor Author

samthor commented Oct 7, 2021

I've updated the README and made the linter run.

  • In CI build mode, we aggressively use the fallback files first, in case e.g. Twitter's API key isn't available.

  • In CI sync mode, we aggressively use the fallback files last, so that Percy and such use the same data every time.

external/build-external.js Outdated Show resolved Hide resolved
@samthor
Copy link
Contributor Author

samthor commented Oct 7, 2021 via email

@samthor
Copy link
Contributor Author

samthor commented Oct 7, 2021 via email

// If this is a CI build, we start with everything found in "fallback/". It won't win, but it
// will be used in cases where credentials and such aren't available.
if (process.env.CI) {
const all = await syncFallback();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like /fallback data never gets refreshed and is used for testing only. Since its only used in CI, I'd call it e.g. testdata or so. "Fallback" suggests its data used when sync fails for some reason,
while it should never be used in prod.

Copy link
Contributor

@devnook devnook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with small comments left

@samthor samthor merged commit 6a5c07e into main Oct 7, 2021
@samthor samthor deleted the cache-gen branch October 7, 2021 21:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants