Skip to content

Commit ab6f6c1

Browse files
Muntermontogeek
authored andcommitted
feat(infra) Travis optimization (#2404)
* Fix internal fragmtn links in optimization.md * Skip link checking or opencollective.com/webpack. Massive html response made the checker go into CPU overdrive * Try out travis staged build * Add proselint * Upgrade pip before using it * Move before-hooks around to try and make proselint install * Try adding python as a language as well to geet an updated version * More messing with config * Manually handle node versioning * Add node minor version to nvm install. Defaulted to slightly too low version * Manually install node 8.11 * Try a matrix build to separate node and python stuff * Add linkcheck task and try a different cahce setup * Minor name change to test if cache works correctly across builds * Attempt to combine matrix and staged build * Attempt going back to staged build * Bump travis * Ping Travis. You alive? * Fix broken travis.yml * Fix wrong stage order * Explicitly run specific lintings, exclude proselint * Allow failures for link checker * Change proselint cache directory. Maybe this works * Add new script to fetch repository names that the docs should contain. Try to centralize github API usage to avoid rate limitations * Add caching to eslint * Remove parts of deploy.sh that are now run by travis * Added new ./repositories to store github api results * Replace fetch.sh with npm scripts and fetch-package-readmes.js * Attempt to make caches more specific to the containers and stages they refer to * Remove deprecaed fetch_packages script. Now replaced by two-step fetch-package-repos and fetch-package-readmes * Attempt a more windows friendly build by using npm and webpack instead of shell commands * Disable link checking for now to speed up builds * Revert "Disable link checking for now to speed up builds" This reverts commit 7d4bb06. * Add dist to proselint cache so generated content also gets checked * Remove unnessessary GITHUB_TOKEN env variable check in repo fetching script * Revert "Add dist to proselint cache so generated content also gets checked" This reverts commit fc7676d. * Rework pipeline for better speed and make proselint a deployment blocker * Rename build stage to reflect its actions * Run content-tree only after generating all external content * Remove link to non-existing named-modules-plugin * Fix double slashes in edit links * Rename stages * Add new internal link check as a blocking check * Fix wrong name in allowed_failures config
1 parent 21c589f commit ab6f6c1

16 files changed

+272
-233
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ src/**/_*.md
88
npm-debug.log
99
yarn-error.log
1010
package-lock.json
11+
.cache

.travis.yml

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1-
branches:
2-
only:
3-
- master
4-
- develop
1+
sudo: false
52
language: node_js
63
node_js:
74
- "8"
8-
sudo: required
9-
install:
10-
- yarn
11-
- sudo pip install proselint
12-
before_script:
13-
- source ./src/scripts/env.sh
14-
script:
15-
- bash ./src/scripts/deploy.sh
5+
6+
cache:
7+
yarn: true
8+
directories:
9+
- node_modules
10+
- dist
11+
- .cache
12+
13+
stages:
14+
- Build
15+
- Post-build
16+
17+
jobs:
18+
fast_finish: true
19+
allow_failures:
20+
- name: External Link Check
21+
22+
include:
23+
- stage: Build
24+
name: Lint and Build
25+
before_install: npm install --global yarn
26+
install: yarn
27+
script:
28+
- yarn lint:js
29+
- yarn lint:markdown
30+
- yarn lint:social
31+
- yarn build
32+
- yarn lint:links
33+
34+
- stage: Build
35+
name: Proselint
36+
language: python
37+
python: 3.6
38+
cache:
39+
pip: true
40+
directories:
41+
- $HOME/.cache
42+
install: pip install -r requirements.txt
43+
script: cp .proselintrc ~/ && proselint src/content
44+
45+
- stage: Post-build
46+
name: Deploy
47+
if: branch = master
48+
script: bash ./src/scripts/deploy.sh
49+
50+
- stage: Post-build
51+
name: External Link Check
52+
script: yarn linkcheck

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@
2626
"scripts": {
2727
"clean": "rimraf ./dist src/content/**/_*.md src/**/_*.json",
2828
"start": "cross-env NODE_ENV=development webpack-dev-server --config webpack.dev.js --env.dev",
29+
"update-repos": "node src/utilities/fetch-package-repos.js",
2930
"content": "node src/scripts/build-content-tree.js ./src/content ./src/_content.json",
3031
"build-test": "npm run build && http-server build/",
31-
"fetch": "sh src/scripts/fetch.sh",
32+
"fetch": "run-p fetch:*",
33+
"fetch:readmes": "node src/utilities/fetch-package-readmes.js",
34+
"fetch:supporters": "node src/utilities/fetch-supporters.js",
35+
"fetch:starter-kits": "node src/utilities/fetch-starter-kits.js",
3236
"prebuild": "npm run clean",
33-
"build": "npm run fetch && npm run content && NODE_ENV=production webpack --config webpack.prod.js && npm run sitemap && echo webpack.js.org > dist/CNAME",
37+
"build": "run-s fetch content && NODE_ENV=production webpack --config webpack.prod.js",
38+
"postbuild": "npm run sitemap",
3439
"test": "npm run lint",
3540
"lint": "run-s lint:*",
36-
"lint:js": "eslint src --ext .js,.jsx,.md",
41+
"lint:js": "eslint src --ext .js,.jsx,.md --cache true --cache-location .cache/.eslintcache",
3742
"lint:markdown": "markdownlint --config ./.markdownlint.json *.md ./src/content/**/*.md --ignore './src/content/**/_*.md'",
3843
"lint:social": "alex . -q",
3944
"lint:prose": "cp .proselintrc ~/ && proselint src/content",
40-
"linkcheck": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ --skip support__ --skip sidecar.gitter.im --skip vimdoc.sourceforge.net --skip img.shields.io --skip npmjs.com/package/ --skip opencollective.com/webpack --todo external-redirect | tee master.tap | tap-spot",
45+
"lint:links": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ -i | tee internal-links.tap | tap-spot",
46+
"linkcheck": "hyperlink -r dist/index.html --canonicalroot https://webpack.js.org/ --skip support__ --skip sidecar.gitter.im --skip vimdoc.sourceforge.net --skip img.shields.io --skip npmjs.com/package/ --skip opencollective.com/webpack --todo external-redirect | tee external-links.tap | tap-spot",
4147
"sitemap": "cd dist && sitemap-static --prefix=https://webpack.js.org/ > sitemap.xml",
4248
"serve": "npm run build && sirv start ./dist --port 4000",
4349
"deploy": "gh-pages -d dist"
@@ -56,7 +62,7 @@
5662
]
5763
},
5864
"devDependencies": {
59-
"@octokit/rest": "^15.2.6",
65+
"@octokit/rest": "^15.9.4",
6066
"alex": "^5.1.0",
6167
"autoprefixer": "^7.2.3",
6268
"babel-core": "^6.26.0",

repositories/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Webpack documentation repositories
2+
3+
The files in this directory are auto generated from `src/utils/fetch-package-repos.js` and should not be edited by hand. Any manual changes will be overwritten by the automation next time it runs.

repositories/loaders.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[
2+
"webpack-contrib/json-loader",
3+
"webpack-contrib/raw-loader",
4+
"webpack-contrib/coffee-loader",
5+
"webpack-contrib/css-loader",
6+
"webpack-contrib/style-loader",
7+
"webpack-contrib/script-loader",
8+
"webpack-contrib/less-loader",
9+
"webpack-contrib/bundle-loader",
10+
"webpack-contrib/val-loader",
11+
"webpack-contrib/file-loader",
12+
"webpack-contrib/url-loader",
13+
"webpack-contrib/i18n-loader",
14+
"webpack-contrib/json5-loader",
15+
"webpack-contrib/worker-loader",
16+
"webpack-contrib/jshint-loader",
17+
"webpack-contrib/imports-loader",
18+
"webpack-contrib/exports-loader",
19+
"webpack-contrib/mocha-loader",
20+
"webpack-contrib/coverjs-loader",
21+
"webpack-contrib/expose-loader",
22+
"webpack-contrib/node-loader",
23+
"webpack-contrib/coffee-redux-loader",
24+
"webpack-contrib/transform-loader",
25+
"webpack-contrib/html-loader",
26+
"webpack-contrib/sass-loader",
27+
"webpack-contrib/source-map-loader",
28+
"webpack-contrib/react-proxy-loader",
29+
"webpack-contrib/null-loader",
30+
"webpack-contrib/multi-loader",
31+
"webpack-contrib/istanbul-instrumenter-loader",
32+
"webpack-contrib/eslint-loader",
33+
"webpack-contrib/yaml-frontmatter-loader",
34+
"webpack-contrib/svg-inline-loader",
35+
"webpack-contrib/restyle-loader",
36+
"webpack-contrib/gzip-loader",
37+
"webpack-contrib/cache-loader",
38+
"webpack-contrib/thread-loader",
39+
"webpack-contrib/polymer-webpack-loader",
40+
"webpack-contrib/workerize-loader",
41+
"webpack-contrib/config-loader",
42+
"babel/babel-loader",
43+
"postcss/postcss-loader",
44+
"peerigon/extract-loader"
45+
]

repositories/plugins.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
"webpack-contrib/i18n-webpack-plugin",
3+
"webpack-contrib/component-webpack-plugin",
4+
"webpack-contrib/compression-webpack-plugin",
5+
"webpack-contrib/extract-text-webpack-plugin",
6+
"webpack-contrib/copy-webpack-plugin",
7+
"webpack-contrib/npm-install-webpack-plugin",
8+
"webpack-contrib/stylelint-webpack-plugin",
9+
"webpack-contrib/babel-minify-webpack-plugin",
10+
"webpack-contrib/uglifyjs-webpack-plugin",
11+
"webpack-contrib/zopfli-webpack-plugin",
12+
"webpack-contrib/closure-webpack-plugin",
13+
"webpack-contrib/css-webpack-plugin",
14+
"webpack-contrib/mini-css-extract-plugin"
15+
]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
proselint

src/CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
webpack.js.org

src/scripts/deploy.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,10 @@
22
# see https://gist.github.com/domenic/ec8b0fc8ab45f39403dd
33
set -e # Exit with nonzero exit code if anything fails
44

5-
SOURCE_BRANCH="master"
6-
7-
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
8-
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
9-
echo "Skipping deploy; just doing a build and linting links/prose/js."
10-
yarn test
11-
yarn build
12-
exit 0
13-
fi
14-
155
# Save some useful information
166
REPO=`git config remote.origin.url`
177
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
188

19-
# Run tests
20-
yarn test
21-
22-
# Run our build
23-
yarn build
24-
259
# Set some git options
2610
git config --global user.name "Travis CI"
2711
git config --global user.email "ci@travis-ci.org"

src/scripts/env.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/scripts/fetch.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const _ = require('lodash');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const { promisify } = require('util');
5+
const mkdirp = promisify(require('mkdirp'));
6+
const request = require('request-promise');
7+
8+
const yamlHeadmatter = require('./yaml-headmatter.js');
9+
const processReadme = require('./process-readme.js');
10+
11+
const writeFile = promisify(fs.writeFile);
12+
const readFile = promisify(fs.readFile);
13+
const cwd = process.cwd();
14+
15+
const types = ['loaders', 'plugins'];
16+
17+
const pathMap = {
18+
loaders: path.resolve(__dirname, '../content/loaders'),
19+
plugins: path.resolve(__dirname, '../content/plugins')
20+
};
21+
22+
async function main() {
23+
for (const type of types) {
24+
const outputDir = pathMap[type];
25+
26+
await mkdirp(outputDir);
27+
28+
const repos = JSON.parse(await readFile(path.resolve(__dirname, `../../repositories/${type}.json`)));
29+
30+
for (const repo of repos) {
31+
const [org, packageName] = repo.split('/');
32+
const url = `https://raw.githubusercontent.com/${repo}/master/README.md`;
33+
const htmlUrl = `https://github.com/${repo}`;
34+
const editUrl = `${htmlUrl}/edit/master/README.md`;
35+
const fileName = path.resolve(outputDir, `_${packageName}.md`);
36+
37+
let title = packageName;
38+
39+
if (type === 'plugins') {
40+
title = _.camelCase(title);
41+
title = _.upperFirst(title);
42+
title = title.replace(/I18N/, 'I18n');
43+
}
44+
45+
// generate yaml matter for file
46+
let headmatter = yamlHeadmatter({
47+
title: title,
48+
source: url,
49+
edit: editUrl,
50+
repo: htmlUrl
51+
});
52+
53+
request(url)
54+
.then(async content => {
55+
const body = processReadme(content, { source: url });
56+
57+
await writeFile(fileName, headmatter + body);
58+
59+
console.log('Generated:', path.relative(cwd, fileName));
60+
});
61+
}
62+
}
63+
}
64+
65+
main();
66+

src/utilities/fetch-package-repos.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const mkdirp = require('mkdirp');
4+
const _ = require('lodash');
5+
const GithubAPI = require('@octokit/rest');
6+
7+
const fetch = {
8+
loaders: [
9+
{
10+
organization: 'webpack-contrib',
11+
suffixes: ['-loader']
12+
},
13+
'babel/babel-loader',
14+
'postcss/postcss-loader',
15+
'peerigon/extract-loader'
16+
],
17+
18+
plugins: [
19+
{
20+
organization: 'webpack-contrib',
21+
suffixes: ['-webpack-plugin', '-extract-plugin']
22+
}
23+
]
24+
};
25+
26+
const api = new GithubAPI();
27+
28+
async function paginate (org) {
29+
let response = await api.repos.getForOrg({ org, type: 'public', per_page: 100});
30+
let {data} = response;
31+
32+
while (api.hasNextPage(response)) {
33+
response = await api.getNextPage(response);
34+
data = data.concat(response.data);
35+
}
36+
37+
return data;
38+
}
39+
40+
async function main() {
41+
mkdirp.sync(path.resolve(__dirname, `../../repositories/`));
42+
43+
for (const [type, collection] of Object.entries(fetch)) {
44+
const result = await Promise.all(collection.map(async (item) => {
45+
if (typeof item === 'string') {
46+
return item;
47+
}
48+
49+
const { organization, suffixes } = item;
50+
51+
const repos = await paginate(organization);
52+
53+
return repos
54+
.map(repo => repo.full_name)
55+
.filter(name => suffixes.some(suffix => name.endsWith(suffix)));
56+
}));
57+
58+
const json = JSON.stringify(_.flatten(result), undefined, 2);
59+
const jsonPath = path.resolve(__dirname, `../../repositories/${type}.json`);
60+
61+
fs.writeFile(jsonPath, json, (err) => {
62+
if (err) {
63+
throw err;
64+
}
65+
});
66+
}
67+
}
68+
69+
main();

0 commit comments

Comments
 (0)