forked from thoth-tech/SplashkitOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
259 lines (230 loc) · 10.4 KB
/
static.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: Deploy current 'deployed'/PR previews
on:
# Runs on pushes targeting the default branch
push:
branches: ["deployed", "main"]
pull_request_target: # use trusted workflow (as opposed to `pull_request`)
types:
- opened
- reopened
- synchronize
- closed
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
permissions: {}
# 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:
# 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: setup compilation env
working-directory: ./
run: |
sudo apt-get -qq update
sudo apt-get install -y build-essential cmake
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install 3.1.48
env:
GITHUB_TOKEN: ''
- name: Checkout
uses: actions/checkout@v4
with:
path: splashkitonline
submodules: 'true'
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
env:
GITHUB_TOKEN: ''
- name: compile binaries
working-directory: ./
run: |
cd emsdk
./emsdk activate 3.1.48
source ./emsdk_env.sh
wget -O ../splashkitonline/SplashKitWasm/prebuilt/sysroot.zip https://github.com/WhyPenguins/SplashkitOnline/tree/cxx_language_backend_binaries/SplashKitWasm/prebuilt/sysroot.zip
cd ../splashkitonline/SplashKitWasm/cmake/
emcmake cmake -G "Unix Makefiles" -DENABLE_CPP_BACKEND=ON .
emmake make -j8
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
rm -rf external/js-lzma/data
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: ''
- 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, merges it in to `site-builds` in its respective folder,
# and deploys.
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
pages: write
id-token: write
pull-requests: write
environment:
name: static-site
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- 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: ./built-site
- name: Or make an empty folder... # Note: Git will ignore empty folders when commiting
if: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }}
run: mkdir -p built-site
- name: Checkout Site Builds
uses: actions/checkout@v4
with:
path: site-builds
submodules: 'false'
ref: site-builds
- name: Upload Built Archive
working-directory: ./site-builds
env:
action: ${{ github.event.action }}
event: ${{ github.event_name }}
pr: ${{ github.event.number }}
ref: ${{ github.ref_name }}
run: |
git checkout --orphan new-site-builds site-builds
# clean the directory - delete everything except for pr-previews and .git, a bit hacky really...
mkdir -p ./pr-previews
mkdir -p ./branch-previews
mv ./pr-previews ../
mv ./branch-previews ../
mv ./.git ../
cd ../ && rm -rf site-builds && mkdir site-builds && cd site-builds
mv ../.git ./.git
mv ../pr-previews ./pr-previews
mv ../branch-previews ./branch-previews
# move the new build in!
if [ "${event}" == "push" ]; then
echo "Branch! ${ref}"
mkdir -p "./branch-previews/${ref}" # also creates parent directories
rm -rf "./branch-previews/${ref}"
mv ../built-site "./branch-previews/${ref}"
elif [ "${event}" == "pull_request_target" ]; then
echo "PR! ${pr}"
rm -rf "./pr-previews/${pr}"
if [ "${action}" != "closed" ]; then
mv ../built-site "./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 --force
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: Structure Deployment # Put everything inside the `deployed` branch's folder
working-directory: ./site-builds
run: |
mkdir -p "./branch-previews/deployed" # just in case
mv "./branch-previews/deployed" ../deployed
mv ./* ../deployed/
- name: Checkout de-duplicate script # This way it's safe...
uses: actions/checkout@v4
with:
path: script
sparse-checkout: |
.github/workflows/generate_pr_map.py
sparse-checkout-cone-mode: false
- 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
- name: Leave a link to 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: |