diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79a69597525..fdc74633b3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: outputs: stackgl_modules: ${{ steps.check.outputs.stackgl_modules }} topojson: ${{ steps.check.outputs.topojson }} + regl_codegen: ${{ steps.check.outputs.regl_codegen }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: @@ -42,6 +43,9 @@ jobs: if git diff --name-only "$BASE"...HEAD -- stackgl_modules/ | grep -q .; then echo "stackgl_modules=true" >> "$GITHUB_OUTPUT" fi + if git diff --name-only "$BASE"...HEAD -- src/traces/scattergl/ src/traces/scatterpolargl/ src/traces/splom/ src/traces/parcoords/ src/lib/prepare_regl.js stackgl_modules/ devtools/regl_codegen/ | grep -q .; then + echo "regl_codegen=true" >> "$GITHUB_OUTPUT" + fi # ============================================================ # Root build job - all dependent jobs fan out from here @@ -753,3 +757,43 @@ jobs: name: topojson-dist retention-days: 7 path: topojson/dist/ + + check-regl-codegen: + needs: [detect-changes, install-and-cibuild] + if: needs.detect-changes.outputs.regl_codegen == 'true' + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + - uses: ./.github/actions/setup-workspace + - uses: ./.github/actions/setup-chrome + + - name: Run regl codegen + run: | + node devtools/regl_codegen/server.mjs & + SERVER_PID=$! + until curl -sf -o /dev/null http://localhost:3000/build/regl_codegen-bundle.js 2>/dev/null; do + sleep 1 + done + $CHROME_BIN --headless=new --no-sandbox --enable-unsafe-swiftshader --ignore-gpu-blocklist http://localhost:3000/devtools/regl_codegen/index.html & + wait $SERVER_PID + + - name: Check regl precompiled shaders are up to date + run: | + if ! git diff --exit-code src/generated/regl-codegen/ src/traces/scattergl/regl_precompiled.js src/traces/scatterpolargl/regl_precompiled.js src/traces/splom/regl_precompiled.js src/traces/parcoords/regl_precompiled.js; then + echo "::error::Regl precompiled shaders are out of date. Download the 'regl-codegen' artifact from this workflow run and commit the updated files to this pull request." + exit 1 + fi + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + name: Upload updated regl codegen files + if: failure() + with: + name: regl-codegen + retention-days: 7 + path: | + src/generated/regl-codegen/ + src/traces/scattergl/regl_precompiled.js + src/traces/scatterpolargl/regl_precompiled.js + src/traces/splom/regl_precompiled.js + src/traces/parcoords/regl_precompiled.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d7cfa2bd96c..1a089e31387 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -163,18 +163,31 @@ npm run schema #### Step 9: REGL - Review & commit potential changes to precompiled regl shaders If you are implementing a new feature that involves regl shaders, or if you are -making changes that affect the usage of regl shaders, you would need to run +making changes that affect the usage of regl shaders, you would need to regenerate the precompiled regl shader code. + +This is needed because regl performs codegen in runtime which breaks CSP +compliance, and so for strict builds we pre-generate regl shader code here. + +The CI pipeline will automatically detect when regl-related files have changed and +run the codegen process. If the precompiled shaders are out of date, the +`check-regl-codegen` job will fail and upload a `regl-codegen` artifact containing +the updated files. To fix this: + +1. Download the `regl-codegen` artifact from the failed workflow run +2. Copy the updated files into your working tree +3. Commit and push the changes to your pull request + +Alternatively, you can regenerate the code locally by running: ```bash npm run regl-codegen ``` -to regenerate the regl code. This will prompt you to open a browser window. This will then run through all -traces with 'regl' in the tags, and store the captured code into -[src/generated/regl-codegen](https://github.com/plotly/plotly.js/blob/master/src/generated/regl-codegen). If no updates are necessary, it will be a no-op, but if there are changes, you will need to commit them. - -This is needed because regl performs codegen in runtime which breaks CSP -compliance, and so for strict builds we pre-generate regl shader code here. +This will prompt you to open a browser window, run through all traces with 'regl' +in the tags, and store the captured code into +[src/generated/regl-codegen](https://github.com/plotly/plotly.js/blob/master/src/generated/regl-codegen). +If no updates are necessary, it will be a no-op, but if there are changes, you +will need to commit them. #### Other npm scripts that may be of interest in development