Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 59 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
Scratch environment: ${{ vars.SCRATCH_ENV || '<none>' }}
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 || '<none>' }}
EOF

- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
Expand Down Expand Up @@ -87,11 +86,64 @@ jobs:
with:
package_name: ${{ matrix.package }}

preview:
runs-on: ubuntu-latest
needs: build
# 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
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: 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: ./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
if: ${{ always() }}
if: ${{ !cancelled() }}
steps:
- run: |
case "${{ needs.test.result }}" in
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/ghpages-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: GitHub Pages Cleanup

on:
schedule:
- cron: 0 0 * * 6 # midnight on Saturdays
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- 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
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 GitHub Pages branches'"
- name: Push
run: "git push"
32 changes: 0 additions & 32 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Loading