-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (138 loc) · 5.55 KB
/
deploy.yml
File metadata and controls
155 lines (138 loc) · 5.55 KB
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
name: Build and deploy Pixel2Polygon to GitHub Pages
on:
pull_request:
branches: ["main"]
push:
branches: ["main"]
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
name: Compile Multilingual sources to WebAssembly
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v5
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: "24"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements-build.txt
- name: Compile Multilingual sources to WebAssembly
run: python -m multilingualprogramming scripts/compile_wasm.ml
- name: Verify build artifacts
run: |
ls -la public
test -f public/index.html
test -f public/style.css
test -f public/app.js
test -f public/hexagonify.wasm
- name: Check JavaScript syntax
run: node --check public/app.js
- name: Validate WASM or fall back to JavaScript-only publish
run: |
node -e "
const fs = require('fs');
const wasmPath = 'public/hexagonify.wasm';
const watPath = 'public/hexagonify.wat';
const fallback = (message, detail) => {
console.warn(message);
if (detail) {
console.warn(detail);
}
if (fs.existsSync(wasmPath)) fs.unlinkSync(wasmPath);
if (fs.existsSync(watPath)) fs.unlinkSync(watPath);
console.log('Publishing JavaScript-only fallback.');
process.exit(0);
};
if (!fs.existsSync(wasmPath)) {
fallback('WASM artifact missing after compilation.');
}
const bytes = fs.readFileSync(wasmPath);
const module = new WebAssembly.Module(bytes);
const importObject = {};
for (const entry of WebAssembly.Module.imports(module)) {
if (!importObject[entry.module]) {
importObject[entry.module] = {};
}
if (entry.kind === 'function') {
importObject[entry.module][entry.name] = () => 0;
} else if (entry.kind === 'memory') {
importObject[entry.module][entry.name] = new WebAssembly.Memory({ initial: 16 });
} else if (entry.kind === 'table') {
importObject[entry.module][entry.name] = new WebAssembly.Table({ initial: 0, element: 'anyfunc' });
} else if (entry.kind === 'global') {
importObject[entry.module][entry.name] = new WebAssembly.Global({ value: 'i32', mutable: true }, 0);
}
}
if (!importObject.env) {
importObject.env = {};
}
WebAssembly.instantiate(module, importObject).then((instance) => {
const exports = instance.exports;
const required = [
'sommet_hex_x', 'sommet_hex_y',
'espacement_horiz', 'espacement_vert',
'hauteur_tri', 'sommet_tri_x', 'sommet_tri_y',
'generer_tuiles', 'charger_tuile', 'sortie_ptr',
'methode_hexagone', 'methode_carre', 'methode_triangle',
];
const missing = required.filter((name) => typeof exports[name] !== 'function');
if (missing.length) {
fallback('WASM exports missing.', missing.join(', '));
}
const checks = [
['sommet_hex_x', Number(exports.sommet_hex_x(0, 0, 10, 0)), 0, 0.001],
['sommet_hex_y', Number(exports.sommet_hex_y(0, 0, 10, 0)), -10, 0.001],
['espacement_horiz', Number(exports.espacement_horiz(10)), 17.320508, 0.01],
['espacement_vert', Number(exports.espacement_vert(10)), 15, 0.001],
['hauteur_tri', Number(exports.hauteur_tri(10)), 8.660254, 0.01],
['sommet_tri_x', Number(exports.sommet_tri_x(5, 10, 1, 1)), 10, 0.001],
['sommet_tri_y', Number(exports.sommet_tri_y(5, 10, 2, 0)), 13.660254, 0.01],
['methode_hexagone', Number(exports.methode_hexagone()), 0, 0.001],
['methode_carre', Number(exports.methode_carre()), 1, 0.001],
['methode_triangle', Number(exports.methode_triangle()), 2, 0.001],
];
for (const [name, actual, expected, tolerance] of checks) {
if (Math.abs(actual - expected) > tolerance) {
fallback('WASM smoke test failed.', JSON.stringify({ name, expected, actual, tolerance }));
}
}
console.log('WASM smoke test OK');
}).catch((err) => {
fallback('Could not instantiate WASM.', err && err.stack ? err.stack : String(err));
});
"
- name: Configure GitHub Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v4
with:
path: "public"
deploy:
name: Deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4