Skip to content

Commit

Permalink
Add deployment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Canleskis committed Jan 15, 2024
1 parent 02a3262 commit 563bc4c
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 2 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy

on:
push:
branches: ["main"]
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Checkout Particular
uses: actions/checkout@v4
with:
repository: canleskis/particular
path: particular

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown

- name: Setup wasm-bindgen
uses: jetli/wasm-bindgen-action@v0.2.0
with:
version: "0.2.89"

- uses: Swatinem/rust-cache@v2
with:
workspaces: particular -> target

- name: Deploy Benchmarks
run: |
bash scripts/deploy_benchmarks.sh content/benchmarks
- name: Deploy Examples
run: |
bash scripts/deploy_showcase.sh
- name: Deploy Site
uses: shalzz/zola-deploy-action@v0.17.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
.idea

public
content/demos/*
# ignore subdirectories but not files
content/demos/*/
content/benchmarks/*.json
5 changes: 5 additions & 0 deletions content/demos/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
+++
title = "Demos"
template = "demos.html"
sort_by = "title"
+++
14 changes: 14 additions & 0 deletions scripts/deploy_benchmarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Add all the benchmarks to a list in single json file.

out_dir=$1
name=${2:-"benchmarks"}
particular_dir=${3:-"particular"}

buffer=""

for file in $particular_dir/particular/benches/results/*.json; do
buffer+=$(cat "$file")
buffer+=","
done

echo "[${buffer%?}]" > $out_dir/$name.json
20 changes: 20 additions & 0 deletions scripts/deploy_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
path=$1
out_dir=$2
particular_dir=$3

metadata=$(grep -A3 "\[package.metadata.particular.rs\]" $path/Cargo.toml | grep -vE "^(#|\[)")

if [ -n "$metadata" ]; then
name=$(basename $path)

RUSTFLAGS='-C target-feature=+simd128' cargo build -p $name --release --target wasm32-unknown-unknown --manifest-path $particular_dir/Cargo.toml
wasm-bindgen --no-typescript --out-name example --out-dir $out_dir/$name --target web $particular_dir/target/wasm32-unknown-unknown/release/$name.wasm

cp $path/preview.png $out_dir/$name/preview.png
cp -r $path/assets $out_dir/$name/assets 2>/dev/null

echo '+++
'"$metadata"'
template = "demo.html"
+++' >$out_dir/$name/index.md
fi
7 changes: 7 additions & 0 deletions scripts/deploy_showcase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
particular_dir=${1:-"particular"}

for subfolder in $particular_dir/examples/*; do
if [ -d $subfolder ]; then
bash scripts/deploy_example.sh $subfolder content/demos $particular_dir
fi
done
1 change: 0 additions & 1 deletion templates/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import init from "./example.js";

const response = await fetch("example_bg.wasm");

const transform = new TransformStream({
flush() {
setTimeout(
Expand Down

0 comments on commit 563bc4c

Please sign in to comment.