Skip to content

Commit

Permalink
Migrate PR stats action into Next.js repo (vercel#13177)
Browse files Browse the repository at this point in the history
* Migrate PR stats into Next.js repo

* Update running prettier in local mode
  • Loading branch information
ijjk authored May 21, 2020
1 parent beeefaa commit da5a05d
Show file tree
Hide file tree
Showing 26 changed files with 1,380 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ packages/next/compiled/**/*
packages/react-refresh-utils/**/*.js
packages/react-dev-overlay/lib/**
**/__tmp__/**
.github/actions/next-stats-action/.work
3 changes: 3 additions & 0 deletions .github/actions/next-stats-action/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules
out.md
.work
19 changes: 19 additions & 0 deletions .github/actions/next-stats-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:10-buster

LABEL com.github.actions.name="Next.js PR Stats"
LABEL com.github.actions.description="Compares stats of a PR with the main branch"
LABEL repository="https://github.com/zeit/next-stats-action"

COPY . /next-stats

# Install node_modules
RUN cd /next-stats && yarn install --production

RUN git config --global user.email 'stats@localhost'
RUN git config --global user.name 'next stats'

RUN apt update
RUN apt install apache2-utils -y

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
93 changes: 93 additions & 0 deletions .github/actions/next-stats-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Next.js Stats GitHub Action

> Downloads and runs project with provided configs gathering stats to compare branches
See it in action at Next.js https://github.com/zeit/next.js

## Getting Started

1. Add a `.stats-app` folder to your project with a [`stats-config.js`](#stats-config) and any files to run against for example a test app that is to be built
2. Add the action to your [workflow](https://help.github.com/en/articles/configuring-a-workflow)
3. Enjoy the stats

## Stats Config

```TypeScript
const StatsConfig = {
// the Heading to show at the top of stats comments
commentHeading: 'Stats from current PR' | undefined,
commentReleaseHeading: 'Stats from current release' | undefined,
// the command to build your project if not done on post install
initialBuildCommand: undefined | string,
skipInitialInstall: undefined | boolean,
// the command to build the app (app source should be in `.stats-app`)
appBuildCommand: string,
appStartCommand: string | undefined,
// the main branch to compare against (what PRs will be merging into)
mainBranch: 'canary',
// the main repository path (relative to https://github.com/)
mainRepo: 'zeit/next.js',
// whether to attempt auto merging the main branch into PR before running stats
autoMergeMain: boolean | undefined,
// an array of configs for each run
configs: [
{ // first run's config
// title of the run
title: 'fastMode stats',
// whether to diff the outputted files (default: onOutputChange)
diff: 'onOutputChange' | false | undefined,
// config files to add before running diff (if `undefined` uses `configFiles`)
diffConfigFiles: [] | undefined,
// renames to apply to make file names deterministic
renames: [
{
srcGlob: 'main-*.js',
dest: 'main.js'
}
],
// config files to add before running (removed before successive runs)
configFiles: [
{
path: './next.config.js',
content: 'module.exports = { fastMode: true }'
}
],
// an array of file groups to diff/track
filesToTrack: [
{
name: 'Pages',
globs: [
'build/pages/**/*.js'
]
}
],
// an array of URLs to fetch while `appStartCommand` is running
// will be output to fetched-pages/${pathname}.html
pagesToFetch: [
'https://localhost:$PORT/page-1'
]
},
{ // second run's config
title: 'slowMode stats',
diff: false,
configFiles: [
{
path: './next.config.js',
content: 'module.exports = { slowMode: true }'
}
],
filesToTrack: [
{
name: 'Main Bundles',
globs: [
'build/runtime/webpack-*.js',
'build/runtime/main-*.js',
]
}
]
},
]
}

module.exports = StatsConfig
```
6 changes: 6 additions & 0 deletions .github/actions/next-stats-action/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -eu # stop on error

export HOME=/root

node /next-stats/src/index.js
18 changes: 18 additions & 0 deletions .github/actions/next-stats-action/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "get-stats",
"version": "1.0.0",
"main": "src/index.js",
"license": "MIT",
"dependencies": {
"async-sema": "^3.1.0",
"fs-extra": "^8.1.0",
"get-port": "^5.0.0",
"glob": "^7.1.4",
"gzip-size": "^5.1.1",
"minimatch": "^3.0.4",
"node-fetch": "^2.6.0",
"prettier": "^1.18.2",
"pretty-bytes": "^5.3.0",
"pretty-ms": "^5.0.0"
}
}
Loading

0 comments on commit da5a05d

Please sign in to comment.