Skip to content

Commit 4d21256

Browse files
committed
Use nightly godot4-prebuilt for unit-test and clippy
This should detect issues that are hidden behind `#[cfg(since_api = "4.x")]` for cases where 4.x is a future (not yet released) version. Until now, clippy and unit tests simply excluded such code.
1 parent 9816e48 commit 4d21256

File tree

4 files changed

+65
-20
lines changed

4 files changed

+65
-20
lines changed

.github/composite/godot-itest/action.yml

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,46 @@ runs:
8686
- name: "Patch prebuilt version ({{ inputs.godot-prebuilt-patch }})"
8787
if: inputs.godot-prebuilt-patch != ''
8888
env:
89-
VERSION: ${{ inputs.godot-prebuilt-patch }}
89+
PATCHED_VERSION: ${{ inputs.godot-prebuilt-patch }}
9090
# sed -i'' needed for macOS compatibility, see https://stackoverflow.com/q/4247068
9191
run: |
92-
echo "Patch prebuilt version to $VERSION..."
92+
# Find the godot4-prebuilt version that gdext currently depends on.
93+
defaultVersion=$(grep 'godot4-prebuilt = {' godot-bindings/Cargo.toml | sed -n 's/.*branch = "\([^"]*\)".*/\1/p')
94+
if [ -z "$defaultVersion" ]; then
95+
echo "::error::prebuilt version not found or format is incorrect."
96+
exit 1
97+
else
98+
echo "Default prebuilt version: $defaultVersion"
99+
fi
100+
101+
# Apply [patch] for godot4-prebuilt crate if needed.
102+
if [[ "$PATCHED_VERSION" != $defaultVersion ]]; then
103+
.github/other/patch-prebuilt.sh "$PATCHED_VERSION"
104+
fi
93105
94-
# Reduce version to "major.minor" format
95-
apiVersion=$(echo $VERSION | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')
106+
# Reduce versions to "major.minor" format.
107+
apiVersion=$(echo "$PATCHED_VERSION" | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')
108+
apiDefaultVersion=$(echo "$defaultVersion" | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')
96109
97-
# For newer versions, update the compatibility_minimum in .gdextension files to the respective version.
98-
# Nothing needs to be done for 4.0.x, as compatibility_minimum didn't exist back then.
99-
if [[ "$apiVersion" == "4.2" ]]; then
110+
# For newer versions, update 'compatibility_minimum' in .gdextension files to the respective version.
111+
# Nothing needs to be done for 4.0.x, as compatibility_minimum didn't exist back then (we do it due to easier code, anyway).
112+
if [[ "$apiVersion" == "$apiDefaultVersion" ]]; then
113+
echo "Already has version $version; no need to change compatibility_minimum."
114+
115+
else
100116
echo "Update compatibility_minimum in .gdextension files to '$apiVersion'..."
101117
dirs=("itest" "examples")
118+
119+
# Note that this is still hardcoded to 4.1, the start of GDExtension's compatibility promise. This makes it easier for users
120+
# to use gdext with older Godot versions. There is anyway a runtime check in gdext that checks compatibility again.
102121
for dir in "${dirs[@]}"; do
103-
find "$dir" -type f -name "*.gdextension" -exec sed -i'.bak' 's/compatibility_minimum = 4\.1/compatibility_minimum = $apiVersion/' {} +
122+
find "$dir" -type f -name "*.gdextension" -exec sed -i'.bak' "s/compatibility_minimum = 4\.1/compatibility_minimum = $apiVersion/" {} +
104123
done
105124
106-
# Apply Cargo.toml patch for godot4-prebuilt crate
107-
else
108-
# Patch only needed if version is not already set
109-
if grep -E 'godot4-prebuilt = { .+ branch = "$VERSION" }' godot-bindings/Cargo.toml; then
110-
echo "Already has version $version; no need for patch."
111-
else
112-
cat << HEREDOC >> Cargo.toml
113-
[patch."https://github.com/godot-rust/godot4-prebuilt"]
114-
godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "$VERSION" }
115-
HEREDOC
116-
echo "Patched Cargo.toml for version $version."
117-
fi
125+
echo "Example output: itest/godot/itest.gdextension"
126+
echo "----------------------------------------------------"
127+
cat itest/godot/itest.gdextension
128+
echo "----------------------------------------------------"
118129
fi
119130
120131
shell: bash

.github/other/patch-prebuilt.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Copyright (c) godot-rust; Bromeon and contributors.
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
# Sets up a patch in Cargo.toml to use godot4-prebuilt artifacts.
8+
# Input: $version
9+
10+
version="$1"
11+
12+
cat << HEREDOC >> Cargo.toml
13+
[patch."https://github.com/godot-rust/godot4-prebuilt"]
14+
godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "$version" }
15+
HEREDOC
16+
17+
echo "Patched Cargo.toml for version $version."

.github/workflows/full-ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ jobs:
5252
steps:
5353
- uses: actions/checkout@v3
5454

55+
- name: "Patch Cargo.toml to use nightly extension API"
56+
run: .github/other/patch-prebuilt.sh nightly
57+
5558
- name: "Install Rust"
5659
uses: ./.github/composite/rust
5760
with:
@@ -70,6 +73,9 @@ jobs:
7073
steps:
7174
- uses: actions/checkout@v3
7275

76+
- name: "Patch Cargo.toml to use nightly extension API"
77+
run: .github/other/patch-prebuilt.sh nightly
78+
7379
- name: "Install Rust"
7480
uses: ./.github/composite/rust
7581
with:
@@ -124,6 +130,11 @@ jobs:
124130
steps:
125131
- uses: actions/checkout@v3
126132

133+
- name: "Patch Cargo.toml to use nightly extension API"
134+
# Only on Linux because godot4-prebuilt/nightly branch doesn't have artifacts for other platforms.
135+
if: matrix.name == 'linux' && matrix.rust-special == ''
136+
run: .github/other/patch-prebuilt.sh nightly
137+
127138
- name: "Install Rust"
128139
uses: ./.github/composite/rust
129140
with:

.github/workflows/minimal-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ jobs:
7777
steps:
7878
- uses: actions/checkout@v3
7979

80+
- name: "Patch Cargo.toml to use nightly extension API"
81+
run: .github/other/patch-prebuilt.sh nightly
82+
8083
- name: "Install Rust"
8184
uses: ./.github/composite/rust
8285
with:
@@ -101,6 +104,9 @@ jobs:
101104
steps:
102105
- uses: actions/checkout@v3
103106

107+
- name: "Patch Cargo.toml to use nightly extension API"
108+
run: .github/other/patch-prebuilt.sh nightly
109+
104110
- name: "Install Rust"
105111
uses: ./.github/composite/rust
106112

0 commit comments

Comments
 (0)