Skip to content

feat: test-isolation package setup configs #3951

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

Merged
merged 44 commits into from
Jan 27, 2025
Merged

Conversation

davidcavazos
Copy link
Contributor

@davidcavazos davidcavazos commented Jan 15, 2025

Description

Supports package setup configuration files. These allow packages to provide per-package configurations like secrets, environment variables, and the runtime version. Additionally, there are some minor refactors to the existing code, just for better organization, but not changing functionality.

Default values are defined at the config file. The CI setup file is optional where each package can opt-in to custom values. The file lives within the same package directory, so there's no need for contributors to edit the workflows or any of the testing infrastructure.

This file is language agnostic, and it can contain any values, so different workflows or languages could configure them differently.

For this PR, we're also enabling generative-ai tests, which need secrets to run.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: genai api: workflows Issues related to the Workflows API. labels Jan 15, 2025
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi team,

I'm currently reviewing this pull request and will have a full review in a few minutes. In the meantime, here's a quick summary for you and other reviewers to get up to speed:

This pull request, authored by davidcavazos, aims to improve test isolation by introducing package setup configuration files. These configuration files allow packages to specify per-package settings such as secrets, environment variables, and runtime versions.

Here's a breakdown of the changes:

  • config.go: This file has been significantly modified to support loading and handling of these new setup configuration files. Specifically:
    • Lines 24-29: Removed the regexp import, simplifying the code.
    • Lines 32-43: Added a Setup struct within the Config struct to handle the setup file's filename and default values.
    • Lines 48-57: Added a Package struct to represent a package with its path and setup configurations.
    • Lines 71-79: Simplified the LoadConfig function by using a helper function to read JSONC files.
    • Lines 156-185: The Affected function was updated to return an array of Package structs, including the setup configurations.
  • utils.go: A new helper function ReadJsonc was added (lines 29-40) to handle reading and parsing JSONC files, simplifying the main config loading logic.
  • .github/config/nodejs-dev.jsonc and .github/config/nodejs-prod.jsonc: These configuration files were updated to include the new setup section, specifying a setup.json file and default values.
  • .github/workflows/ci-dev.yaml: This file was updated (lines 70-81) to use the google-github-actions/get-secretmanager-secrets@v2 action to retrieve secrets defined in the setup.json files.
  • generative-ai/snippets/setup.json: A sample setup.json file was added, demonstrating how to define secrets and Node.js version.

Several files also had lines removed related to the previous comment handling logic, which is now handled by the new ReadJsonc function. The functions/http/uploadFile sample was also removed from the ignore list in the production config file.

I'll provide a more detailed review shortly. In the meantime, please let me know if you have any questions.

And now, a little haiku to brighten your day:

Tests run, green light shows,
Configs now make setup smooth,
Code flows, clean and bright.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request introduces support for per-package setup configuration files, which is a valuable addition. The implementation looks good overall, but there are a few points to address regarding consistency, error handling, and best practices.

@davidcavazos davidcavazos force-pushed the test-isolation-configs branch 7 times, most recently from 8389be9 to 37befa1 Compare January 21, 2025 20:56
@davidcavazos davidcavazos force-pushed the test-isolation-configs branch from 37befa1 to 9372772 Compare January 21, 2025 20:58
@davidcavazos davidcavazos marked this pull request as ready for review January 27, 2025 20:40
@davidcavazos davidcavazos requested review from a team as code owners January 27, 2025 20:40
Copy link
Member

@briandorsey briandorsey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very high level review without running it myself, but overall LGTM.

@@ -29,8 +29,8 @@ import (
var usage = `usage: tools <command> ...

commands:
affected path/to/config.jsonc path/to/diffs.txt
run-all path/to/config.jsonc path/to/script.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checking... looks like run-all didn't exist before this PR? (context: didn't see "run-all" in the switch command { section.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, run-all came from another experiment that was removed, but forgot to update this.

Copy link
Contributor

@telpirion telpirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only nits. Looks good!


var config Config
err = json.Unmarshal(sourceJson, &config)
// This mutates `config` so there's no need to reassign it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: I love the comments here that help me interpret what the code is doing.

@davidcavazos davidcavazos merged commit 8368771 into main Jan 27, 2025
16 checks passed
@davidcavazos davidcavazos deleted the test-isolation-configs branch January 27, 2025 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: genai api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants