Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build tasks: Move review app tasks into app/tasks #3384

Merged
merged 9 commits into from
Mar 30, 2023

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Mar 14, 2023

This PR splits out all "Review app" tasks into app/tasks as part of:

This reduces the risk of affecting govuk-frontend output by keeping each build separate:

  1. Project-level ./tasks via gulpfile.mjs
  2. Review app ./app/tasks via app/gulpfile.mjs
├── app
│   ├── dist
│   ├── src
│   └── tasks
└── tasks

Creating tasks

Whilst Gulp is still used as a task runner, I've switched to the export your tasks pattern vs using gulp.task()

Reminder: This API isn't the recommended pattern anymore - export your tasks.

All our new tasks are now plain async functions:

await files.copy('**/*', {
  srcPath: join(paths.src, 'govuk/assets'),
  destPath: join(paths.app, 'dist/assets')
})

But they can be composed into tasks for Gulp's gulp.series() and gulp.parallel() etc

task.name('copy:assets', () => files.copy('**/*', {
  srcPath: join(paths.src, 'govuk/assets'),
  destPath: join(paths.app, 'dist/assets')
}))

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 14, 2023 17:25 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 2da619b to cd0e06b Compare March 14, 2023 17:34
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 14, 2023 17:35 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from 49b1279 to 62da944 Compare March 15, 2023 09:30
@colinrotherham colinrotherham requested a review from a team as a code owner March 15, 2023 09:30
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from cd0e06b to 4634755 Compare March 15, 2023 10:02
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 15, 2023 10:03 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from 62da944 to 0354637 Compare March 15, 2023 10:19
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 4634755 to 914e09a Compare March 15, 2023 10:20
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 15, 2023 10:20 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from 0354637 to d48f97f Compare March 15, 2023 13:05
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 914e09a to 7d12dce Compare March 15, 2023 13:06
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 15, 2023 13:06 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from d48f97f to 2dcb55d Compare March 15, 2023 14:25
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 7d12dce to 259203b Compare March 15, 2023 14:48
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 15, 2023 14:48 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from 2dcb55d to bfa6e52 Compare March 16, 2023 10:58
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 259203b to bd7a622 Compare March 16, 2023 10:59
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 16, 2023 10:59 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from bfa6e52 to 3da41a9 Compare March 17, 2023 11:27
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from bd7a622 to c74785a Compare March 17, 2023 11:29
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 17, 2023 11:30 Inactive
@colinrotherham colinrotherham linked an issue Mar 20, 2023 that may be closed by this pull request
7 tasks
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from 3da41a9 to 080347e Compare March 20, 2023 13:46
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from c74785a to 28db545 Compare March 20, 2023 14:22
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 20, 2023 14:23 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-copy-app branch from 080347e to 6da759c Compare March 20, 2023 16:44
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 28db545 to 16ff2e8 Compare March 20, 2023 16:44
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 20, 2023 16:45 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from ebc21bf to d761c8c Compare March 29, 2023 09:36
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 29, 2023 09:36 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from d761c8c to d970378 Compare March 29, 2023 16:32
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 29, 2023 16:32 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from d970378 to 7b5fc1e Compare March 29, 2023 16:51
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 29, 2023 16:52 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 7b5fc1e to a47ebdb Compare March 29, 2023 21:59
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 29, 2023 21:59 Inactive
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

I think it's almost there, just had a couple of questions and little things in the comments 😄 Cheers for the move to plain functions with task.name and the genral tidy up.

@@ -20,18 +20,16 @@ export function watch () {
`${slash(paths.src)}/govuk/**/*.scss`,
`!${slash(paths.src)}/govuk/vendor/*`
], gulp.parallel(
npm.run('lint:scss'),
npm.script('lint:scss'),
Copy link
Member

Choose a reason for hiding this comment

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

I think the naming works, run makes it clear that something will happen while script sounds more like something you'll reference in a variable for later 🙌🏻

tasks/scripts.mjs Show resolved Hide resolved
tasks/styles.mjs Show resolved Hide resolved
@@ -4,7 +4,8 @@ const { ports } = require('./config/index.js')
* @type {import('jest-dev-server').Config}
*/
module.exports = {
command: 'npm start --workspace app',
// Start Express.js without "prestart" build script
command: 'npm start --ignore-scripts --workspace app',
Copy link
Member

Choose a reason for hiding this comment

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

question: Wouldn't running the prestart build script guarantee that our tests run against the last build of the server? Is it run some other way?

Copy link
Contributor Author

@colinrotherham colinrotherham Mar 30, 2023

Choose a reason for hiding this comment

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

This is a learning from the GOV.UK Design System
https://github.com/alphagov/govuk-design-system/blob/main/jest-puppeteer.config.js#L6

Every time you run npm test or npx jest ./path/to/spec.test.js it does a full rebuild each time

So here we cheat and give Jest permission to run what's already built

For anyone else running npm start I'd like it to stay nice and simple and build first 😊

Well spotted though

"serve": "nodemon",
"prestart": "npm run build",
Copy link
Member

Choose a reason for hiding this comment

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

nitpick As we're looking at reducing the complexity of our build, I think I'd be keen to avoid that prestart step that magically links the build to all our start calls. It also allows to keep the build and the start of the app separate without having to know that you need to reach for --ignore-scripts (which is a bit arcane).

I think it'll only be used on heroku so could we maybe make things explicit in the Procfile with something like (cd app && run build && npm start) (or with two --workspace app on each command).

Copy link
Contributor Author

@colinrotherham colinrotherham Mar 30, 2023

Choose a reason for hiding this comment

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

Would you mind if we kept npm start?

Keeps things simple

Although perhaps in future should align start/dev?

Server start

npm start
npm start --workspace app
npm start --workspace docs/examples/webpack

Development

npm run dev
npm run dev --workspace app
npm run dev --workspace docs/examples/webpack

But for now we have a necessary mismatch with npm start at project-level running this:

npm run dev --workspace app

@@ -41,7 +41,7 @@ jobs:
uses: ./.github/workflows/actions/build

- name: Start review application
run: npm run serve &
run: npm start --workspace app &
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to make sure we skip the prestart build here (as it's cached in GitHub Actions)

Suggested change
run: npm start --workspace app &
# Start Express.js without "prestart" build script
run: npm start --ignore-scripts --workspace app &

@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from a47ebdb to 3891d17 Compare March 30, 2023 19:00
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 30, 2023 19:00 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 3891d17 to 7887cab Compare March 30, 2023 19:04
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 30, 2023 19:05 Inactive
@colinrotherham colinrotherham force-pushed the build-tasks-gulpfile-app branch from 7887cab to 69b3f08 Compare March 30, 2023 19:07
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3384 March 30, 2023 19:08 Inactive
@colinrotherham colinrotherham merged commit fe38010 into main Mar 30, 2023
@colinrotherham colinrotherham deleted the build-tasks-gulpfile-app branch March 30, 2023 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Split project into separate app, config, lib and tasks packages
3 participants