@@ -188,8 +188,10 @@ jobs:
188188 if : matrix.test_commit_records
189189 run : yarn test-upsert-comment
190190
191+ # The format check gives the same result everywhere; it runs on Linux
192+ # only, where it is fastest.
191193 - name : Run tests
192- run : node scripts/test.js -all
194+ run : node scripts/test.js ${{ runner.os == 'Linux' && ' -all' || '-ounit -mocha -build -docstrings' }}
193195
194196 - name : Check for diffs in tests folder
195197 run : git diff --ignore-cr-at-eol --exit-code tests
@@ -393,50 +395,80 @@ jobs:
393395
394396 # Checks that the website builds with the generated API docs. These
395397 # steps stay in this job rather than in one that needs build-compiler,
396- # which would wait for the slowest platform before starting.
397- - name : Checkout rescript-lang.org
398+ # which would wait for the slowest platform before starting. The build
399+ # depends only on the docs and the website commit, so an empty cache
400+ # entry keyed on both records each pair that built, and a pull request
401+ # whose docs match an earlier build skips it.
402+ - name : Website build key
403+ id : website-build-key
398404 if : ${{ matrix.generate_api_docs }}
405+ env :
406+ WEBSITE_BRANCH : ${{ steps.api-docs-plan.outputs.website-branch }}
407+ run : |
408+ sha=$(git ls-remote https://github.com/rescript-lang/rescript-lang.org.git "refs/heads/$WEBSITE_BRANCH" | cut -f1)
409+ if [ -z "$sha" ]; then
410+ echo "::error::The website has no branch $WEBSITE_BRANCH"
411+ exit 1
412+ fi
413+ echo "sha=$sha" >> "$GITHUB_OUTPUT"
414+ echo "value=website-build-v1-$sha-${{ hashFiles('scripts/res/apiDocs/**') }}" >> "$GITHUB_OUTPUT"
415+ shell : bash
416+
417+ - name : Look up website build
418+ id : website-build
419+ if : ${{ matrix.generate_api_docs }}
420+ uses : actions/cache/restore@v6
421+ with :
422+ path : tmp/website-build
423+ key : ${{ steps.website-build-key.outputs.value }}
424+ lookup-only : true
425+
426+ - name : Checkout rescript-lang.org
427+ if : ${{ matrix.generate_api_docs && steps.website-build.outputs.cache-hit != 'true' }}
399428 uses : actions/checkout@v7
400429 with :
401430 repository : rescript-lang/rescript-lang.org
402- ref : ${{ steps.api-docs-plan .outputs.website-branch }}
431+ ref : ${{ steps.website-build-key .outputs.sha }}
403432 path : rescript-lang.org
404433
405- - name : Check for API docs changes
406- id : api-docs-diff
407- if : ${{ matrix.generate_api_docs }}
408- run : |
409- cp -R scripts/res/apiDocs/. rescript-lang.org/data/api/
410- git -C rescript-lang.org status
411- if [[ -z "$(git -C rescript-lang.org status --porcelain)" ]]; then
412- echo "changed=false" >> "$GITHUB_OUTPUT"
413- else
414- echo "changed=true" >> "$GITHUB_OUTPUT"
415- fi
416- shell : bash
417-
418434 # The website is checked out inside this repository, so its Yarn also
419435 # reads this repository's .yarnrc.yml and rejects the settings it does
420436 # not know yet. The steps that need this config are done.
421437 - name : Hide the compiler's Yarn config from the website
422- if : ${{ matrix.generate_api_docs && steps.api-docs-diff .outputs.changed = = 'true' }}
438+ if : ${{ matrix.generate_api_docs && steps.website-build .outputs.cache-hit ! = 'true' }}
423439 run : mv .yarnrc.yml "$RUNNER_TEMP/rescript.yarnrc.yml"
424440 shell : bash
425441
426442 - name : Use Node.js for website
427- if : ${{ matrix.generate_api_docs && steps.api-docs-diff .outputs.changed = = 'true' }}
443+ if : ${{ matrix.generate_api_docs && steps.website-build .outputs.cache-hit ! = 'true' }}
428444 uses : actions/setup-node@v7
429445 with :
430446 cache : yarn
431447 cache-dependency-path : rescript-lang.org/yarn.lock
432448 node-version-file : rescript-lang.org/.node-version
433449
434450 - name : Build website with the API docs
435- if : ${{ matrix.generate_api_docs && steps.api-docs-diff .outputs.changed = = 'true' }}
451+ if : ${{ matrix.generate_api_docs && steps.website-build .outputs.cache-hit ! = 'true' }}
436452 run : |
453+ cp -R ../scripts/res/apiDocs/. data/api/
437454 yarn
438455 yarn build
439456 working-directory : rescript-lang.org
457+ shell : bash
458+
459+ - name : Record website build
460+ if : ${{ matrix.generate_api_docs && steps.website-build.outputs.cache-hit != 'true' }}
461+ run : mkdir -p tmp/website-build && echo "$KEY" > tmp/website-build/key
462+ env :
463+ KEY : ${{ steps.website-build-key.outputs.value }}
464+ shell : bash
465+
466+ - name : Save website build record
467+ if : ${{ matrix.generate_api_docs && steps.website-build.outputs.cache-hit != 'true' }}
468+ uses : actions/cache/save@v6
469+ with :
470+ path : tmp/website-build
471+ key : ${{ steps.website-build-key.outputs.value }}
440472
441473 # Compares the words the compiler allocates on fixed inputs, and the
442474 # instructions it executes on some of them, with the base branch
0 commit comments