Skip to content

Commit

Permalink
Merge pull request #4650 from alphagov/only-use-fixture-cache-ci
Browse files Browse the repository at this point in the history
Only use fixture HTML 'cache' when running on CI
  • Loading branch information
36degrees authored Jan 17, 2024
2 parents b2cf8f5 + e3651dc commit 39c0a23
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
10 changes: 3 additions & 7 deletions packages/govuk-frontend-review/src/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export default async () => {

// Feature flags
const flags = /** @type {FeatureFlags} */ ({
isDeployedToHeroku: !!process.env.HEROKU_APP,
isDevelopment: !['test', 'production'].includes(process.env.NODE_ENV),
isDevelopment: !process.env.HEROKU_APP && !process.env.CI,

// Check for JSDoc, SassDoc and Rollup stats
hasDocsScripts: await hasPath(join(paths.app, 'dist/docs/jsdoc')),
Expand Down Expand Up @@ -219,9 +218,7 @@ export default async () => {
const componentView = render(componentName, {
context: fixture.options,
env,

// Skip Nunjucks render from cache in development
fixture: !flags.isDevelopment ? fixture : undefined
fixture
})

let bodyClasses = 'app-template__body'
Expand Down Expand Up @@ -278,8 +275,7 @@ export default async () => {

/**
* @typedef {object} FeatureFlags
* @property {boolean} isDeployedToHeroku - Review app using `HEROKU_APP`
* @property {boolean} isDevelopment - Review app not using `NODE_ENV` production or test
* @property {boolean} isDevelopment - Review app not in CI or on Heroku
* @property {boolean} hasDocsStyles - Stylesheets documentation (SassDoc) is available
* @property {boolean} hasDocsScripts - JavaScripts documentation (JSDoc) is available
* @property {boolean} hasStats - Rollup stats are available
Expand Down
4 changes: 2 additions & 2 deletions packages/govuk-frontend-review/src/common/middleware/docs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ router.get('/', (req, res) => {
* Sass docs latest release (when deployed)
*/
router.use('/sass', ({ app }, res, next) => {
const { isDeployedToHeroku } =
const { isDevelopment } =
/** @type {import('../../app.mjs').FeatureFlags} */ (app.get('flags'))

if (isDeployedToHeroku) {
if (!isDevelopment) {
return res.redirect(
'https://frontend.design-system.service.gov.uk/sass-api-reference/'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function renderer(app) {
{
dev: true, // log stack traces
express: app, // the Express.js review app that nunjucks should install to
noCache: !flags.isDeployedToHeroku, // use cache when deployed only
noCache: flags.isDevelopment, // use cache in development only
watch: flags.isDevelopment // reload templates in development only
},
{
Expand Down
10 changes: 8 additions & 2 deletions shared/lib/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,14 @@ function render(componentName, options) {
const macroName = componentNameToMacroName(componentName)
const macroPath = `govuk/components/${componentName}/macro.njk`

// Return built fixture or render
return options?.fixture?.html ?? renderMacro(macroName, macroPath, options)
// On Heroku / CI we know we're running against an up-to-date build so we can
// use the generated HTML from the component JSON (where it exists) to make
// things faster
if ((process.env.HEROKU_APP || process.env.CI) && options?.fixture?.html) {
return options.fixture.html
}

return renderMacro(macroName, macroPath, options)
}

/**
Expand Down

0 comments on commit 39c0a23

Please sign in to comment.