From 563bc4ca8424307b4f09198bded613610fe223df Mon Sep 17 00:00:00 2001 From: Canleskis <91223490+Canleskis@users.noreply.github.com> Date: Sun, 14 Jan 2024 22:11:01 +0100 Subject: [PATCH] Add deployment workflow --- .github/workflows/deploy.yaml | 45 +++++++++++++++++++++++++++++++++++ .gitignore | 3 ++- content/demos/_index.md | 5 ++++ scripts/deploy_benchmarks.sh | 14 +++++++++++ scripts/deploy_example.sh | 20 ++++++++++++++++ scripts/deploy_showcase.sh | 7 ++++++ templates/demo.html | 1 - 7 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy.yaml create mode 100644 content/demos/_index.md create mode 100644 scripts/deploy_benchmarks.sh create mode 100644 scripts/deploy_example.sh create mode 100644 scripts/deploy_showcase.sh diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..487a88c --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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 }} diff --git a/.gitignore b/.gitignore index cdad65c..2eb57b9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ .idea public -content/demos/* +# ignore subdirectories but not files +content/demos/*/ content/benchmarks/*.json diff --git a/content/demos/_index.md b/content/demos/_index.md new file mode 100644 index 0000000..5765924 --- /dev/null +++ b/content/demos/_index.md @@ -0,0 +1,5 @@ ++++ +title = "Demos" +template = "demos.html" +sort_by = "title" ++++ diff --git a/scripts/deploy_benchmarks.sh b/scripts/deploy_benchmarks.sh new file mode 100644 index 0000000..7e5a634 --- /dev/null +++ b/scripts/deploy_benchmarks.sh @@ -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 diff --git a/scripts/deploy_example.sh b/scripts/deploy_example.sh new file mode 100644 index 0000000..abb9ed6 --- /dev/null +++ b/scripts/deploy_example.sh @@ -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 diff --git a/scripts/deploy_showcase.sh b/scripts/deploy_showcase.sh new file mode 100644 index 0000000..5d8f273 --- /dev/null +++ b/scripts/deploy_showcase.sh @@ -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 diff --git a/templates/demo.html b/templates/demo.html index 970c960..17cf895 100644 --- a/templates/demo.html +++ b/templates/demo.html @@ -45,7 +45,6 @@ import init from "./example.js"; const response = await fetch("example_bg.wasm"); - const transform = new TransformStream({ flush() { setTimeout(