Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/.trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Edit this file to manually trigger the workflow - just increase the number
1
124 changes: 124 additions & 0 deletions .github/workflows/build_static_site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
set -e
#build_static_site.sh <sha> <workflow event_name> <username/repo>

# Do we need to build?
cd ./splashkitonline
# only build if the SplashKitWasm folder has changed, or if this was a push to a branch (so branches always build)
if ! git diff --quiet $(git merge-base "origin/main" "$1").."$1" -- SplashKitWasm &>/dev/null || [ "$2" == "push" ]; then
cd ../

echo "========================================"
echo "Downloading Compilation Pre-builts (To improve...these should be buildable too)"
echo "========================================"
mkdir -p ./splashkitonline/SplashKitWasm/prebuilt/cxx/compiler/
cd ./splashkitonline/SplashKitWasm/prebuilt/cxx/compiler/
wget -O clang++.js https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/clang++.js
wget -O clang.wasm.lzma https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/clang.wasm.lzma
wget -O wasm-ld.js https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/wasm-ld.js
wget -O lld.wasm.lzma https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/lld.wasm.lzma
wget -O sysroot.zip https://github.com/WhyPenguins/SplashkitOnline/raw/refs/heads/cxx_language_backend_binaries/SplashKitWasm/prebuilt/sysroot.zip
# decompress them - silly since they'll just be re-compressed again, but it is what it is for now...
xz -d clang.wasm.lzma
xz -d lld.wasm.lzma

cd ../../../../../

echo "========================================"
echo "Set Up Compilation Environment"
echo "========================================"

sudo apt-get -qq update
sudo apt-get install -y build-essential cmake libpng-dev libcurl4-openssl-dev libsdl2-dev libsdl2-mixer-dev libsdl2-gfx-dev libsdl2-image-dev libsdl2-net-dev libsdl2-ttf-dev libmikmod-dev libbz2-dev libflac-dev libvorbis-dev libwebp-dev
git clone https://github.com/emscripten-core/emsdk.git
./emsdk/emsdk install 3.1.48


echo "========================================"
echo "Build SplashKit WASM Libraries"
echo "========================================"

cd emsdk
./emsdk activate 3.1.48
source ./emsdk_env.sh
cd ../
mkdir -p ./splashkitonline/SplashKitWasm/out/cxx/compiler/ # this one is due to a mistake in old CMakeLists, can be removed soon
# build this as well...


cd ./splashkitonline/SplashKitWasm/cmake/

emcmake cmake -G "Unix Makefiles" -DENABLE_JS_BACKEND=ON -DENABLE_CPP_BACKEND=ON -DENABLE_FUNCTION_OVERLOADING=ON -DCOMPRESS_BACKENDS=ON .
emmake make -j8

cd ../../../

else

echo "========================================"
echo "Using Precompiled Binaries from Main"
echo "========================================"

cd ../

# Rather than building, we'll just grab the compiled binaries from the main release.
# To do this, we'll copy over all completely untracked files from it, which will correctly
# handle if the PR has deleted files since branching from main.
# Perhaps there's a cleaner way :)

# first let's get a list of files _not_ to copy
cd ./splashkitonline
TRACKED_FILES=$(git log --pretty=format: --name-only --diff-filter=A -- Browser_IDE| sort - | sed '/^$/d')
EXCLUDE_FILE=$(mktemp)
echo "$TRACKED_FILES" | sed "s|^Browser_IDE||" > "$EXCLUDE_FILE"

# add some explicit excludes
echo "/codemirror-5.65.15" >> "$EXCLUDE_FILE"
echo "/jszip" >> "$EXCLUDE_FILE"
echo "/babel" >> "$EXCLUDE_FILE"
echo "/split.js" >> "$EXCLUDE_FILE"
echo "/mime" >> "$EXCLUDE_FILE"
echo "/DemoProjects" >> "$EXCLUDE_FILE"
echo "/node_modules" >> "$EXCLUDE_FILE"

cd ../

mkdir prebuilt
cd prebuilt
# Download main's latest release
wget "https://github.com/$3/releases/download/branch%2Fmain/splashkitonline-static-site-branch_main.zip"
unzip splashkitonline-static-site-branch_main.zip
rm splashkitonline-static-site-branch_main.zip
cd ../

# copy in all the untracked files!
rsync -av --progress --exclude-from="$EXCLUDE_FILE" "prebuilt/" "splashkitonline/Browser_IDE/"

fi


echo "========================================"
echo "Install Node Dependencies"
echo "========================================"
cd ./splashkitonline/Browser_IDE

npm install

cd ../../



echo "========================================"
echo "Re-Structure Static Site"
echo "========================================"
cd ./splashkitonline/Browser_IDE

# if changed, remember to update the explicit excludes above
mv node_modules/codemirror codemirror-5.65.15
mv node_modules/jszip/dist jszip
mv node_modules/@babel/standalone babel
mv node_modules/split.js/dist split.js
mv node_modules/mime/dist mime
rm -rf external/js-lzma/data
mv ../DemoProjects DemoProjects

cd ../
188 changes: 188 additions & 0 deletions .github/workflows/build_static_site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: Build Static Site

on:
# Runs on pushes targeting the default branch
push:
branches: ["deployed", "main"]

pull_request_target: # use trusted workflow (as opposed to `pull_request`)
types:
- labeled # workaround for manual triggering...if we actually start using labels this might need to be removed
- unlabeled # same
- opened
- reopened
- synchronize
- closed

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

permissions: {}

concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true

jobs:
# Creates a build of the website and uploads it as an artifact
# May be running untrusted code, so it's been given very restricted permissions
# Hopefully it can't do anything too bad...
build:
if: ${{ github.event_name != 'pull_request_target' || github.event.action != 'closed' }}
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
env:
GITHUB_TOKEN: ''

- name: Checkout
uses: actions/checkout@v4
with:
path: splashkitonline
submodules: 'recursive'
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: '0'
env:
GITHUB_TOKEN: ''

- name: Checkout scripts
uses: actions/checkout@v4
with:
path: script
sparse-checkout: |
.github/workflows/
sparse-checkout-cone-mode: false

- name: Build static site
working-directory: ./
run: |
GITHUB_SHA=${{ github.sha }}
if [ "${{ github.event_name }}" == "pull_request_target" ]; then
GITHUB_SHA="${{ github.event.pull_request.head.sha }}"
fi

cd ./splashkitonline
# only run the `build_static_site.sh` in the PR if the user changed it - otherwise use the latest in main.
if ! git diff --quiet $(git merge-base "origin/main" "$GITHUB_SHA").."$GITHUB_SHA" -- .github/workflows/ &>/dev/null; then
script_path="./splashkitonline/.github/workflows/build_static_site.sh" # use the PR's
else
script_path="./script/.github/workflows/build_static_site.sh" # use main's
fi
cd ../
echo "using $script_path"

bash "$script_path" "$GITHUB_SHA" "${{ github.event_name }}" "${{ github.repository }}"
env:
GITHUB_TOKEN: ''

- name: Upload the build as an artifact
uses: actions/upload-artifact@v4.4.3
with:
name: preview-${{ github.sha }}
path: ./splashkitonline/Browser_IDE
retention-days: 1
compression-level: 8
overwrite: true

# This part takes that artifact and uploads it as a release
# Perhaps this can be merged into the previous job - just seperated it out for
# potential security concerns (if for instance scripts in the previous job poisoned something)
# We never run the artifact here, so should be completely safe this way.
# Todo: Investigate!
deploy:
needs: build
if: ${{ always() && !failure() && !cancelled() }} # run this job even if the previous one is skipped
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
id-token: write
pull-requests: write
environment:
name: static-site
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout scripts # This way it's safe...
uses: actions/checkout@v4
with:
path: script
sparse-checkout: |
.github/workflows/
sparse-checkout-cone-mode: false

- name: Checkout Repo for Tagging
uses: actions/checkout@v4
with:
path: repo
submodules: 'false'
fetch-depth: '0'

# Note, we download it _into_ the git folder (so a .git is in a parent dir)
# The edit_release.py script will upload the assets in release_assets.txt, _relative_ to where the script is
# called from. However, it also updates tags in the repo, and so a `.git` directory needs to be somewhere.
# This is all a bit messy, but it works for now. Can be someone else's job to untangle it :P
- name: Download built site
if: ${{ github.event_name != 'pull_request_target' || github.event.action != 'closed' }}
uses: actions/download-artifact@v4.1.8
with:
name: preview-${{ github.sha }}
path: ./repo/built-site

- name: Create/Update release
if: ${{ github.event_name != 'pull_request_target' || github.event.action != 'closed' }}
working-directory: ./repo/built-site
run: |
sudo apt-get install zip sed

if [ "${{ github.event_name }}" == "pull_request_target" ]; then
echo " PR Release! ${{ github.event.number }}"
tag_name="pr/${{ github.event.number }}"
else
echo "Branch Release! ${{ github.ref_name }}"
tag_name="branch/${{ github.ref_name }}"
fi
file_name=$(echo $tag_name | sed "s#/#_#")

zip -r "../splashkitonline-static-site-$file_name.zip" ./ # note: this name is expected in download_github_site_previews.py
echo "../splashkitonline-static-site-$file_name.zip" >> ../../script/.github/workflows/release_assets.txt

python3 ../../script/.github/workflows/edit_release.py "update" "${{ secrets.GITHUB_TOKEN }}" "${{ github.repository }}" "$tag_name" "${{ github.sha }}" yes "../../script/.github/workflows/release_assets.txt" "# Static Site Build ($tag_name)\nA static build of $tag_name, used in the live deployment :smiley:"

repoSiteURL=$(echo ${{ github.repository }} | sed 's/\//.github.io\//')
echo "repoSiteURL=$repoSiteURL" >> $GITHUB_ENV

- name: Or delete the release...
if: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }}
working-directory: ./repo
run: |
echo " PR Release Delete! ${{ github.ref_name }}"
python3 ../script/.github/workflows/edit_release.py "delete" "${{ secrets.GITHUB_TOKEN }}" "${{ github.repository }}" "pr/${{ github.event.number }}"

# The following bits assume the GitHub Pages site is about to be updated with this new release preview
- name: Leave a link on the PR
if: ${{ success() && github.event_name == 'pull_request_target' && github.event.action != 'closed' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: |
| :whale2: **PR Preview!** |
| :-----: |
| Preview at https://${{ env.repoSiteURL }}/pr-previews/${{ github.event.number }} |
| for commit ${{ github.event.pull_request.head.sha }} |

- name: Or delete the link...
if: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: |
| :whale2: **PR Preview!** |
| :-----: |
| The preview is no more! |
| Congrats if this was merged! :smile: |
81 changes: 81 additions & 0 deletions .github/workflows/deploy_github_site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Assemble and Deploy Live Site

on:
workflow_run:
workflows: ['Build Static Site']
types:
- completed

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

permissions: {}

concurrency:
group: "site_build"
cancel-in-progress: true

jobs:
# This job downloads and extracts every release that has a splashkitonline-static-site-....zip asset
# It then arranges them into folders, de-duplicates large files, and deploys the result as the GitHub Pages site.
deploy:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
pull-requests: write
environment:
name: static-site
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout Scripts
uses: actions/checkout@v4
with:
path: script
sparse-checkout: |
.github/workflows/
sparse-checkout-cone-mode: false

- name: Download Built Sites
working-directory: ./
run: |
sudo apt-get install tree
python3 ./script/.github/workflows/download_github_site_previews.py "${{ github.repository }}" static-site
tree

# the directories are named based on the Git tag - let's rename them
cd static-site
mkdir -p "./branch" # just in case
mkdir -p "./pr" # just in case
mv branch branch-previews
mv pr pr-previews

- name: Structure Deployment # Put everything inside the `deployed` branch's folder
working-directory: ./static-site
run: |
mkdir -p "./branch-previews/deployed" # just in case
mv "./branch-previews/deployed" ../deployed
mv ./* ../deployed/

- name: De-duplicate # I really wish GitHub supported hardlinks at least, this would have been much less painful...and save them space!
working-directory: ./deployed
run: python3 ../script/.github/workflows/generate_pr_map.py

- name: Delete existing page artifact # allows re-run of workflow
uses: geekyeggo/delete-artifact@v5
with:
name: github-pages

- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload IDE site
path: './deployed'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
Loading
Loading