Skip to content

Commit

Permalink
Merge pull request godot-rust#526 from godot-rust/qol/examples-ci
Browse files Browse the repository at this point in the history
Integrate examples into CI
  • Loading branch information
Bromeon authored Dec 6, 2023
2 parents 6cb6895 + e170fe1 commit 83feabc
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 15 deletions.
62 changes: 62 additions & 0 deletions .github/other/check-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# Copyright (c) godot-rust; Bromeon and contributors.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

# Tests an example with Godot, by first importing it in the editor and letting it run for some time.
# Input: $exampleCrate

set -euo pipefail

# Opening in editor can take a while (import reosurces, load extensions for the first time, ...).
# Unlike EXAMPLE_TIMEOUT, this is an upper bound, after which CI job fails, so not the entire time is necessarily spent.
EXAMPLE_TIMEOUT=5
EDITOR_TIMEOUT=20

example="$1"
if [ -z "$example" ]; then
echo "::error::required argument 'example' missing."
exit 1
fi

PRE="# EXAMPLE $example |"
dir="examples/$example/godot"
logfile="stderr-$example.log"

# In .gdextension file, use paths to release artifacts.
sed -i'.bak' "s!/debug/!/release/!g" "$dir/rust.gdextension"

echo "$PRE Godot binary: $GODOT4_BIN"

# Open in editor to import resources (--quit exits once loaded).
echo "$PRE Briefly open Godot editor, to import resources..."
timeout "$EDITOR_TIMEOUT"s "$GODOT4_BIN" -e --headless --path "$dir" --quit || {
echo "::error::$PRE Godot editor failed to open in time."
exit 1
}

# Could also use `timeout -s9`, but there were some issues and this gives more control.
echo "$PRE Run example..."
$GODOT4_BIN --headless --verbose --path "$dir" 2> "$logfile" &
pid=$!

# Keep open for some time (even just main menu or so).
sleep $EXAMPLE_TIMEOUT

# Terminate (once shutdown in dodge-the-creeps is graceful without error messages, can also omit `-9`).
echo "$PRE Terminate Godot process $pid after ${EXAMPLE_TIMEOUT}s..."
kill $pid
wait $pid || true

echo "$PRE Output in stderr:"
echo "----------------------------------------------------"
cat "$logfile"
echo "----------------------------------------------------"

if grep --quiet "ERROR:" "$logfile"; then
echo "::error::$PRE Godot engine encountered errors while running."
exit 1
fi

echo "$PRE Example ran successfully."
23 changes: 23 additions & 0 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ jobs:
godot-check-header: ${{ matrix.godot-check-header }}


run-examples:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4

- name: "Install Rust"
uses: ./.github/composite/rust

# First compile, to fail early in case of compilation errors.
- name: "Compile Rust examples (release mode)"
run: cargo build --release -p dodge-the-creeps

- name: "Install Godot"
uses: ./.github/composite/godot-install
with:
artifact-name: godot-linux-4.2
godot-binary: godot.linuxbsd.editor.dev.x86_64

- name: "Run examples for short time"
run: ./.github/other/check-example.sh dodge-the-creeps


license-guard:
runs-on: ubuntu-20.04
steps:
Expand Down Expand Up @@ -354,6 +376,7 @@ jobs:
- clippy
- unit-test
- godot-itest
- run-examples
- license-guard

runs-on: ubuntu-20.04
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/minimal-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ jobs:
godot-check-header: ${{ matrix.godot-check-header }}


run-examples:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4

- name: "Install Rust"
uses: ./.github/composite/rust

# First compile, to fail early in case of compilation errors.
- name: "Compile Rust examples (release mode)"
run: cargo build --release -p dodge-the-creeps

- name: "Install Godot"
uses: ./.github/composite/godot-install
with:
artifact-name: godot-linux-4.2
godot-binary: godot.linuxbsd.editor.dev.x86_64

- name: "Run examples for short time"
run: ./.github/other/check-example.sh dodge-the-creeps


license-guard:
runs-on: ubuntu-20.04
steps:
Expand Down Expand Up @@ -248,6 +270,7 @@ jobs:
- clippy
- unit-test
- godot-itest
- run-examples
- license-guard

runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion examples/dodge-the-creeps/godot/.godot/extension_list.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
res://DodgeTheCreeps.gdextension
res://rust.gdextension
2 changes: 1 addition & 1 deletion examples/dodge-the-creeps/godot/Hud.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=3 uid="uid://ccqoreueuxdb7"]

[ext_resource type="FontFile" uid="uid://b0b6g57tsjvwg" path="res://fonts/Xolonium-Regular.ttf" id="1_poxll"]
[ext_resource type="FontFile" uid="uid://dapyvc0w1idt5" path="res://fonts/Xolonium-Regular.ttf" id="1_poxll"]

[sub_resource type="InputEventAction" id="InputEventAction_fopy7"]
action = &"start_game"
Expand Down
4 changes: 2 additions & 2 deletions examples/dodge-the-creeps/godot/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[ext_resource type="PackedScene" uid="uid://4vwrqjegqwpj" path="res://Player.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://ccqoreueuxdb7" path="res://Hud.tscn" id="4"]
[ext_resource type="AudioStream" uid="uid://ciubrqiaxnr8u" path="res://art/House In a Forest Loop.ogg" id="5"]
[ext_resource type="AudioStream" uid="uid://bs6ekw8xcvudv" path="res://art/gameover.wav" id="6"]
[ext_resource type="AudioStream" uid="uid://dayf3f2a4jdqy" path="res://art/House In a Forest Loop.ogg" id="5"]
[ext_resource type="AudioStream" uid="uid://d3ivry013w5bv" path="res://art/gameover.wav" id="6"]

[sub_resource type="Curve2D" id="1"]
_data = {
Expand Down
12 changes: 6 additions & 6 deletions examples/dodge-the-creeps/godot/Mob.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_scene load_steps=9 format=3 uid="uid://rkdnhqgf2hpj"]

[ext_resource type="Texture2D" uid="uid://cn5jn5vhjdvu0" path="res://art/enemyFlyingAlt_1.png" id="2"]
[ext_resource type="Texture2D" uid="uid://s7uqmmnastuj" path="res://art/enemyFlyingAlt_2.png" id="3"]
[ext_resource type="Texture2D" uid="uid://b1lct02v3dplm" path="res://art/enemyWalking_1.png" id="4"]
[ext_resource type="Texture2D" uid="uid://dpbmhndvgolto" path="res://art/enemyWalking_2.png" id="5"]
[ext_resource type="Texture2D" uid="uid://30ykq0j1xst3" path="res://art/enemySwimming_1.png" id="6"]
[ext_resource type="Texture2D" uid="uid://h3bbhy1mmen8" path="res://art/enemySwimming_2.png" id="7"]
[ext_resource type="Texture2D" uid="uid://5gjrxbqflj5i" path="res://art/enemyFlyingAlt_1.png" id="2"]
[ext_resource type="Texture2D" uid="uid://ckfg0wyq7pf4w" path="res://art/enemyFlyingAlt_2.png" id="3"]
[ext_resource type="Texture2D" uid="uid://eh7cjhw7wn5l" path="res://art/enemyWalking_1.png" id="4"]
[ext_resource type="Texture2D" uid="uid://6jkksg8gec57" path="res://art/enemyWalking_2.png" id="5"]
[ext_resource type="Texture2D" uid="uid://ddninc0dlt5f8" path="res://art/enemySwimming_1.png" id="6"]
[ext_resource type="Texture2D" uid="uid://b7scxor6pygwl" path="res://art/enemySwimming_2.png" id="7"]

[sub_resource type="SpriteFrames" id="1"]
animations = [{
Expand Down
8 changes: 4 additions & 4 deletions examples/dodge-the-creeps/godot/Player.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[gd_scene load_steps=12 format=3 uid="uid://4vwrqjegqwpj"]

[ext_resource type="Texture2D" uid="uid://bjxqdykvppv36" path="res://art/playerGrey_walk1.png" id="2"]
[ext_resource type="Texture2D" uid="uid://cjjq4q2w3ik86" path="res://art/playerGrey_walk2.png" id="3"]
[ext_resource type="Texture2D" uid="uid://dgx1rw0rbteg5" path="res://art/playerGrey_up1.png" id="4"]
[ext_resource type="Texture2D" uid="uid://b12jfidh1rmdj" path="res://art/playerGrey_up2.png" id="5"]
[ext_resource type="Texture2D" uid="uid://co0y23xy1j4bv" path="res://art/playerGrey_walk1.png" id="2"]
[ext_resource type="Texture2D" uid="uid://dx27fpt8s4b76" path="res://art/playerGrey_walk2.png" id="3"]
[ext_resource type="Texture2D" uid="uid://723lwa7jajhx" path="res://art/playerGrey_up1.png" id="4"]
[ext_resource type="Texture2D" uid="uid://c1fx6841eyogj" path="res://art/playerGrey_up2.png" id="5"]

[sub_resource type="SpriteFrames" id="1"]
animations = [{
Expand Down
2 changes: 1 addition & 1 deletion examples/dodge-the-creeps/godot/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is a finished version of the game featured in the 'Your first 2D game'
tutorial in the documentation. For more details, consider
following the tutorial in the documentation."
run/main_scene="res://Main.tscn"
config/features=PackedStringArray("4.1")
config/features=PackedStringArray("4.2")
config/icon="res://icon.png"

[debug]
Expand Down

0 comments on commit 83feabc

Please sign in to comment.