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

feat: Updates migration tests to run separately and use last released version of provider for plan checks #1565

Merged
merged 14 commits into from
Oct 31, 2023

Conversation

maastha
Copy link
Collaborator

@maastha maastha commented Oct 25, 2023

Description

This PR adds a new Github action workflow 'Migration Tests' and separates out existing migration acceptance tests into this workflow only i.e. migration tests will no longer run as part of existing Acceptance tests workflows in PRs.

What are 'Migration tests'?
Migration tests are similar to Terraform acceptance tests but focus on ensuring that empty plans are generated when upgrading from a previous released version to the current version of the Terraform provider. See documentation.

Releases: This workflow will run during release and use the last released version of our provider to run migration tests to ensure no unexpected plans are generated when our users upgrade.

Manual: This workflow can be manually run if required, using labels or via UI.

We can eventually disable these tests to run for every PR as migration tests usually cover scenarios already covered by acceptance tests, and require to only run these during releases or manually.

NOTE: This workflow was not tested for a run during release.
NOTE: This PR also introduces convention to use prefix TestAccMigration* for all migration tests.

Link to any related issue(s):

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.

Further comments

@maastha maastha changed the title feat: migration tests feat: Update migration tests to run separately and use last released version of provider for plan checks Oct 25, 2023
@maastha maastha marked this pull request as ready for review October 25, 2023 08:50
@maastha maastha requested a review from a team as a code owner October 25, 2023 08:50
@maastha maastha changed the title feat: Update migration tests to run separately and use last released version of provider for plan checks feat: Updates migration tests to run separately and use last released version of provider for plan checks Oct 25, 2023
@maastha
Copy link
Collaborator Author

maastha commented Oct 25, 2023

unit-test step failing due to issue with Adds coverage report to PRs step

@@ -88,7 +88,7 @@ jobs:
- uses: actions/checkout@v4
- name: Run ShellCheck
uses: bewuethr/shellcheck-action@v2
call-accettance-tests-workflow:
call-acceptance-tests-workflow:
Copy link
Member

Choose a reason for hiding this comment

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

finally, thanks! :-)


project:
needs: [ change-detection ]
if: ${{ needs.change-detection.outputs.project == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc-migration' || github.event.label.name == 'run-testacc-project-migration' || inputs.parent-event-name == 'release' }}
Copy link
Member

Choose a reason for hiding this comment

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

i know we have this in other gh actions but I wonder if we could make this easier or have some functions or something

Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps we could start fixing this file and then a follow-up to change the others?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lantoli I couldn't find a way to make this reusable or use a function, is there any example or reference you could share?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the best way, but for instance what about creating a variable in the workflow and use the variable? something like:

on: ...

env:
hasToTrigger: ${{ needs.change-detection.outputs.config == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc-migration' || github.event.label.name == 'run-testacc-config-migration' || inputs.parent-event-name == 'release' }}

job...

and use:

if: ${{ env.hasToTrigger }}

Copy link
Member

Choose a reason for hiding this comment

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

or use it for the common part and then:
if: ${{ env.hasToTrigger }} || specific conditions here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since this doesn't hold a static value, rather holds a condition, i don't believe this is possible to do via a variable as well

Copy link
Member

Choose a reason for hiding this comment

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

i suppose it's possible while you use variables that are know before starting execution

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed, see comment #1565 (comment)


config:
needs: [ change-detection ]
if: ${{ needs.change-detection.outputs.config == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc-migration' || github.event.label.name == 'run-testacc-config-migration' || inputs.parent-event-name == 'release' }}
Copy link
Member

Choose a reason for hiding this comment

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

same

orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
clusterName = acctest.RandomWithPrefix("test-acc-cluster")
lastVersionConstraint = os.Getenv("MONGODB_ATLAS_LAST_VERSION")
Copy link
Member

Choose a reason for hiding this comment

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

do we need to check that this env var exists?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice catch, will update

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

Copy link
Collaborator

@marcosuma marcosuma left a comment

Choose a reason for hiding this comment

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

minor comments, but LGTM!

.github/workflows/migration-tests.yml Outdated Show resolved Hide resolved

project:
needs: [ change-detection ]
if: ${{ needs.change-detection.outputs.project == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc-migration' || github.event.label.name == 'run-testacc-project-migration' || inputs.parent-event-name == 'release' }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps we could start fixing this file and then a follow-up to change the others?

Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

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

great idea having the version update automatically, gives proper value to the migration tests

types: [ labeled ]

jobs:
set-output:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lantoli tried with another step: https://github.com/mongodb/terraform-provider-mongodbatlas/pull/1565/files#diff-9e63d3ed50a83cef3c77bb7447f2858374bc51e6dd94ac7f65b3420205c70ea6
This is an example PR running this workflow: maastha#1

Let me know if this approach makes sense, not sure if this is possible with a variable

Copy link
Member

Choose a reason for hiding this comment

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

that's great, thanks!

@marcosuma
Copy link
Collaborator

I just realised something now: why do we call them migration? shouldn't it be backwardCompatibiltyTest?

@lantoli
Copy link
Member

lantoli commented Oct 30, 2023

I just realised something now: why do we call them migration? shouldn't it be backwardCompatibiltyTest?

@marcosuma I think it's Hashicorp naming

@maastha maastha merged commit c3ff8a0 into mongodb:master Oct 31, 2023
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants