ci: don't upload debug build to cf, too big, and a bunch of fixes #135
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build | |
on: push | |
env: | |
CARGO_TERM_COLOR: always | |
EMSCRIPTEN_VERSION: 3.1.39 | |
GODOT_VERSION: 4.2.2 | |
GODOT_PROJECT_PATH: godot | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
lint-rust: | |
name: Lint Rust | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Cache | |
uses: Swatinem/rust-cache@v2 | |
with: | |
workspaces: | | |
rust | |
- name: Clippy | |
run: | | |
cd rust | |
cargo clippy | |
- name: rustfmt | |
run: | | |
cd rust | |
cargo fmt --check | |
build-rust: | |
strategy: | |
fail-fast: false | |
matrix: | |
build_type: [release, debug] | |
platform: | |
- build_for: linux-x86_64 | |
os: ubuntu-22.04 | |
target: x86_64-unknown-linux-gnu | |
bin: libblocks_plus_plus.so | |
- build_for: wasm32 | |
os: ubuntu-22.04 | |
target: wasm32-unknown-emscripten | |
bin: blocks_plus_plus.wasm | |
- build_for: windows-x86_64 | |
os: windows-2022 | |
target: x86_64-pc-windows-msvc | |
bin: blocks_plus_plus.dll | |
- build_for: macos-x86_64 | |
os: macos-14 | |
target: x86_64-apple-darwin | |
bin: libblocks_plus_plus.dylib | |
- build_for: macos-aarch64 | |
os: macos-14 | |
target: aarch64-apple-darwin | |
bin: libblocks_plus_plus.dylib | |
name: Build Rust ${{ matrix.platform.build_for }} ${{ matrix.build_type }} | |
runs-on: ${{ matrix.platform.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Emscripten | |
if: contains(matrix.platform.target, 'wasm') | |
uses: mymindstorm/setup-emsdk@v14 | |
with: | |
version: ${{env.EMSCRIPTEN_VERSION}} | |
actions-cache-folder: 'emsdk-cache' | |
- name: Cache | |
uses: Swatinem/rust-cache@v2 | |
with: | |
workspaces: | | |
rust | |
- name: Build | |
uses: houseabsolute/actions-rust-cross@v0 | |
with: | |
target: ${{ matrix.platform.target }} | |
command: build | |
args: "--locked ${{ matrix.build_type == 'release' && '--release' || ' '}} ${{ contains(matrix.platform.target, 'wasm') && '-Zbuild-std' || ' '}}" | |
strip: true | |
working-directory: rust | |
toolchain: ${{ contains(matrix.platform.target, 'wasm') && 'nightly' || 'stable' }} | |
- name: Upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: rust-${{ matrix.platform.build_for }}-${{ matrix.build_type }} | |
path: rust/target/${{ matrix.platform.target }}/${{ matrix.build_type }}/${{ matrix.platform.bin }} | |
build-godot: | |
# Inspired by https://github.com/abarichello/godot-ci | |
strategy: | |
fail-fast: false | |
matrix: | |
build_type: [release, debug] | |
platform: | |
- build_for: linux-x86_64 | |
export: linux_x11 | |
target: x86_64-unknown-linux-gnu | |
export_name: blocks-plus-plus.x86_64 | |
- build_for: wasm32 | |
export: web | |
target: wasm32-unknown-emscripten | |
export_name: index.html | |
- build_for: windows-x86_64 | |
export: windows | |
target: x86_64-pc-windows-msvc | |
export_name: blocks-plus-plus.exe | |
- build_for: macos-x86_64 | |
export: macos | |
target: x86_64-apple-darwin | |
export_name: blocks-plus-plus.zip | |
# - build_for: macos-aarch64 | |
# export: Mac OSX??? | |
# target: aarch64-apple-darwin | |
# bin: libblocks_plus_plus.dylib | |
needs: [lint-rust, build-rust] | |
runs-on: ubuntu-22.04 | |
name: Build Godot ${{ matrix.platform.export }} ${{ matrix.build_type }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
lfs: true | |
- name: Setup Godot | |
uses: chickensoft-games/setup-godot@v1 | |
with: | |
version: ${{ env.GODOT_VERSION }}-stable | |
use-dotnet: false | |
path: godot-bin | |
- name: Download rust bin | |
uses: actions/download-artifact@v4 | |
with: | |
name: rust-${{ matrix.platform.build_for }}-${{ matrix.build_type }} | |
path: rust/target/${{ matrix.platform.target }}/${{ matrix.build_type }}/ | |
- name: Download rust linux bin # We always need the bin for the platform we're running on, in the debug dir | |
uses: actions/download-artifact@v4 | |
with: | |
name: rust-linux-x86_64-debug | |
path: rust/target/x86_64-unknown-linux-gnu/debug/ | |
- name: Download custom templates | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow: compile_godot.yaml | |
workflow_search: true | |
workflow_conclusion: success | |
name: templates-${{ env.GODOT_VERSION }} | |
path: /home/runner/.local/share/godot/export_templates/${{ env.GODOT_VERSION }}.stable/ | |
- name: Build | |
run: | | |
tree /home/runner/.local/share/godot | |
mkdir -v -p build/${{ matrix.platform.build_for }} | |
cd $GODOT_PROJECT_PATH | |
godot --headless --verbose ${{ matrix.build_type == 'release' && '--export-release' || '--export-debug'}} ${{ matrix.platform.export }} ../build/${{ matrix.platform.build_for }}/${{ matrix.platform.export_name }} | |
env: | |
GODOT_URL: https://godot-engine.static.ilus.pw/index.side.wasm | |
- name: Upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.platform.build_for }}-${{ matrix.build_type }} | |
path: build/${{ matrix.platform.build_for }} | |
publish-web: | |
strategy: | |
fail-fast: false | |
matrix: | |
build_type: [release] # debug blocks_plus_plus.wasm is 62.4 MiB and I'm not uploading more stuff to R2 | |
runs-on: ubuntu-22.04 | |
environment: main | |
name: Publish Web ${{ matrix.build_type }} | |
needs: [build-godot] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download Web build | |
uses: actions/download-artifact@v4 | |
with: | |
name: wasm32-${{ matrix.build_type }} | |
path: wasm32 | |
- name: Prepare cloudflare publish | |
run: | | |
cp deploy/cloudflare-pages/* wasm32/ | |
# exclude the engine file from cloudflare pages because it's too big | |
export engine_hash=($(sha256sum wasm32/index.side.wasm)) | |
rm wasm32/index.side.wasm | |
# ugly hack to force godot to pull the engine from another domain | |
export build_type=${{ matrix.build_type }} | |
sed -i -e "s|{{{DIR}}}|${build_type}_${GODOT_VERSION}_${engine_hash[0]}|g" deploy/templates/readAsyncNew | |
sed -i -e '/readAsync = (url, onload, onerror) => {/{r deploy/templates/readAsyncNew' -e 'd;}' wasm32/index.js | |
- name: Publish to Cloudflare Pages | |
uses: cloudflare/pages-action@v1 | |
with: | |
apiToken: ${{ secrets.PAGES_API_TOKEN }} | |
accountId: ${{ secrets.PAGES_ACCOUNT_ID }} | |
projectName: blocks-plus-plus | |
directory: wasm32 | |
wranglerVersion: '3' | |
branch: ${{ matrix.build_type == 'release' && ' ' || 'debug_'}}${{ github.head_ref || github.ref_name }} |