name: webapps-site # Build the doc/webpacks bundles (gitignored on main; jquery-components.* and # its hashed assets stay committed — see .gitignore) and publish the `gh-pages` # branch: the full main tree (so every URL GitHub Pages served from main keeps # working, CNAME included) plus # # packages/{shex-webapp,extension-map,extension-reduce,extension-wasi,extension-shacl-sparql,extension-path-assert}/doc/webpacks/ # (the built bundles) # / experiment sites published by webapps-site-branch.yml, # carried over from the previous gh-pages commit (EXPERIMENTS) # .nojekyll (serve the tree as-is; test fixtures confuse Jekyll) # # and with the … # block (clone-local instructions) removed from /index.html. # # The repo-relative layout is preserved because everything here points at # everything else relatively: shex.html loads webpacks/shex-webapp.js, # shexmap-simple.html redirects to ../../shex-webapp/doc/shex.html with # ?plugin=, and a plugin's `scripts` # are resolved against the plugin rather than the page -- so a plugin's # bundle has to be published beside it. # # Each publish commits ON TOP of the existing gh-pages history so consumers # can update with a plain `git pull`: # - GitHub Pages (Pages source: "Deploy from a branch", gh-pages /root): # serves https://shex.js.org/ per the CNAME. # - shex.io: a clone checked out on gh-pages, updated by its /update CGI's # `git pull` loop. (tools/sync-webpacks.sh remains for main checkouts that # just want the bundles.) # The branch accumulates ~8MB of bundles per publish; to shed old history, # delete the gh-pages branch on GitHub — the next publish recreates it from # scratch (gh-pages clones then need one `git fetch origin gh-pages && # git reset --hard origin/gh-pages`). on: push: branches: [main] workflow_dispatch: # One publish per ref at a time (a newer push supersedes an in-flight one); # publishes of *different* refs -- main and the experiment branches -- still # run concurrently and settle their gh-pages contention in the push retry # loop below. (A shared group can't help here: GitHub keeps only one pending # run per group, so serializing main + N branches into one group would drop # publishes rather than queue them.) concurrency: group: gh-pages-${{ github.ref }} cancel-in-progress: true jobs: build-and-publish: runs-on: ubuntu-latest permissions: contents: write # push to the gh-pages branch steps: - uses: actions/checkout@v7 - name: clone shexTest alongside the checkout, on the ref the shex-test dependency names run: | REF=$(sed -n 's|.*"shex-test": "github:shexSpec/shexTest#\([^"]*\)".*|\1|p' package.json) git clone --depth=1 --branch="${REF:-main}" https://github.com/shexSpec/shexTest.git ../shexTest - uses: actions/setup-node@v7 with: node-version: 24 cache: npm - run: npm ci - run: npm run webpacks-all - name: publish site to the gh-pages branch run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" # Drop the clone-local notice from the landing page. sed ranges are # line-based, so the block may span any number of lines; each marker # must sit on its own line (marker lines are deleted whole). sed -i '//,//d' index.html if grep -q 'STRIP-FOR-PUBLICATION' index.html; then echo 'index.html still mentions STRIP-FOR-PUBLICATION after stripping (unbalanced markers?)' >&2 exit 1 fi touch .nojekyll # stage the full tree (`add -A` respects .gitignore, so no # node_modules) plus the ignored built bundles, and freeze it as a # tree object -- this main-side content doesn't change between push # attempts, only the gh-pages parent it grafts onto does git add -A . git add -f .nojekyll \ packages/shex-webapp/doc/webpacks packages/extension-map/doc/webpacks \ packages/extension-reduce/doc/webpacks packages/extension-wasi/doc/webpacks \ packages/extension-shacl-sparql/doc/webpacks packages/extension-path-assert/doc/webpacks OURS=$(git write-tree) # the experiment-branch sites to carry across this root rebuild: # index.html's experiment-sites data block, the same source that # renders the landing page's Experiments card EXPERIMENTS=$(node -e ' const m = require("fs").readFileSync("index.html", "utf8") .match(/id="experiment-sites">\s*([\s\S]*?)<\/script>/); process.stdout.write(m ? JSON.parse(m[1]).map(e => e.dir).join(" ") : "");') echo "carrying: $EXPERIMENTS" # Commit on top of the current gh-pages and push -- retrying if a # concurrent publish (another branch's site) moved gh-pages under # us: refetch, regraft the experiments onto the new parent, and try # again. (If the branch was deleted to shed history, PARENT is # empty and this starts it afresh.) for attempt in 1 2 3 4 5 6; do git fetch origin gh-pages || true PARENT=$(git rev-parse --verify --quiet origin/gh-pages || true) GIT_INDEX_FILE=$(mktemp); export GIT_INDEX_FILE git read-tree "$OURS" if [ -n "$PARENT" ]; then for d in $EXPERIMENTS; do if git rev-parse --verify --quiet "$PARENT:$d" >/dev/null; then git read-tree --prefix="$d/" "$PARENT:$d" fi done fi TREE=$(git write-tree) rm -f "$GIT_INDEX_FILE"; unset GIT_INDEX_FILE COMMIT=$(git commit-tree $TREE ${PARENT:+-p $PARENT} -m "webapps site built from $GITHUB_SHA") if git push origin $COMMIT:refs/heads/gh-pages; then echo "published (attempt $attempt)"; exit 0 fi echo "gh-pages moved under us (attempt $attempt); refetching and retrying" sleep $((attempt * 3)) done echo "could not publish to gh-pages after several attempts" >&2; exit 1