-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration tests for the build plugin #31
Conversation
25e4eeb
to
359affd
Compare
1368b0f
to
3c34daa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some feedback and you might not like it because it involves writing more bash... 😬
There's a lot of copy-pasta here which I think we can script quite easily (I think).
- All the .gitignores are the same
- All the Package.swift files are the same
- The hello world proto is used in tests 1, 2, 5, and 6
- The adopter.swift file is the same for tests 1, 2, 3, and 4, another adopter.swift file is the same for tests 5 and 6.
I think the approach here should be to generate out packages into a temporary directory and construct a package in there by blatting in a package manifest (we can skip the ignore file), creating a Sources directory and then populating it as necessary.
@@ -0,0 +1 @@ | |||
{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-6.0)","swift_version":"nightly-6.0","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash","command_arguments":""}]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this generated somehow, if so, how? Can we run it through jq
or similar so it's readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not generated. We can run it through jq to make it readable for the purposes of review but the loading workflow requires that the JSON be densely encoded (jq . -c
).
{
"config": [
{
"name": "Plugin tests (6.0)",
"swift_version": "6.0",
"runner": "ubuntu-latest",
"image": "swift:6.0-jammy",
"platform": "Linux",
"setup_command": "apt-get update -y -q && apt-get install -y -q curl protobuf-compiler",
"command": "curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash",
"command_arguments": ""
},
{
"name": "Plugin tests (nightly-6.1)",
"swift_version": "nightly-6.1",
"runner": "ubuntu-latest",
"image": "swiftlang/swift:nightly-6.1-jammy",
"platform": "Linux",
"setup_command": "apt-get update -y -q && apt-get install -y -q curl protobuf-compiler",
"command": "curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash",
"command_arguments": ""
},
{
"name": "Plugin tests (nightly-main)",
"swift_version": "nightly-main",
"runner": "ubuntu-latest",
"image": "swiftlang/swift:nightly-main-jammy",
"platform": "Linux",
"setup_command": "apt-get update -y -q && apt-get install -y -q curl protobuf-compiler",
"command": "curl -s https://raw.githubusercontent.com/grpc/grpc-swift-protobuf/package_plugins/dev/plugin-tests.sh | bash",
"command_arguments": ""
}
]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest why does it need to be densely encoded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GitHub action which loads matrices from JSON errors-out if it encounters any unnecessary whitespace. It's pretty great. It used to have a step which pre-processed and condensed the JSON but it was noisy in CI so it was removed.
dev/plugin-tests.sh
Outdated
error() { printf -- "** ERROR: %s\n" "$*" >&2; } | ||
fatal() { error "$@"; exit 1; } | ||
|
||
source_dir=$(pwd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes the current working directory is the root of the package, which is quite brittle.
Most other shell scripts take the location of the shell script and then figure out where the root of the package is relative to that. which is less brittle. Here's an example:
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason I didn't do this (which I forgot) was that we tend to invoke scripts by curling and piping them into bash
. In that case we don't have a source directory to anchor our relative paths to. In that case our scripts just assume you're in the right place. I've added some code which attempts to handle both.
dev/plugin-tests.sh
Outdated
fatal() { error "$@"; exit 1; } | ||
|
||
source_dir=$(pwd) | ||
pluginTests="${source_dir}/IntegrationTests/PluginTests" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snake_case
for shell scripts please!
dev/plugin-tests.sh
Outdated
|
||
for dir in "$pluginTests"/test_*/ ; do | ||
if [[ -f "$dir/Package.swift" ]]; then | ||
pluginTest=$(basename "$dir") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snake_case
please!
), | ||
.package( | ||
url: "https://github.com/grpc/grpc-swift.git", | ||
exact: "2.0.0-beta.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only set to exact:
for when we tag releases so that's unlikely to be correct (grpc-swift-protobuf is likely to change its requirement between on grpc-swift very soon).
Motivation: To protect against regressions in common use-cases of the grpc-swift-protobuf build plugin. Modifications: Add test cases which make use of the build plugin as a dependency and ensure that they can compile and use the generated code * top level config file * peer config file * separate service message protos * cross directory imports * two definitions * nested definitions The new tests are run as part of CI on PRs Result: More CI.
58c07c6
to
3c5b627
Compare
8f63edd
to
7105fb7
Compare
376b6db
to
c6201ec
Compare
c6201ec
to
63dc0bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of small bits but looks good otherwise, thanks Rick!
@@ -0,0 +1 @@ | |||
{"config":[{"name":"Plugin tests (6.0)","swift_version":"6.0","runner":"ubuntu-latest","image":"swift:6.0-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""},{"name":"Plugin tests (nightly-6.1)","swift_version":"nightly-6.1","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-6.1-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""},{"name":"Plugin tests (nightly-main)","swift_version":"nightly-main","runner":"ubuntu-latest","image":"swiftlang/swift:nightly-main-jammy","platform":"Linux","setup_command":"apt-get update -y -q && apt-get install -y -q curl protobuf-compiler","command":"curl -s https://raw.githubusercontent.com/rnro/grpc-swift-protobuf/refs/heads/build_plugin_integration_tests/dev/plugin-tests.sh| GITHUB_ACTIONS=true bash","command_arguments":""}]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Late realisation: if we use this vs. this approach we have to update it for each new Swift version. Can we do the alternative?
|
||
import PackageDescription | ||
|
||
var package = Package( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this should be a let
as Package
is a class
🙃
Motivation:
To protect against regressions in common use-cases of the grpc-swift-protobuf build plugin.
Modifications:
Add test cases which make use of the build plugin as a dependency and ensure that they can compile and use the generated code
The new tests are run as part of CI on PRs
Result:
More CI.
This PR was split out of #26