Skip to content

Commit

Permalink
deploy github pages
Browse files Browse the repository at this point in the history
  • Loading branch information
pranabdas committed Nov 16, 2022
1 parent f8e49b1 commit d9a65e9
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 45 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/gh-pages-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy gh-pages

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-22.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

steps:
- uses: actions/checkout@v3

- name: Prepare Node environment
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Prepare and build everything
run: bash build.sh

- name: Deploy on gh-pages
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ bash setup.sh
Or create new rust lib:
```console
cargo new rust-libs --lib
cd rust-libs
cargo add wasm-bindgen
```

Move in to our `rust-libs` directory and build the rust libs:
```console
cd wasm-rust-libs
wasm-pack build --target web
```

Notice the `Cargo.toml` spec and add rust byproducts in `.gitignore`.
Change crate-type in `Cargo.toml` and add rust byproducts in `.gitignore`.
```rs
[lib]
crate-type = ["cdylib"]
```
Run:

Build the rust libs:
```console
wasm-pack build --target web
```

Install/add package to npm:
```
npm i ./rust-libs/pkg
```
Expand Down
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
sudo apt update
sudo apt install -y curl
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | bash
cargo install cargo-generate
cd rust-libs
wasm-pack build --target web
cd ..
npm i
npm run build
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "wasm-rust-react",
"homepage": ".",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down
49 changes: 12 additions & 37 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="A React application using WebAssemby generated from Rust code." />
<title>React Wasm App</title>
</head>

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

0 comments on commit d9a65e9

Please sign in to comment.