Skip to content
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

Merged
merged 10 commits into from
Jan 24, 2025

Conversation

rnro
Copy link
Collaborator

@rnro rnro commented Jan 21, 2025

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.

This PR was split out of #26

@rnro rnro force-pushed the build_plugin_integration_tests branch 2 times, most recently from 25e4eeb to 359affd Compare January 21, 2025 17:20
@rnro rnro added the 🔨 semver/patch No public API change. label Jan 21, 2025
@rnro rnro force-pushed the build_plugin_integration_tests branch 2 times, most recently from 1368b0f to 3c34daa Compare January 21, 2025 17:23
@rnro rnro requested a review from glbrntt January 21, 2025 17:27
@rnro rnro marked this pull request as ready for review January 21, 2025 17:27
Copy link
Collaborator

@glbrntt glbrntt left a 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":""}]}
Copy link
Collaborator

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.

Copy link
Collaborator Author

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": ""
    }
  ]
}

Copy link
Collaborator

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?

Copy link
Collaborator Author

@rnro rnro Jan 23, 2025

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.

.github/workflows/main.yml Outdated Show resolved Hide resolved
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }

source_dir=$(pwd)
Copy link
Collaborator

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 )"

Copy link
Collaborator Author

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.

fatal() { error "$@"; exit 1; }

source_dir=$(pwd)
pluginTests="${source_dir}/IntegrationTests/PluginTests"
Copy link
Collaborator

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!


for dir in "$pluginTests"/test_*/ ; do
if [[ -f "$dir/Package.swift" ]]; then
pluginTest=$(basename "$dir")
Copy link
Collaborator

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"
Copy link
Collaborator

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).

rnro added 2 commits January 22, 2025 06:52
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.
@rnro rnro force-pushed the build_plugin_integration_tests branch from 58c07c6 to 3c5b627 Compare January 22, 2025 06:54
@rnro rnro force-pushed the build_plugin_integration_tests branch from 8f63edd to 7105fb7 Compare January 23, 2025 08:52
@rnro rnro force-pushed the build_plugin_integration_tests branch 4 times, most recently from 376b6db to c6201ec Compare January 23, 2025 10:12
@rnro rnro force-pushed the build_plugin_integration_tests branch from c6201ec to 63dc0bf Compare January 23, 2025 11:12
@rnro rnro requested a review from glbrntt January 23, 2025 11:21
Copy link
Collaborator

@glbrntt glbrntt left a 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":""}]}
Copy link
Collaborator

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(
Copy link
Collaborator

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 🙃

@glbrntt glbrntt merged commit 4153ada into grpc:main Jan 24, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants