Skip to content

Update static.yml

Update static.yml #26

Workflow file for this run

name: Deploy current `deploy` _and_ PR previews
on:
# Runs on pushes targeting the default branch
push:
branches: ["deployed"]
pull_request:
types:
- opened
- reopened
- synchronize
- closed
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
pages: write
id-token: write
pull-requests: write
# Allow only one concurrent deployment per PR, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: preview-${{ github.ref }}
# cancel-in-progress: false
jobs:
# Updates the `site-builds` branch with the new build
build:
environment:
name: static-site
url: ${{ steps.deployment.outputs.page_url }}
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: 'true'
env:
GITHUB_TOKEN: ''
- name: npm install
working-directory: ./splashkitonline/Browser_IDE
run: |
npm install
env:
GITHUB_TOKEN: ''
- name: shuffle folders
working-directory: ./splashkitonline/Browser_IDE
run: |
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
mv ../DemoProjects DemoProjects
env:
GITHUB_TOKEN: ''
- name: download binaries
working-directory: ./splashkitonline/Browser_IDE #python3 ./setup.py
run: |
wget -O splashkit/splashkit_autocomplete.json https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/splashkit/splashkit_autocomplete.json
wget -O runtimes/javascript/bin/SplashKitBackendWASM.js https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/runtimes/javascript/bin/SplashKitBackendWASM.js
wget -O runtimes/javascript/bin/SplashKitBackendWASM.wasm https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/runtimes/javascript/bin/SplashKitBackendWASM.wasm
wget -O compilers/cxx/bin/wasi-sysroot.zip.lzma https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/wasi-sysroot.zip.lzma
wget -O compilers/cxx/bin/clang++.js https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/clang++.js
wget -O compilers/cxx/bin/clang.wasm.lzma https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/clang.wasm.lzma
wget -O compilers/cxx/bin/wasm-ld.js https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/wasm-ld.js
wget -O compilers/cxx/bin/lld.wasm.lzma https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/compilers/cxx/bin/lld.wasm.lzma
wget -O runtimes/cxx/bin/SplashKitBackendWASMCPP.js https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/runtimes/cxx/bin/SplashKitBackendWASMCPP.js
wget -O runtimes/cxx/bin/SplashKitBackendWASMCPP.worker.js https://raw.githubusercontent.com/WhyPenguins/SplashkitOnline/github-live/Browser_IDE/runtimes/cxx/bin/SplashKitBackendWASMCPP.worker.js
env:
GITHUB_TOKEN: ''
# At this point any scripts that exist in the filesystem _cannot_ be trusted
# But I think (...?) if we do everything in the workflow from here on,
# it should be safe and be unable to trash the live site. I think anyway...
# - name: Create Build Archive
# run: tar -c --lzma -f deployed.tar.gz ./Browser_IDE # ${{ inputs.pr-number }}
- name: Checkout Site Builds
uses: actions/checkout@v4
with:
path: site-builds
ref: site-builds
- name: Upload Built Archive
working-directory: ./site-builds
env:
action: ${{ github.event.action }}
event: ${{ github.event_name }}
pr: ${{ github.event.number }}
run: |
git checkout --orphan new-site-builds site-builds
# move the new build in!
echo "Event! ${event}"
echo "Action! ${action}"
if [ "${event}" == "push" ]; then
# clean the directory - delete everything except for pr-previews and .git, a bit hacky really...
mkdir -p ./pr-previews
mv ./pr-previews ../
mv ./.git ../
cd ../ && rm -rf site-builds && mkdir site-builds && cd site-builds
mv ../.git ./.git
mv ../pr-previews ./pr-previews
echo "Deploy!"
mv ../splashkitonline/Browser_IDE/* ./
elif [ "${event}" == "pull_request" ]; then
echo "PR! ${pr}"
rm -rf "./pr-previews/${pr}"
if [ "${action}" != "closed" ]; then
mkdir -p "./pr-previews/${pr}"
mv ../splashkitonline/Browser_IDE/* ./pr-previews/${pr}/
fi
fi
# commit!
git config --global user.email "buildbot@bot.bot"
git config --global user.name "build-bot-bob"
git add --all
git commit -m "Update builds"
git branch -M new-site-builds site-builds
# TODO: This is race condition, if there are two simultaneous PRs only one will survive...
git push origin site-builds --force-with-lease
repoSiteURL=$(echo ${{ github.repository }} | sed 's/\//.github.io\//')
echo "repoSiteURL=$repoSiteURL" >> $GITHUB_ENV
- name: Leave a link to the PR
if: ${{ success() && github.event_name == 'pull_request' && github.event.action != 'closed' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
message: |
# PR Preview!
Preview at https://${{ env.repoSiteURL }}/pr-previews/${{ github.event.number }} for commit ${{ github.sha }}
- name: Or delete the link...
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-preview
delete: true
message: |
# PR Preview Removed
deploy:
environment:
name: static-site
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'false'
ref: site-builds
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload IDE site
path: './'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4