-
Notifications
You must be signed in to change notification settings - Fork 715
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
github(workflows): add package size checks, add auto demo deploy #1048
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
7754a8b
internal(deps): add deps for ts-node and filesize computation
williaster f385cdf
internal(node): add tsconfig for node
williaster 6b67007
build: add computeBuildSizes script
williaster 96b1e96
build: add compareBuildSizes, upsertPullRequestComment scripts
williaster b778c4f
build: update computeBuildSizes output file
williaster 65d7f0b
build: add deploy-demo script
williaster 894c506
github(workflows/ci): add Package sizes + Deploy gallery steps
williaster cb085cc
github(workflows/ci): add pull_request checks to happo, package sizes
williaster 06f90a2
deps(dev): add @types/node-fetch
williaster 85d18be
deps: update yarn.lock
williaster c055393
type(scripts/upsertPullRequestComment): fix comment type
williaster 6703ca8
github(workflows): separate CI into push + pull_request
williaster fdcc602
deps(dev): add @octokit/rest
williaster 1efd7c8
fix(workflows/pull_request): add needed variables for upsertPullReque…
williaster 91f4e6e
commit to kick workflow
williaster a861a39
github(workflows): fix package size report job
williaster f50dff2
github(workflow): fix GITHUB_REPOSITORY/ACTOR variable syntax
williaster f01184d
fix(scripts/upsertPullRequestComment): better types
williaster 8dd0720
fix(scripts/compareBuildSizes): log errors
williaster e21bc08
debug(scripts//upsertPullRequestComment): add more debug logs
williaster 2169ed7
debug(scripts/upsertPullRequestComment): add more debug logs
williaster 42509e4
fix(/workflows/pull_request): remove debug logging
williaster 734973e
github(workflows): update branches for testing
williaster 32deeda
fix(workflows/push)
williaster e8a955c
fix(scripts/upsertPullRequestComment): fix bot user login check
williaster 9609b2f
deps(demo, annotation, tooltip): react-measure@2.0.3
williaster e6d31c5
fix(demo/axis,pattern,xychart): fix window check for ssr
williaster 0009880
fix(/workflows/push): rewrite gallery deploy job to fix credentials
williaster ff77c3e
fix(workflows/push/gallery): try to fix credentials
williaster 6cb73a3
fix(github/workflows/push): try https for gallery push
williaster 2fdee13
fix(workflows/push): tweak https syntax
williaster 521b296
fix(workflows/push): try github-pages-deploy-action
williaster 72b182c
fix(workflows/push): don't use working-directory with uses
williaster 82bfeab
fix(workflows/push): try changing persist-credentials mid-workflow
williaster ff3a7b7
fix(workflows/push): more changes
williaster 6e71972
fix(workflows/push): try worktree approach
williaster ed6c6bf
fix(workflows/push): build gallery on master
williaster b6734d3
fix(workflows/push): add out/ contents pre-commit
williaster 16eac02
fix(workflows/push): fix credentials
williaster 3bed467
fix(workflows/push): try not master
williaster ddd77a9
fix(workflows/push): try not master take 2
williaster da1b374
fix(workflows/push): we have a winner
williaster 1bc79d1
fix(workflows/push,pull_request): final final
williaster d503be5
fix(workflows/push): match 📡 emoji across workflows 🙄
williaster 160db5c
type(scripts/upsertPullRequestComment): fix types
williaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Push | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 # checkout visx + this commit | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: '12' | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- uses: actions/cache@v1 | ||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
|
||
- name: 📡 Install dependencies | ||
run: yarn install --frozen-lockfile --ignore-engines | ||
|
||
- name: 🛠 Build packages | ||
run: yarn build | ||
|
||
- name: 📐 Commit package sizes | ||
run: | | ||
yarn build:sizes | ||
git config user.name github-actions | ||
git config user.email github-actions@github.com | ||
git add . | ||
git commit -m "build(${GITHUB_SHA}): auto-commit package sizes" | ||
git push | ||
|
||
- name: 🚀 Build and deploy gallery | ||
# below we | ||
# - setup git credentials provided via actions/checkout@v2 | ||
# - initialize gh-pages-branch as an orphan branch so we don't build history | ||
# - checkout the current commit and create gh-pages-root-dir/ as a new worktree | ||
# - outside that directory HEAD is detached at $GITHUB_SHA | ||
# - within that directory we are on the gh-pages-branch we just initialized | ||
# *worktree initialization should be in a root dir, otherwise the worktree inherits nested directories | ||
# - build the static next.js site and copy the output into gh-pages-root-dir/ | ||
# - we can't output directly into gh-pages-root-dir/ because next wipes the folder including .git | ||
# - commit the demo site within gh-pages-root-dir/ onto the gh-pages-branch | ||
# - push gh-pages-branch to visx as gh-pages. we overwrite history every time so it must be forced | ||
run: | | ||
git config user.name github-actions | ||
git config user.email github-actions@github.com | ||
git checkout --orphan gh-pages-branch | ||
git reset --hard | ||
touch .nojekyll | ||
git add .nojekyll | ||
git commit -m "bot(${GITHUB_SHA}): initialize gh-pages branch" | ||
git checkout "$GITHUB_SHA" | ||
git worktree add gh-pages-root-dir gh-pages-branch | ||
cd ./packages/visx-demo/ | ||
yarn build | ||
mv -v out/* ../../gh-pages-root-dir/ | ||
cd ../../gh-pages-root-dir/ | ||
git add . | ||
git commit -m "bot(${GITHUB_SHA}): build gh-pages" | ||
git push -f "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:gh-pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,23 +30,29 @@ | |
], | ||
"private": true, | ||
"scripts": { | ||
"build": "yarn run babel && yarn run type:dts", | ||
"build-one": "nimbus babel --clean", | ||
"babel": "yarn run babel:cjs && yarn run babel:esm", | ||
"babel:cjs": "nimbus babel --clean --workspaces=\"@visx/!(demo)\"", | ||
"babel:esm": "nimbus babel --clean --workspaces=\"@visx/!(demo)\" --esm", | ||
"build": "yarn run babel && yarn run type", | ||
"build-one": "echo 'build-one has been replaced with build:workspace' & exit 1", | ||
"build:sizes": "yarn run ts ./scripts/computeBuildSizes.ts", | ||
"build:workspace": "nimbus babel --clean", | ||
"check:sizes": "yarn run ts ./scripts/compareBuildSizes.ts", | ||
"clean": "rm -rf ./packages/**/{lib,esm}", | ||
"format": "yarn run prettier --write", | ||
"jest": "NODE_ENV=test nimbus jest --coverage --verbose", | ||
"lint": "nimbus eslint", | ||
"lint:fix": "yarn run lint --fix", | ||
"prepare-release": "git checkout master && git pull --rebase origin master && lerna updated", | ||
"prettier": "nimbus prettier", | ||
"release": "yarn run prepare-release && lerna publish --exact", | ||
"setup": "yarn run build", | ||
"test": "yarn run jest", | ||
"type:dts": "nimbus typescript --build --reference-workspaces", | ||
"type-one": "nimbus typescript --build", | ||
"prepare-release": "git checkout master && git pull --rebase origin master && lerna updated", | ||
"release": "yarn run prepare-release && lerna publish --exact" | ||
"ts": "ts-node --project ./tsconfig.node.json", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"type": "nimbus typescript --build --reference-workspaces", | ||
"type-one": "echo 'type-one has been replaced with type:workspace' & exit 1", | ||
"type:dts": "echo 'type:dts has been replaced with type' & exit 1", | ||
"type:workspace": "nimbus typescript --build" | ||
}, | ||
"devDependencies": { | ||
"@airbnb/config-babel": "^2.1.3", | ||
|
@@ -55,26 +61,33 @@ | |
"@airbnb/config-prettier": "^2.0.4", | ||
"@airbnb/config-typescript": "^2.1.2", | ||
"@airbnb/nimbus": "^2.1.3", | ||
"@octokit/rest": "18.1.0", | ||
"@types/enzyme": "^3.10.3", | ||
"@types/jest": "^24.0.18", | ||
"@types/jsdom": "^12.2.4", | ||
"@types/node-fetch": "1.6.9", | ||
"@types/react-test-renderer": "^16.9.0", | ||
"@types/webpack": "^4.41.17", | ||
"chalk": "4.1.0", | ||
"coveralls": "^3.0.6", | ||
"enzyme": "^3.10.0", | ||
"enzyme-adapter-react-16": "^1.14.0", | ||
"enzyme-to-json": "^3.4.0", | ||
"fast-glob": "3.2.5", | ||
"filesize": "6.1.0", | ||
"fs-jetpack": "^1.3.0", | ||
"husky": "^3.0.0", | ||
"jest-mock-console": "^1.0.1", | ||
"lerna": "^3.15.0", | ||
"marked": "^0.7.0", | ||
"node-fetch": "2.6.1", | ||
"raf": "^3.4.0", | ||
"react": "^15.0.0-0 || ^16.0.0-0", | ||
"react-dom": "^15.0.0-0 || ^16.0.0-0", | ||
"react-test-renderer": "^16.8.6", | ||
"regenerator-runtime": "^0.10.5", | ||
"timezone-mock": "^1.1.0" | ||
"timezone-mock": "^1.1.0", | ||
"ts-node": "9.1.1" | ||
}, | ||
"workspaces": [ | ||
"./packages/*" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,8 @@ export default function Example({ | |
showControls = true, | ||
}: AxisProps) { | ||
// use non-animated components if prefers-reduced-motion is set | ||
const prefersReducedMotionQuery = window?.matchMedia('(prefers-reduced-motion: reduce)'); | ||
const prefersReducedMotionQuery = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
typeof window === 'undefined' ? false : window.matchMedia('(prefers-reduced-motion: reduce)'); | ||
const prefersReducedMotion = !prefersReducedMotionQuery || !!prefersReducedMotionQuery.matches; | ||
const [useAnimatedComponents, setUseAnimatedComponents] = useState(!prefersReducedMotion); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/visx-demo/src/sandboxes/visx-xychart/userPrefersReducedMotion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default function userPrefersReducedMotion() { | ||
const prefersReducedMotionQuery = window?.matchMedia('(prefers-reduced-motion: reduce)'); | ||
const prefersReducedMotionQuery = | ||
typeof window === 'undefined' ? false : window.matchMedia('(prefers-reduced-motion: reduce)'); | ||
return !prefersReducedMotionQuery || !!prefersReducedMotionQuery.matches; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import fs from 'fs'; | ||
import size from 'filesize'; | ||
import chalk from 'chalk'; | ||
import fetch from 'node-fetch'; | ||
import upsertPullRequestComment from './upsertPullRequestComment'; | ||
import { PACKAGE_SIZES_FILENAME } from './computeBuildSizes'; | ||
|
||
type StatMap = { | ||
[pkg: string]: { | ||
[dir: string]: number; | ||
}; | ||
}; | ||
|
||
function calculateDiff(prev: number, next: number): number { | ||
return (next - prev) / prev; | ||
} | ||
|
||
function formatDiff(diff: number): string { | ||
const sum = diff * 100; | ||
const percent = sum.toFixed(1); | ||
|
||
// Smaller | ||
if (percent.startsWith('-')) { | ||
return `${sum < -10 ? ':small_red_triangle_down: ' : ''}${percent}%`; | ||
} | ||
|
||
// Larger | ||
return `${sum > 10 ? ':small_red_triangle: ' : ''}+${percent}%`; | ||
} | ||
|
||
async function compareBuildSizes() { | ||
const nextSizes: StatMap = JSON.parse(fs.readFileSync(PACKAGE_SIZES_FILENAME, 'utf8')); | ||
let prevSizes: StatMap = {}; | ||
let sameBuild = false; | ||
|
||
try { | ||
const masterFileSizesRequest = await fetch( | ||
`https://raw.githubusercontent.com/airbnb/visx/master/${PACKAGE_SIZES_FILENAME}`, | ||
); | ||
|
||
prevSizes = await masterFileSizesRequest.json(); | ||
} catch (error) { | ||
console.log(`Could not fetch file ${PACKAGE_SIZES_FILENAME} from master. Aborting.`); | ||
console.log(error.message); | ||
|
||
prevSizes = nextSizes; | ||
sameBuild = true; | ||
} | ||
|
||
function getPrevSize(name: string, type: string) { | ||
return (prevSizes[name] && prevSizes[name][type]) || 0; | ||
} | ||
|
||
const output: string[] = [ | ||
'### Size Changes', | ||
'| Package | Diff | ESM | Prev ESM | CJS | Prev CJS |', | ||
'| --- | ---: | ---: | ---: | ---: | ---: |', | ||
]; | ||
const rows: string[] = []; | ||
|
||
Object.entries(nextSizes).forEach(([pkgName, stats]) => { | ||
const prevEsm = getPrevSize(pkgName, 'esm'); | ||
const prevLib = getPrevSize(pkgName, 'lib'); | ||
const diff = calculateDiff(prevEsm, stats.esm); | ||
|
||
if (!isFinite(diff) || diff === 0 || diff === 0.0) { | ||
return; | ||
} | ||
|
||
const row = [ | ||
pkgName, | ||
formatDiff(diff), | ||
size(stats.esm), | ||
prevEsm === 0 ? 'N/A' : size(prevEsm), | ||
size(stats.lib), | ||
prevLib === 0 ? 'N/A' : size(prevLib), | ||
]; | ||
|
||
rows.push(`| ${row.join(' | ')} |`); | ||
}); | ||
|
||
// Don't post anything if no changes | ||
if (rows.length === 0) { | ||
return; | ||
} | ||
|
||
// Sort rows before joining to output | ||
rows.sort(); | ||
|
||
output.push(...rows); | ||
output.push('> Compared to master. File sizes are unminified and ungzipped.'); | ||
|
||
// Show dumps for easier debugging | ||
if (!sameBuild) { | ||
output.push(`<details> | ||
<summary>View raw build stats</summary> | ||
|
||
#### Previous (master) | ||
\`\`\`json | ||
${JSON.stringify(prevSizes, null, 2)} | ||
\`\`\` | ||
|
||
#### Current | ||
\`\`\`json | ||
${JSON.stringify(nextSizes, null, 2)} | ||
\`\`\` | ||
</details>`); | ||
} | ||
|
||
// Leave a comment on the PR | ||
const breakdown = output.join('\n'); | ||
|
||
try { | ||
await upsertPullRequestComment('### Size Changes', breakdown); | ||
} catch (error) { | ||
console.log('Could not post size stats', breakdown); | ||
console.error(error); | ||
} | ||
} | ||
|
||
compareBuildSizes().catch(error => { | ||
console.error(chalk.red(error.message)); | ||
process.exitCode = 1; | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually use this package to handle deployment to github pages.
Would it simplify the script here?
https://www.npmjs.com/package/gh-pages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we deploy to
gh-pages
with a simple script in@visx/demo
that is similar to these commands. the complexity comes from the creation of a new git worktree without history in the action environment.tbh I spent so much time on this already I'd rather just leave it. I tried a
gh-pages
action someone made and it worked, but it requires special handling of credentials which then causes the package size commit to fail. so would have to duplicate theyarn && yarn build
steps multiple times which isn't ideal.