From fd711ffa8aca1e893fadb1992efd7d33a7d75d7f Mon Sep 17 00:00:00 2001 From: Marvin Ewald Date: Sat, 18 May 2024 16:33:16 +0200 Subject: [PATCH] Run tests automatically on push --- .github/workflows/ci.yml | 25 +++++++ .github/workflows/unit_tests.yml | 111 +++++++++++++++++++++++++++++ addons/diagnosticlist/LSPClient.gd | 9 ++- test/BaseTest.gd | 4 +- 4 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/unit_tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0c6224e --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 }} + diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 0000000..68f7aa4 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -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 diff --git a/addons/diagnosticlist/LSPClient.gd b/addons/diagnosticlist/LSPClient.gd index 2a6046a..c199542 100644 --- a/addons/diagnosticlist/LSPClient.gd +++ b/addons/diagnosticlist/LSPClient.gd @@ -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 diff --git a/test/BaseTest.gd b/test/BaseTest.gd index e606131..1b1d150 100644 --- a/test/BaseTest.gd +++ b/test/BaseTest.gd @@ -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 @@ -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)