Skip to content

Commit

Permalink
Run tests automatically on push
Browse files Browse the repository at this point in the history
  • Loading branch information
mphe committed May 18, 2024
1 parent dc77e39 commit fd711ff
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: ⚙️ CI
on:
push:
# branches: [ master ]
paths-ignore:
- "README.md"
- "LICENSE"
- "**/*.png"
- "**/*.svg"

pull_request:
# branches: [ master ]
paths-ignore:
- "README.md"
- "LICENSE"
- "**/*.png"
- "**/*.svg"

jobs:
ci-unit-tests:
name: "⚙️ CI: Unit tests"
uses: ./.github/workflows/unit_tests.yml
with:
repo-ref: ${{ github.ref }}

111 changes: 111 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: 🔎 Unit tests
on:
workflow_call:
inputs:
godot-version:
description: Godot Engine version to use for testing.
type: string
default: 4.2.1-stable
repo-ref:
description: A commit, branch or tag to use for testing.
type: string
required: true

workflow_dispatch:
inputs:
godot-version:
description: Godot Engine version to use for testing.
type: string
default: 4.2.1-stable
repo-ref:
description: A commit, branch or tag to use for testing.
type: string
required: true

jobs:
unit-tests-linux:
name: 🔎 Unit tests - Linux
runs-on: "ubuntu-latest"
# Needs to run in a container apparently, otherwise TCP connection won' work.
container: ghcr.io/catthehacker/ubuntu:act-latest

env:
DONWLOAD_URL: https://github.com/godotengine/godot/releases/download/${{inputs.godot-version}}/Godot_v${{inputs.godot-version}}_linux.x86_64.zip
BIN: Godot_v${{inputs.godot-version}}_linux.x86_64

steps:
- name: Setup
shell: bash
run: |
apt-get update
apt-get install -y wget unzip
- name: Download Godot
shell: bash
run: |
echo "Godot version: ${{ github.event.inputs.godot-version }}"
mkdir -p bin
cd bin
wget "${DONWLOAD_URL}" -O godot.zip
unzip godot.zip
chmod u+x ${BIN}
rm godot.zip
ls -l
- name: Clone repository
uses: actions/checkout@v4
with:
path: repo
ref: ${{ inputs.repo-ref }}

- name: Run tests
shell: bash
run: |
: # Run an editor process in background, because we need its LSP server. (also first time setup, like importing resources)
./bin/${BIN} --headless --path ./repo/ --editor --lsp-port 6008 &
sleep 10
./bin/${BIN} --headless --path ./repo/ --script addons/gut/gut_cmdln.gd -gdir=res://test/ -gexit
unit-tests-windows:
name: 🔎 Unit tests - Windows
runs-on: "ubuntu-latest"
container: ghcr.io/catthehacker/ubuntu:act-latest

env:
DONWLOAD_URL: https://github.com/godotengine/godot/releases/download/${{inputs.godot-version}}/Godot_v${{inputs.godot-version}}_win32.exe.zip
BIN: Godot_v${{inputs.godot-version}}_win32.exe

steps:
- name: Setup
shell: bash
run: |
dpkg --add-architecture i386
apt-get update
apt-get install -y wget unzip wine-stable wine32
chown -R $USER: ~/.wine
- name: Download Godot
shell: bash
run: |
echo "Godot version: ${{ github.event.inputs.godot-version }}"
mkdir -p bin
cd bin
wget "${DONWLOAD_URL}" -O godot.zip
unzip godot.zip
chmod u+x ${BIN}
rm godot.zip
ls -l
- name: Clone repository
uses: actions/checkout@v4
with:
path: repo
ref: ${{ inputs.repo-ref }}

- name: Run tests
shell: bash
run: |
: # Run an editor process in background, because we need its LSP server
wine ./bin/${BIN} --headless --path ./repo/ --editor --lsp-port 6008 &
sleep 10
wine ./bin/${BIN} --headless --path ./repo/ --script addons/gut/gut_cmdln.gd -gdir=res://test/ -gexit
9 changes: 6 additions & 3 deletions addons/diagnosticlist/LSPClient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,28 @@ func disconnect_lsp() -> void:


## Connect to the LSP server using host and port specified in the editor config.
func connect_lsp() -> void:
func connect_lsp() -> bool:
var settings := EditorInterface.get_editor_settings()
var port: int = settings.get("network/language_server/remote_port")
var host: String = settings.get("network/language_server/remote_host")
connect_lsp_at(host, port)
return connect_lsp_at(host, port)


## Connect to the LSP server at the given host and port.
func connect_lsp_at(host: String, port: int) -> void:
func connect_lsp_at(host: String, port: int) -> bool:
var err := _client.connect_to_host(host, port)

if err != OK:
log_error("Failed to connect to LSP server: %s" % err)
return false

# Enable processing
_id = 0
_timer.start()
_reset_tick_interval()

return true


func is_lsp_connected() -> bool:
return _client.get_status() == StreamPeerTCP.STATUS_CONNECTED
Expand Down
4 changes: 2 additions & 2 deletions test/BaseTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func _connect_client() -> DiagnosticList_LSPClient:

assert_false(client.is_lsp_connected())

client.connect_lsp_at("127.0.0.1", 6008)
client.connect_lsp_at("localhost", 6008)
await wait_for_signal(client.on_initialized, 3)

return client
Expand All @@ -26,7 +26,7 @@ func _get_diagnostics(client: DiagnosticList_LSPClient, res_path: String) -> Dia
client.on_publish_diagnostics.connect(_on_publish_diagnostics)

client.update_diagnostics(res_path, FileAccess.get_file_as_string(res_path))
await client.on_publish_diagnostics
await wait_for_signal(client.on_publish_diagnostics, 3)

client.on_publish_diagnostics.disconnect(_on_publish_diagnostics)

Expand Down

0 comments on commit fd711ff

Please sign in to comment.