Skip to content

Commit

Permalink
Enchance Rust CI/CD (#153)
Browse files Browse the repository at this point in the history
* Remove wee_alloc from rush

* Add Rust licensing.

* Add rust compiler to git action.

* Allow Rust Cargo.lock be checked in

* Add wasm detection

* Add workflow check compiled wasm
  • Loading branch information
yoonghan authored Mar 29, 2023
1 parent 349dfde commit 6880acd
Show file tree
Hide file tree
Showing 16 changed files with 1,043 additions and 141 deletions.
26 changes: 26 additions & 0 deletions .github/scripts/wasm-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Can't compare *.wasm file as binary compilation are different

wasm_dir_compare="./$1/"
wasm_dir=./pkg/

function cmpFile() {
fileName="${1##*/}"
echo "comparing $fileName"
cmp -b $wasm_dir_compare$fileName $wasm_dir$fileName
if [[ $? -ne 0 ]]; then
echo "Please recompile WASM with $fileName"
exit 1
fi
}

for file in ./$wasm_dir_compare/*.ts ; do
[ -L "${file%/}" ] && continue
cmpFile $file
done

for file in ./$wasm_dir_compare/*.js ; do
[ -L "${file%/}" ] && continue
cmpFile $file
done
21 changes: 21 additions & 0 deletions .github/workflows/validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,24 @@ jobs:
- name: ✅ Validate backstopjs snapshot is valid
run: chmod a+x ./.github/scripts/snapshot-check.sh && ./.github/scripts/snapshot-check.sh
shell: bash

rust:
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel previous runs
uses: styfle/cancel-workflow-action@0.11.0

- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- uses: jetli/wasm-pack-action@v0.4.0
with:
version: "latest"

- name: ⎔ Compile rust code
run: wasm-pack build --target web --out-dir pkg_compare
shell: bash

- name: ✅ Validate wasm is compiled
run: chmod a+x ./.github/scripts/wasm-check.sh && ./.github/scripts/wasm-check.sh pkg_compare
shell: bash
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ public/workbox*
#cargo, rust
/target
**/*.rs.bk
Cargo.lock
bin/
wasm-pack.log/target
126 changes: 126 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[package]
name = "snake"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = "A snake game similar to Nokia"
repository = "https://github.com/yoonghan/Walcron"
license = "Mozilla Public License Version 2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wasm-bindgen = "0.2.63"
wee_alloc = "0.4.5"

[lib]
crate-type = ["cdylib"]
Expand Down
Loading

1 comment on commit 6880acd

@vercel
Copy link

@vercel vercel bot commented on 6880acd Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.