Skip to content

Commit

Permalink
feat: actions and format
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Jul 24, 2024
1 parent bf95113 commit c76545b
Show file tree
Hide file tree
Showing 15 changed files with 604 additions and 27 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Based on https://github.com/bevyengine/bevy_github_ci_template/blob/main/.github/workflows/ci.yaml
name: ci

on:
push:
branches: [main, dev]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
clippy_fmt:
name: Cargo clippy and fmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install nix
uses: nixbuild/nix-quick-install-action@v28

- name: Use nix flake
uses: nicknovitski/nix-develop@v1

- name: Rust cache
uses: leafwing-studios/cargo-cache@v2

- name: Cargo clippy
run: cargo clippy --workspace --all-targets --all-features -- -Dwarnings --no-deps

- name: Cargo fmt
run: cargo fmt --all -- --check

check_toml:
name: Toml check
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install nix
uses: nixbuild/nix-quick-install-action@v28

- name: Run Taplo
run: nix run nixpkgs#taplo fmt -- --check --diff

test:
name: Cargo test
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install nix
uses: nixbuild/nix-quick-install-action@v28

- name: Use nix flake
uses: nicknovitski/nix-develop@v1

- name: Rust cache
uses: leafwing-studios/cargo-cache@v2

- name: Cargo test
run: cargo test --workspace

- name: Cargo check examples
run: cargo check --workspace --examples

- name: Cargo check main
run: cargo check --workspace

test_release:
name: Cargo test (release)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install nix
uses: nixbuild/nix-quick-install-action@v28

- name: Use nix flake
uses: nicknovitski/nix-develop@v1

- name: Rust cache
uses: leafwing-studios/cargo-cache@v2

- name: Cargo test
run: cargo test --workspace --release --no-default-features --features release

- name: Cargo check examples
run: cargo check --workspace --examples --release --no-default-features --features release

- name: Cargo check main
run: cargo check --workspace --release --no-default-features --features release
211 changes: 211 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# Based on https://github.com/bevyengine/bevy_github_ci_template/blob/main/.github/workflows/release.yaml
# and on https://github.com/TheBevyFlock/bevy_quickstart/blob/main/.github/workflows/release.yaml
# For cache to work in tags, you need to create it first in main, this should be handled automatically
# Note that main runs of this workflow will only create the cache and not the actual release
name: release

on:
push:
branches: [main, dev]
tags: [ "*[0-9]+.[0-9]+" ]
workflow_dispatch:
inputs:
version:
description: "Version as '<anything>0.1'"
required: true
type: string

env:
binary: game # This needs to match the project name in Cargo.toml
itch_target: eerii/hello-bevy # If you want to deploy to itch, set this as your username/project-url
features: "release" # Add features here if you need them
optimize: false # This produces a smaller and faster web build, but it takes a long time

jobs:
get-version:
runs-on: ubuntu-latest
steps:
- name: Get tag
id: tag
run: echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
outputs:
version: ${{ inputs.version || steps.tag.outputs.tag }}

build:
needs: get-version
env:
version: ${{needs.get-version.outputs.version}}

strategy:
fail-fast: false
matrix:
include:
- platform: wasm
runner: ubuntu-latest
targets: wasm32-unknown-unknown
nix: .#web
profile: release-web

- platform: linux
runner: ubuntu-latest
targets: x86_64-unknown-linux-gnu
nix: .#default
profile: release

- platform: windows
runner: windows-latest
targets: x86_64-pc-windows-msvc
nix: ''
profile: release

- platform: macos
runner: macos-13
targets: x86_64-apple-darwin # Disabled for now, build failing aarch64-apple-darwin
nix: .#default
profile: release
out_dir_suffix: .app/Contents/MacOS

runs-on: ${{ matrix.runner }}

defaults:
run:
shell: bash

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install nix
if: ${{ matrix.nix != '' }}
uses: nixbuild/nix-quick-install-action@v28

- name: Use nix flake
if: ${{ matrix.nix != '' }}
uses: nicknovitski/nix-develop@v1
with:
arguments: ${{ matrix.nix }}

- name: Install Rust toolchain (not nix)
if: ${{ matrix.nix == '' }}
uses: dtolnay/rust-toolchain@nightly
with:
targets: ${{ matrix.targets }}

- name: Set rust linker (windows)
if: ${{ matrix.platform == 'windows' }}
run: |
echo "RUSTFLAGS=$RUSTFLAGS -Clinker=rust-lld.exe" >> $GITHUB_ENV
- name: Rust cache
id: cache
uses: leafwing-studios/cargo-cache@v2

- name: Build
if: ${{ github.ref_name != 'main' || steps.cache.outputs.cache-hit != 'true' }} # Skip if cache is a hit on main
run: |
for target in ${{ matrix.targets }}; do
cargo build --profile='${{ matrix.profile }}' --target="${target}" --no-default-features --features='${{ env.features }}'
done
- name: Prepare package (linux and windows)
if: ${{ (matrix.platform == 'linux' || matrix.platform == 'windows') && github.ref_name != 'main' }}
run: |
mkdir ${{ matrix.platform }}
cp target/${{ matrix.targets }}/release/${{ env.binary }} ${{ matrix.platform }}/
if [ '${{ matrix.platform }}' == 'linux' ]; then
strip ${{ matrix.platform }}/${{ env.binary }}
fi
- name: Prepare package (web)
if: ${{ matrix.platform == 'wasm' && github.ref_name != 'main' }}
run: |
wasm-bindgen --no-typescript --out-name ${{ env.binary }} --out-dir wasm --target web target/${{ matrix.targets }}/release-web/${{ env.binary }}.wasm
sed -i "s/GAME/${{ env.binary }}/g" wasm/index.html
- name: Prepare package (mac)
if: ${{ matrix.platform == 'macos' && github.ref_name != 'main' }}
run: |
mkdir ${{ matrix.platform }}
# lipo -create -output ${{ env.binary }} target/aarch64-apple-darwin/release/${{ env.binary }} target/x86_64-apple-darwin/release/${{ env.binary }}
cp target/x86_64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}
mkdir -p ${{ env.binary }}.app/Contents/MacOS
cp ${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/
strip ${{ env.binary }}.app/Contents/MacOS/${{ env.binary }}
hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ matrix.platform }}/${{ env.binary }}.dmg
- name: Optimize Wasm
if: ${{ matrix.platform == 'wasm' && env.optimize == 'true' && github.ref_name != 'main' }}
working-directory: ./wasm
run: |
mv ${{ env.binary }}_bg.wasm base.wasm
wasm-opt base.wasm -o ${{ env.binary }}_bg.wasm -Os
- name: Upload binaries to artifacts
if: ${{ github.ref_name != 'main' }}
uses: actions/upload-artifact@v4
with:
path: ${{ matrix.platform }}/*
name: ${{ matrix.platform }}

- name: Package as a zip
if: ${{ matrix.platform != 'windows' && github.ref_name != 'main' }}
run: |
zip --recurse-paths ./${{ env.binary }}.zip ./${{ matrix.platform }}
- name: Package as a zip (windows)
if: ${{ matrix.platform == 'windows' && github.ref_name != 'main' }}
shell: pwsh
run: |
Compress-Archive -Path windows/* -DestinationPath ${{ env.binary }}.zip
- name: Upload binaries to release
if: ${{ github.ref_name != 'main' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.binary }}.zip
asset_name: ${{ env.binary }}-$${{ matrix.platform }}-${{ env.version }}.zip
tag: ${{ github.ref }}
overwrite: true

get-itch-target:
runs-on: ubuntu-latest
steps:
- name: Do nothing
run: 'true'
outputs:
itch-target: ${{ env.itch_target }}

upload-to-itch:
runs-on: ubuntu-latest
needs:
- get-itch-target
- build
if: ${{ needs.get-itch-target.outputs.itch-target != '' && github.ref_name != 'main' }}
env:
version: ${{ needs.get-version.outputs.version }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: builds

- name: Install butler
run: |
curl -L -o butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default
unzip butler.zip
chmod +x butler
./butler -V
- name: Upload to itch.io
env:
BUTLER_API_KEY: ${{ secrets.ITCH_API_KEY }}
run: |
echo $(ls builds)
for channel in $(ls builds); do
./butler push \
--fix-permissions \
--userversion="${{ env.version }}" \
builds/$channel \
${{ env.itch_target }}:$channel
done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.data
.direnv
.envrc
wasm/game*
18 changes: 18 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
condense_wildcard_suffixes = true
format_code_in_doc_comments = true
group_imports = "StdExternalCrate"
hex_literal_case = "Lower"
imports_granularity = "Crate"
imports_layout = "HorizontalVertical"
match_block_trailing_comma = true
newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
overflow_delimited_expr = true
reorder_impl_items = true
single_line_if_else_max_width = 100 # 50
single_line_let_else_max_width = 100 # 50
unstable_features = true
use_field_init_shorthand = true
use_try_shorthand = true
wrap_comments = true
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ common = []
[dependencies]
bevy = { version = "0.14", features = ["serialize", "wayland"] }
leafwing-input-manager = { git = "https://github.com/Leafwing-Studios/leafwing-input-manager" }
log = { version = "*", features = [
"max_level_debug",
"release_max_level_warn",
] }

[profile.dev]
opt-level = 1
Expand Down
Loading

0 comments on commit c76545b

Please sign in to comment.