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

New Tool: update-go-azure-sdk #23498

Merged
merged 9 commits into from
Oct 11, 2023
Merged

New Tool: update-go-azure-sdk #23498

merged 9 commits into from
Oct 11, 2023

Conversation

tombuildsstuff
Copy link
Contributor

This PR introduces a new tool update-go-azure-sdk which is primarily intended to be run in automation.

This tool obtains the changes between two versions of hashicorp/go-azure-sdk, then updates the version of hashicorp/go-azure-sdk used in this repository - and when a new API Version is available in the latest SDK, attempts to update the API Version for each Service.

Both the SDK Upgrade and each API Version update are done in individual commits - and prior to both being committed the unit tests are run to ensure these pass. This means that when an API Version is compatible, that is contains no breaking changes to the API Payloads - the API Version upgrade can be done automatically. However in the event that the API Payload is not compatible - the API Version will be ignored, with the issues outlined in the PR description. Examples of both of these can be seen below.

This will be conditionally run by hashicorp/go-azure-sdk after a release is made, to both update the version of hashicorp/go-azure-sdk that's being used in the Provider - but also to update the API Version being used in the Provider when a new API Version becomes available (and the build passes).

There's a bunch of assumptions built into this tool and it's not going to be infallible - however this should both ensure that hashicorp/go-azure-sdk is up-to-date in this repository and remove the manual work needed to update from one API Version to another.

Examples

Console output:

2023-10-10T15:14:12.249+0200 [INFO]  Old SDK Version is "v0.20230918.1115907"
2023-10-10T15:14:12.249+0200 [INFO]  New SDK Version is "v0.20231005.1153009"
2023-10-10T15:14:12.249+0200 [INFO]  Output File Name is "pr-description.txt"
2023-10-10T15:14:12.249+0200 [INFO]  Working Directory is "../../../"
2023-10-10T15:14:12.249+0200 [INFO]  Checking the changes between "v0.20230918.1115907" and "v0.20231005.1153009" of `hashicorp/go-azure-sdk`..
2023-10-10T15:14:34.275+0200 [INFO]  Updating `hashicorp/go-azure-sdk`..
2023-10-10T15:14:50.939+0200 [INFO]  Committed as "b5b40b0b49d9f192f9d65d620ecba98862764e6b"
2023-10-10T15:14:53.958+0200 [INFO]  Processing Service "connectedvmware"..
2023-10-10T15:14:54.552+0200 [INFO]  Processed Service "connectedvmware".
2023-10-10T15:14:57.578+0200 [INFO]  Processing Service "cosmosdb"..
2023-10-10T15:14:58.148+0200 [INFO]  Attempting to update API Version "2022-05-15" to "2023-09-15" for Service "cosmosdb"..
2023-10-10T15:15:03.823+0200 [INFO]  Updated the Imports for Service "cosmosdb" to use API Version "2023-09-15" rather than "2022-05-15"..
2023-10-10T15:15:03.823+0200 [INFO]  Running `go mod tidy` / `go mod vendor`..
2023-10-10T15:15:15.022+0200 [INFO]  Running `make test` within "../../../"..
2023-10-10T15:18:04.450+0200 [INFO]  Committed as "a88ab1b1be8344a07bcf316a62c3ea31a87be507"
2023-10-10T15:18:04.450+0200 [INFO]  Updated Service "cosmosdb" from "2022-05-15" to "2023-09-15"
2023-10-10T15:18:04.450+0200 [INFO]  Attempting to update API Version "2022-11-15" to "2023-09-15" for Service "cosmosdb"..
2023-10-10T15:18:10.035+0200 [INFO]  Updated the Imports for Service "cosmosdb" to use API Version "2023-09-15" rather than "2022-11-15"..
2023-10-10T15:18:10.035+0200 [INFO]  Running `go mod tidy` / `go mod vendor`..
2023-10-10T15:18:22.087+0200 [INFO]  Running `make test` within "../../../"..
2023-10-10T15:19:46.236+0200 [INFO]  Resetting the working directory since `make test` failed..
2023-10-10T15:19:56.549+0200 [INFO]  Attempting to update API Version "2023-04-15" to "2023-09-15" for Service "cosmosdb"..
2023-10-10T15:20:02.211+0200 [INFO]  Updated the Imports for Service "cosmosdb" to use API Version "2023-09-15" rather than "2023-04-15"..
2023-10-10T15:20:02.211+0200 [INFO]  Running `go mod tidy` / `go mod vendor`..
2023-10-10T15:20:12.584+0200 [INFO]  Running `make test` within "../../../"..

Output in a PR:

Screenshot 2023-10-10 at 12 54 56

An earlier build log containing example failures (with slightly less detail) can be seen here: https://gist.github.com/tombuildsstuff/d6c153d484697961b6519a3c1cec4882#file-output-txt-L156-L337

Questions

Why not extend the existing tool update-api-version?

In short, there's value in both - updating the API Version being used, and updating go-azure-sdk are subtly different use-cases - with the former being primarily run by a human and the latter primarily being run in automation.

It's worth calling out that some of the changes made in this PR should also be made to that tool, but that'll follow as a separate PR.

Why not just use Dependabot?

Dependabot would work great for updating the SDK dependency - however this wouldn't allow us to update the API Versions being used in the Provider. In addition, using a custom tool allows us to provide additional logic, such as running the (unit) tests for each API Version update to ensure these pass prior to committing the changes - else rolling this back (and documenting it in the PR description).

Whilst there's value in running this on every release of hashicorp/go-azure-sdk - for the moment we need this tool to be conditionally run, as when the base layer is migrated from Azure/go-autorest to hashicorp/go-azure-sdk additional changes must be made by hand.

Why not use a bash script?

In short, it's far simpler to get the output we want from a tool.

This tool is intended to update the `hashicorp/go-azure-sdk` dependency within the Provider - and then update the codebase
to take advantage of any new API Versions that are present within this version of `hashicorp/go-azure-sdk`, if used in the
Provider and the API versions are compatible (e.g. the tests pass when updating the API Version).

This tool makes a considerable number of assumptions about the working directory and environment this is being run in and
is primarily intended to be run in automation - and whilst will not be automatically configured initially, in time should
mean that both SDK upgrades and new API Version upgrades are (mostly) automated.

In the event that an SDK/API Version is _not_ compatible, the automated process will fail - and manual intervention is
required - which is desired (since this should be the edge-case and/or requires additional thought).
@tombuildsstuff tombuildsstuff requested a review from a team October 10, 2023 13:27
Copy link
Contributor

@manicminer manicminer left a comment

Choose a reason for hiding this comment

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

@tombuildsstuff This looks great! Should we also run make test after updating the module version, to catch any breaking changes outside of the services/ directory (e.g. in internal/clients or internal/provider)?

internal/tools/update-go-azure-sdk/main.go Show resolved Hide resolved
internal/tools/update-go-azure-sdk/main.go Outdated Show resolved Hide resolved
internal/tools/update-go-azure-sdk/main.go Outdated Show resolved Hide resolved
This allows for reusing an existing checkout, rather than cloning a fresh copy of `hashicorp/go-azure-sdk`
useful both for automation, and when working with an offline copy
@tombuildsstuff
Copy link
Contributor Author

tombuildsstuff commented Oct 11, 2023

@manicminer

Should we also run make test after updating the module version, to catch any breaking changes outside of the services/ directory (e.g. in internal/clients or internal/provider)?

I considered that, honestly if that's happened we have larger problems - either intentional or not - I suspect that we'll make those types of changes infrequently enough that it's not worth the cost of the extra CPU cycles to check that - since the tests would be run when the PR's sent to this repository anyway (where we'd catch it)?

@manicminer
Copy link
Contributor

I considered that, honestly if that's happened we have larger problems - either intentional or not - I suspect that we'll make those types of changes infrequently enough that it's not worth the cost of the extra CPU cycles to check that - since the tests would be run when the PR's sent to this repository anyway (where we'd catch it)?

I was mainly thinking of scenarios where an intentional breaking change is introduced, for example in go-azure-sdk/sdk/environments, where we intend to upgrade by hand - but thinking about it properly, the existing unit test workflow would of course be triggered by vendor/** anyway so I agree it's not worth the extra cycles 👍

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants