-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Faster website build #3660
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
Open
Jake Bailey (jakebailey)
wants to merge
14
commits into
microsoft:v2
Choose a base branch
from
jakebailey:faster-website-build
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Faster website build #3660
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f022a5c
Avoid rebuilding packages after bootstrapping
jakebailey 899c793
Avoid redundant syntax-highlighting work
jakebailey 247c8fc
Build bootstrap-only aliases just once
jakebailey 5b21845
Distinguish semantic inputs in the Twoslash cache
jakebailey 41e4d55
Reuse dependency and compiler caches in website workflows
jakebailey f79440d
Leave build documentation unchanged
jakebailey 9b9508e
Bound saved Twoslash entries with LRU pruning
jakebailey e2c8d0a
Checkpoint website caches after successful builds
jakebailey 880c307
Reuse website cache snapshots across source changes
jakebailey 988d0aa
Exercise restored website build caches
jakebailey 2ed2488
Generate the TSConfig reference just once per build
jakebailey 40a711a
Reuse prepared packages when running CI tests
jakebailey 905cbf2
Checkpoint compiled examples after validation
jakebailey 43ade33
Run package validation independently of website builds
jakebailey 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 hidden or 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,25 @@ | ||
| name: Restore website build work | ||
| description: Reuse compiled examples and Webpack work without caching generated pages | ||
|
|
||
| outputs: | ||
| key: | ||
| description: Primary key to use when checkpointing the completed build | ||
| value: ${{ steps.restore.outputs.cache-primary-key }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Get Node version | ||
| id: node | ||
| shell: bash | ||
| run: echo "version=$(node --version)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| id: restore | ||
| with: | ||
| path: | | ||
| node_modules/.cache/twoslash | ||
| packages/typescriptlang-org/.cache/webpack | ||
| key: website-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.node.outputs.version }}-${{ github.run_id }}-${{ github.run_attempt }} | ||
| restore-keys: | | ||
| website-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.node.outputs.version }}- |
This file contains hidden or 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,51 @@ | ||
| const fs = require("fs") | ||
| const path = require("path") | ||
|
|
||
| const MAX_BYTES = 64 * 1024 * 1024 | ||
|
|
||
| function pruneTwoslashCache(directory) { | ||
| let entries | ||
| try { | ||
| if (!fs.lstatSync(directory).isDirectory()) { | ||
| throw new Error(`Expected a Twoslash cache directory: ${directory}`) | ||
| } | ||
| entries = fs.readdirSync(directory, { withFileTypes: true }) | ||
| } catch (error) { | ||
| if (error.code !== "ENOENT") throw error | ||
| return { bytes: 0, removed: 0, removedBytes: 0 } | ||
| } | ||
|
|
||
| const files = entries.map(entry => { | ||
| if (!entry.isFile() || !/^[a-f0-9]{40}\.json$/.test(entry.name)) { | ||
| throw new Error(`Unexpected Twoslash cache entry: ${entry.name}`) | ||
| } | ||
| const filename = path.join(directory, entry.name) | ||
| const { size, mtimeMs } = fs.statSync(filename) | ||
| return { filename, size, mtimeMs } | ||
| }) | ||
| files.sort((a, b) => a.mtimeMs - b.mtimeMs || a.filename.localeCompare(b.filename)) | ||
|
|
||
| let bytes = files.reduce((total, file) => total + file.size, 0) | ||
| let removed = 0 | ||
| let removedBytes = 0 | ||
| for (const file of files) { | ||
| if (bytes <= MAX_BYTES) break | ||
| fs.unlinkSync(file.filename) | ||
| bytes -= file.size | ||
| removedBytes += file.size | ||
| removed++ | ||
| } | ||
| return { bytes, removed, removedBytes } | ||
| } | ||
|
|
||
| module.exports = { MAX_BYTES, pruneTwoslashCache } | ||
|
|
||
| if (require.main === module) { | ||
| const directory = path.resolve(__dirname, "../../../node_modules/.cache/twoslash") | ||
| const { bytes, removed, removedBytes } = pruneTwoslashCache(directory) | ||
| console.log( | ||
| `Twoslash cache: ${(bytes / 1024 / 1024).toFixed(2)} MiB retained; ` + | ||
| `removed ${removed} entries (${(removedBytes / 1024 / 1024).toFixed(2)} MiB). ` + | ||
| `Limit: ${MAX_BYTES / 1024 / 1024} MiB.` | ||
| ) | ||
| } |
This file contains hidden or 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,28 @@ | ||
| name: Save website build work | ||
| description: Prune least-recently-used compiled examples and checkpoint the successful build | ||
|
|
||
| inputs: | ||
| key: | ||
| description: Primary key returned by the website cache restore action | ||
| required: true | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Prune Twoslash cache to 64 MiB | ||
| shell: bash | ||
| env: | ||
| CACHE_KEY: ${{ inputs.key }} | ||
| run: | | ||
| if [[ -z "$CACHE_KEY" ]]; then | ||
| echo "::error::Missing website cache restore key" | ||
| exit 1 | ||
| fi | ||
| node "$GITHUB_ACTION_PATH/../prune-twoslash-cache.js" | ||
|
|
||
| - uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | ||
| with: | ||
| path: | | ||
| node_modules/.cache/twoslash | ||
| packages/typescriptlang-org/.cache/webpack | ||
| key: ${{ inputs.key }} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -41,7 +41,8 @@ | |
| "webpack": "^5.105.3" | ||
| }, | ||
| "patchedDependencies": { | ||
| "[email protected]": "patches/[email protected]" | ||
| "[email protected]": "patches/[email protected]", | ||
| "[email protected]": "patches/[email protected]" | ||
| }, | ||
| "ignoredBuiltDependencies": [ | ||
| "@parcel/watcher", | ||
|
|
@@ -67,7 +68,7 @@ | |
| }, | ||
| "scripts": { | ||
| "ci:publish": "pnpm changeset git-tag && pnpm publish -r", | ||
| "bootstrap": "pnpm -r run bootstrap && BOOTSTRAPPING=true pnpm -r run build", | ||
| "bootstrap": "pnpm -r --filter=!@typescript/ata --filter=!@typescript/vfs --filter=!@typescript/twoslash --filter=!playground-examples --filter=!tsconfig-reference run bootstrap && pnpm build", | ||
| "start": "concurrently -p \"[{name}]\" -n \"BUILD,SITE\" -c \"bgBlue.bold,bgMagenta.bold\" \"node watcher.js\" \"pnpm run --filter=typescriptlang-org start\"", | ||
| "build": "pnpm run --filter=!typescriptlang-org build", | ||
| "build-site": "pnpm run --filter=typescriptlang-org build", | ||
|
|
@@ -76,6 +77,9 @@ | |
| "clean": "pnpm run --filter=typescriptlang-org gatsby clean", | ||
| "clean-twoslash": "rm -rf packages/.cache/twoslash", | ||
| "test": "CI=true pnpm -r run test", | ||
| "test:ci": "pnpm test:ci:site && pnpm test:ci:packages", | ||
| "test:ci:site": "CI=true pnpm -r --filter=glossary --filter=tsconfig-reference run lint && CI=true pnpm --filter=typescriptlang-org test", | ||
| "test:ci:packages": "CI=true pnpm -r --filter=!root --filter=!typescriptlang-org --filter=!glossary --filter=!tsconfig-reference --no-sort run test", | ||
| "update-test-snapshots": "CI=true pnpm run --filter=@typescript/twoslash --filter=@typescript/vfs test -u" | ||
| }, | ||
| "repository": "microsoft/TypeScript-Website", | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
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.
Wow, what?