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

[SPIKE] Collecting performance information #3239

30 changes: 30 additions & 0 deletions .github/workflows/actions/build-dist/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build `dist`

runs:
using: composite

steps:
- name: Cache build
uses: actions/cache@v3
id: build-cache

with:
# Restore build cache (unless commit SHA changes)
key: build-dist-cache-${{ github.sha }}
path: |
dist

- name: Install dependencies
uses: ./.github/workflows/actions/install-node

# Skip install when build is already cached
if: steps.build-cache.outputs.cache-hit != 'true'

- name: Build
id: build

# Skip build when we’ve built this SHA before
if: steps.build-cache.outputs.cache-hit != 'true'
shell: bash

run: npm run build:dist
30 changes: 30 additions & 0 deletions .github/workflows/actions/build-package/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build package

runs:
using: composite

steps:
- name: Cache build
uses: actions/cache@v3
id: build-cache

with:
# Restore build cache (unless commit SHA changes)
key: build-package-cache-${{ github.sha }}
path: |
package

- name: Install dependencies
uses: ./.github/workflows/actions/install-node

# Skip install when build is already cached
if: steps.build-cache.outputs.cache-hit != 'true'

- name: Build
id: build

# Skip build when we’ve built this SHA before
if: steps.build-cache.outputs.cache-hit != 'true'
shell: bash

run: npm run build:compile
2 changes: 1 addition & 1 deletion .github/workflows/actions/install-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
key: npm-install-cache-${{ hashFiles('package-lock.json', '**/package.json') }}
path: |
.cache/puppeteer
node_modules
**/node_modules

- name: Setup Node.js
uses: ./.github/workflows/actions/setup-node
Expand Down
81 changes: 73 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:

workflow_dispatch:

permissions:
pull-requests: write

concurrency:
group: tests-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
Expand Down Expand Up @@ -126,14 +129,6 @@ jobs:

matrix:
include:
- description: Verify package build
name: test-build-package
run: npm run build:package

- description: Verify distribution build
name: test-build-dist
run: npm run build:dist

- description: JavaScript behaviour tests
name: test-behaviour
run: npx jest --color --maxWorkers=2 --selectProjects "JavaScript behaviour tests"
Expand Down Expand Up @@ -172,3 +167,73 @@ jobs:

# Skip when secrets are unavailable on forks
if: ${{ github.repository_owner == 'alphagov' }}

build_dist:
name: Build dist
needs: [install]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Restore dependencies
uses: ./.github/workflows/actions/install-node

- name: Build dist
uses: ./.github/workflows/actions/build-dist

build_package:
name: Build package
needs: [install]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Restore dependencies
uses: ./.github/workflows/actions/install-node

- name: Build package
uses: ./.github/workflows/actions/build-package

stats:
name: Stats
needs: [build_dist,build_package]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Restore dependencies
uses: ./.github/workflows/actions/install-node

- name: Restore dist
uses: ./.github/workflows/actions/build-dist

- name: Restore package
uses: ./.github/workflows/actions/build-package

- name: Collects stats
run: npm start --workspace stats

- name: Save stats
uses: actions/upload-artifact@v3
with:
name: File stats
path: stats/public/all/stats-sunburst.html
if-no-files-found: ignore

- name: Add comment to PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const commentOnPr = require('./stats/comment-on-pr.js');
await commentOnPr({github,context})

if: github.event_name == 'pull_request'


1 change: 1 addition & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module.exports = async (options) => {
app.use(middleware.assets)
app.use('/docs', middleware.docs)
app.use('/vendor', middleware.vendor)
app.use('/stats', middleware.stats)

// Turn form POSTs into data that can be used for validation.
app.use(bodyParser.urlencoded({ extended: true }))
Expand Down
4 changes: 3 additions & 1 deletion app/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
*/
const assets = require('./assets')
const docs = require('./docs')
const stats = require('./stats')
const vendor = require('./vendor')

module.exports = {
assets,
docs,
vendor
vendor,
stats
}
12 changes: 12 additions & 0 deletions app/middleware/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const express = require('express')
const serveIndex = require('serve-index')

const configPaths = require('../../config/paths')
const router = express.Router()

// Serve the files themselves
router.use(express.static(configPaths.stats))
// Serve the directory listings, to allow navigating to the files
router.use(serveIndex(configPaths.stats))

module.exports = router
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"minimatch": "^5.1.1",
"nodemon": "^2.0.20",
"nunjucks": "^3.2.3",
"serve-index": "^1.9.1",
"shuffle-seed": "^1.1.6"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const configPaths = {

// Documentation
jsdoc: join(rootPath, 'jsdoc'),
sassdoc: join(rootPath, 'sassdoc')
sassdoc: join(rootPath, 'sassdoc'),

// Performance
stats: join(rootPath, 'stats', 'public')
}

module.exports = {
Expand Down
30 changes: 17 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"postinstall": "npm ls --depth=0",
"start": "gulp dev",
"serve": "npm run serve --workspace app",
"heroku": "npm run build:compile && npm start --workspace app",
"heroku": "npm run build:compile && npm start --workspace stats && npm start --workspace app",
"build-release": "./bin/build-release.sh",
"publish-release": "./bin/publish-release.sh",
"pre-release": "./bin/pre-release.sh",
Expand Down
Loading