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
85 changes: 85 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Deploy Brian2WASM Simulation to GitHub Pages

on:
push:
branches: [ main ]

permissions:
contents: write

jobs:
build-and-deploy:
runs-on: ubuntu-latest

env:
SCRIPT: path/to/your/script # 👈 set this

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install pixi
uses: prefix-dev/setup-pixi@v0.8.0
with:
cache: false

- name: Install dependencies
run: pixi install --locked

- name: Run setup
run: pixi run setup

- name: Derive folder paths
run: |
FOLDER_PATH="${SCRIPT%.py}"
FOLDER_NAME=$(basename "$FOLDER_PATH")
echo "FOLDER_PATH=$FOLDER_PATH" >> $GITHUB_ENV
echo "FOLDER_NAME=$FOLDER_NAME" >> $GITHUB_ENV

- name: Generate simulation files
run: |
python -m brian2wasm $SCRIPT --no-server
shell: pixi run bash -e {0}

- name: Fetch existing gh-pages
run: |
rm -rf public
git clone --branch gh-pages --depth 1 https://github.com/${{ github.repository }} public

- name: Copy new simulation output
run: |
rm -rf public/$FOLDER_NAME
mkdir -p public/$FOLDER_NAME
cp $FOLDER_PATH/brian.js \
$FOLDER_PATH/index.html \
$FOLDER_PATH/wasm_module.js \
$FOLDER_PATH/wasm_module.wasm \
$FOLDER_PATH/worker.js \
public/$FOLDER_NAME/

- name: Rebuild main index.html
run: |
TEMPLATE="brian2wasm/index_template.html" # 👈 Set this if you want your own template
cp "$TEMPLATE" public/index.html

LINKS=""
for d in public/*/ ; do
if [ -f "$d/index.html" ]; then
NAME=$(basename "$d")
LINKS="$LINKS <li><a href=\"$NAME/\">$NAME</a></li>
"
fi
done

sed -i "s/{{ACTOR}}/${GITHUB_ACTOR}/g" public/index.html
sed -i "/{{LINKS}}/{
s/{{LINKS}}//g
r /dev/stdin
}" public/index.html <<< "$LINKS"

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
publish_branch: gh-pages
41 changes: 41 additions & 0 deletions brian2wasm/index_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ACTOR}}'s brian2wasm simulations</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 40px auto;
max-width: 700px;
text-align: center;
background: #fafafa;
}
h1 {
font-size: 2em;
margin-bottom: 1em;
color: #222;
}
ul {
list-style: disc;
text-align: left;
display: inline-block;
font-size: 1.2em;
line-height: 1.6;
}
a {
text-decoration: none;
color: #007acc;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>{{ACTOR}}'s brian2wasm simulations</h1>
<ul>
{{LINKS}}
</ul>
</body>
</html>
2 changes: 0 additions & 2 deletions examples/non_reliability.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#source: https://brian2.readthedocs.io/en/stable/examples/non_reliability.html#example-non-reliability
from brian2 import *
import brian2wasm
set_device('wasm_standalone', directory='non_reliability')

N = 24
tau = 20*ms
Expand Down
Loading