Skip to content

Commit b77a96e

Browse files
author
AvidDollars
committed
finalize it & make GH action for deployment
1 parent 30da7f3 commit b77a96e

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Deploy WASM build to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 20
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- uses: actions/cache@v4
19+
with:
20+
path: |
21+
~/.cargo/bin/
22+
~/.cargo/registry/index/
23+
~/.cargo/registry/cache/
24+
~/.cargo/git/db/
25+
target/
26+
key: ${{ github.ref || github.run_id }}
27+
- uses: dtolnay/rust-toolchain@stable
28+
- name: Add WASM
29+
run: rustup target add wasm32-unknown-unknown
30+
- name: Install WASM bindgen CLI
31+
run: cargo install -f wasm-bindgen-cli
32+
- name: Install alsa and udev
33+
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
34+
- name: Build
35+
run: cargo build --release --target wasm32-unknown-unknown && wasm-bindgen --out-dir ./out/ --target web ./target/wasm32-unknown-unknown/release/tetris_in_rust.wasm
36+
- name: Copy
37+
run: cp -R assets out/ && cp index.html out/index.html && cp style.css out
38+
- name: Push
39+
uses: s0/git-publish-subdir-action@develop
40+
env:
41+
SQUASH_HISTORY: true
42+
REPO: self
43+
BRANCH: gh-pages # The branch name where you want to push the assets
44+
FOLDER: out # The directory where your assets are generated
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub will automatically add this - you don't need to bother getting a token
46+
MESSAGE: "Build: ({sha}) {msg}" # The commit message
47+
- name: Upload artifact
48+
uses: actions/upload-pages-artifact@v3
49+
with:
50+
path: '${{ github.event.repository.name }}/out'
51+
deploy:
52+
needs: build
53+
runs-on: ubuntu-latest
54+
permissions:
55+
pages: write
56+
id-token: write
57+
environment:
58+
name: github-pages
59+
url: 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/'
60+
steps:
61+
- name: Setup Pages
62+
uses: actions/configure-pages@v5
63+
- name: Deploy
64+
uses: actions/deploy-pages@v4

index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="style.css">
7+
<title>Tetris</title>
8+
</head>
9+
<body>
10+
<script type="module">
11+
import init from './out/tetris_in_rust.js'
12+
init()
13+
</script>
14+
</body>
15+
</html>

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
title: "Tetris".into(),
2323
name: Some("bevy.app".into()),
2424
resolution: (1920., 1080.).into(),
25+
fit_canvas_to_parent: true, // FROM: https://mevlyshkin.com/blog/bevy-github-actions/
2526
..default()
2627
}),
2728
..default()}),

style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
html,
2+
body {
3+
margin: 0;
4+
height: 100%;
5+
}

0 commit comments

Comments
 (0)