From 2fbc84091017fb909758df98a364e1f7c9028c21 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Fri, 2 May 2025 14:24:26 -0700 Subject: [PATCH 1/7] ci: publish all builds to GH Pages --- .github/workflows/ci.yml | 55 ++++++++++++++++++++++++++++++++++- .github/workflows/publish.yml | 32 -------------------- 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41e2950720..8020355ea8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,10 +87,47 @@ jobs: with: package_name: ${{ matrix.package }} + preview: + runs-on: ubuntu-latest + needs: + - build + - test + if: ${{ needs.build.outputs.any-workspace == 'true' }} + strategy: + fail-fast: false + matrix: + package: ${{ fromJSON(needs.build.outputs.packages) }} + exclude: + - package: global + - package: any-workspace + name: Test ${{ matrix.package }} + steps: + - name: Determine GitHub Pages directory name + id: branch_dir_name + run: | + if [ "$GITHUB_REF_NAME" == "develop" ]; then + echo "result=." + else + echo "result=${GITHUB_REF_NAME//[^A-Za-z0-9._-]/_}" + fi | tee --append "$GITHUB_OUTPUT" + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 + with: + name: build + path: packages + - name: Deploy ${{ matrix.package }} testing playground to GitHub Pages + uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./packages/${{ matrix.package }}/playground + destination_dir: "${{steps.branch_dir_name.outputs.result}}/${{ matrix.package }}" + full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" + results: name: Results runs-on: ubuntu-latest - needs: test + needs: + - test + - preview if: ${{ always() }} steps: - run: | @@ -109,3 +146,19 @@ jobs: exit 1 ;; esac + - run: | + case "${{ needs.preview.result }}" in + success) + echo "GitHub Pages previews published successfully." + exit 0 + ;; + skipped) + echo "Previews were unnecessary for these changes, so they were skipped." + echo "If this is unexpected, check the path filters." + exit 0 + ;; + *) + echo "Publishing GitHub Pages previews failed." + exit 1 + ;; + esac diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 35620bdfa2..41af211943 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -145,35 +145,3 @@ jobs: run: | git tag -f "${{github.event.release.tag_name}}" HEAD git push -f origin "refs/tags/${{github.event.release.tag_name}}" - - - name: Deploy scratch-svg-renderer to GitHub Pages - uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./packages/scratch-svg-renderer/playground - destination_dir: scratch-svg-renderer - full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" - - - name: Deploy scratch-render to GitHub Pages - uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./packages/scratch-render/playground - destination_dir: scratch-render - full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" - - - name: Deploy scratch-vm to GitHub Pages - uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./packages/scratch-vm/playground - destination_dir: scratch-vm - full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" - - - name: Deploy scratch-gui to GitHub Pages - uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./packages/scratch-gui/build - destination_dir: scratch-gui - full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" From 6a9aa102f30988e660728b3d98b50328c0728299 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Fri, 2 May 2025 14:44:44 -0700 Subject: [PATCH 2/7] ci: clean up stale GH Pages subdirectories --- .github/workflows/ghpages-cleanup.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/ghpages-cleanup.yml diff --git a/.github/workflows/ghpages-cleanup.yml b/.github/workflows/ghpages-cleanup.yml new file mode 100644 index 0000000000..75f6efd380 --- /dev/null +++ b/.github/workflows/ghpages-cleanup.yml @@ -0,0 +1,27 @@ +on: + schedule: + - cron: 0 0 * * 6 # midnight on Saturdays + workflow_dispatch: + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Check out GH Pages branch + uses: actions/checkout + with: + # replace `fetch-depth` with `shallow-since` if and when actions/checkout#619 (or an equivalent) gets merged + fetch-depth: 0 + ref: gh-pages + - name: Mark stale directories for removal + run: | + for dir in */; do + if [ -z "$(git log -n 1 --since "1 month ago" -- "$dir")" ]; then + git rm -r "$dir" + fi + done + git status + - name: Commit + run: "git commit -m 'chore: remove stale GH Pages branches'" + - name: Push + run: "git push" From aeba04d391db790318c5f8b6a430fb6935e74005 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Wed, 3 Sep 2025 10:11:13 -0700 Subject: [PATCH 3/7] ci: de-matrix GH Pages deploy --- .github/workflows/ci.yml | 59 ++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8020355ea8..f2946aeee6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,18 +89,9 @@ jobs: preview: runs-on: ubuntu-latest - needs: - - build - - test + needs: build if: ${{ needs.build.outputs.any-workspace == 'true' }} - strategy: - fail-fast: false - matrix: - package: ${{ fromJSON(needs.build.outputs.packages) }} - exclude: - - package: global - - package: any-workspace - name: Test ${{ matrix.package }} + name: Publish preview playgrounds to GitHub Pages steps: - name: Determine GitHub Pages directory name id: branch_dir_name @@ -114,21 +105,35 @@ jobs: with: name: build path: packages - - name: Deploy ${{ matrix.package }} testing playground to GitHub Pages + - name: Prepare playgrounds for GitHub Pages + working-directory: ./packages + run: | + mkdir -p ../pages/ + for pkg in *; do + if [ -d "${pkg}/playground" ]; then + # using symlinks is quick and artifact generation will dereference them + # if the GitHub Pages action stops dereferencing these links, we'll need to copy the files instead + ln -s "../packages/${pkg}/playground" "../pages/${pkg}" + fi + done + + # scratch-gui doesn't follow the pattern above + ln -s "../packages/scratch-gui/build" "../pages/scratch-gui" + + ls -l ../pages/ + - name: Deploy playgrounds to GitHub Pages uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./packages/${{ matrix.package }}/playground - destination_dir: "${{steps.branch_dir_name.outputs.result}}/${{ matrix.package }}" + publish_dir: ./pages + destination_dir: "${{steps.branch_dir_name.outputs.result}}" full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}" results: - name: Results + name: Test Results runs-on: ubuntu-latest - needs: - - test - - preview - if: ${{ always() }} + needs: test + if: ${{ !cancelled() }} steps: - run: | case "${{ needs.test.result }}" in @@ -146,19 +151,3 @@ jobs: exit 1 ;; esac - - run: | - case "${{ needs.preview.result }}" in - success) - echo "GitHub Pages previews published successfully." - exit 0 - ;; - skipped) - echo "Previews were unnecessary for these changes, so they were skipped." - echo "If this is unexpected, check the path filters." - exit 0 - ;; - *) - echo "Publishing GitHub Pages previews failed." - exit 1 - ;; - esac From 2333f33a00c0e69a1d81f58323a7b3a35ee385b6 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Thu, 4 Sep 2025 09:45:31 -0700 Subject: [PATCH 4/7] ci: output more info for debugging GHA --- .github/workflows/ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2946aeee6..2790291d37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,15 +27,14 @@ jobs: - name: Debug info # https://docs.github.com/en/actions/reference/security/secure-use#use-an-intermediate-environment-variable env: - GH_HEAD_REF: ${{ github.head_ref }} + # `env:` values are printed to the log even without using them in `run:` + GH_CONTEXT: ${{ toJson(github) }} run: | cat <' }} + Working directory: $(pwd) Node version: $(node --version) NPM version: $(npm --version) - GitHub ref: ${{ github.ref }} - GitHub head ref: ${GH_HEAD_REF} - Working directory: $(pwd) + Scratch environment: ${{ vars.SCRATCH_ENV || '' }} EOF - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3 From 45b4e62586e47a0f4dcc8912555f2a42157e223e Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Thu, 4 Sep 2025 09:11:42 -0700 Subject: [PATCH 5/7] ci: skip GH Pages publish from fork PRs --- .github/workflows/ci.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2790291d37..ae74091f12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,18 @@ jobs: preview: runs-on: ubuntu-latest needs: build - if: ${{ needs.build.outputs.any-workspace == 'true' }} + # We don't want to give forks free reign to publish to our GitHub Pages, so run this job only if both: + # - any workspace changed (otherwise there's no work to do) + # - and either + # - this is not a PR (so it's some other event that happened in our fork, like a push or merge group) + # - or it's a PR from our fork (not some other fork) + if: ${{ + (needs.build.outputs.any-workspace == 'true') && + ( + (!github.event.pull_request) || + (github.event.pull_request.head.repo.full_name == github.repository) + ) + }} name: Publish preview playgrounds to GitHub Pages steps: - name: Determine GitHub Pages directory name From ffe4eeaec6efd6438d55447fce93aab471159a00 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Fri, 5 Sep 2025 06:59:02 -0700 Subject: [PATCH 6/7] ci: fix missing version number for actions/checkout --- .github/workflows/ghpages-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ghpages-cleanup.yml b/.github/workflows/ghpages-cleanup.yml index 75f6efd380..5bc988456f 100644 --- a/.github/workflows/ghpages-cleanup.yml +++ b/.github/workflows/ghpages-cleanup.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out GH Pages branch - uses: actions/checkout + uses: actions/checkout@v4 with: # replace `fetch-depth` with `shallow-since` if and when actions/checkout#619 (or an equivalent) gets merged fetch-depth: 0 From d9911f75e79c6089c996a341d9cd8c36008c68ab Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Fri, 5 Sep 2025 07:04:29 -0700 Subject: [PATCH 7/7] ci: update naming in GH Pages workflow --- .github/workflows/ghpages-cleanup.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghpages-cleanup.yml b/.github/workflows/ghpages-cleanup.yml index 5bc988456f..16f3e7202c 100644 --- a/.github/workflows/ghpages-cleanup.yml +++ b/.github/workflows/ghpages-cleanup.yml @@ -1,3 +1,5 @@ +name: GitHub Pages Cleanup + on: schedule: - cron: 0 0 * * 6 # midnight on Saturdays @@ -7,7 +9,7 @@ jobs: cleanup: runs-on: ubuntu-latest steps: - - name: Check out GH Pages branch + - name: Check out GitHub Pages branch uses: actions/checkout@v4 with: # replace `fetch-depth` with `shallow-since` if and when actions/checkout#619 (or an equivalent) gets merged @@ -22,6 +24,6 @@ jobs: done git status - name: Commit - run: "git commit -m 'chore: remove stale GH Pages branches'" + run: "git commit -m 'chore: remove stale GitHub Pages branches'" - name: Push run: "git push"