Skip to content

Support writing .env files from Test Resources #10579

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 3 commits into from
May 12, 2025

Conversation

heaths
Copy link
Member

@heaths heaths commented May 8, 2025

If a language repo opts into it and if a test-resources.bicep file exists and lints clean of writing secrets and if the .env file is gitignore'd, write a .env file next to test-resources.bicep.

@heaths heaths requested review from Copilot, weshaggard and benbp and removed request for benbp and weshaggard May 8, 2025 23:51
@heaths heaths requested a review from a team as a code owner May 8, 2025 23:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for writing .env files from test resources when certain conditions are met. The primary changes include:

  • Adding a new function to lint Bicep files and check for secret outputs before writing .env files.
  • Conditional logic to handle .env file generation for both .NET (DPAPI-protected) and Bicep templates.
  • Updates to related documentation and cleanup scripts to remove .env files.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
eng/common/TestResources/TestResources-Helpers.ps1 Added LintBicepFile function and new branch to conditionally write .env files for Bicep templates.
eng/common/TestResources/Remove-TestResources.ps1 Enhanced removal logic to delete generated .env files.
eng/common/TestResources/README.md Updated documentation to explain new .env file behavior and prerequisites.
eng/common/TestResources/New-TestResources.ps1 & .md Revised logic and documentation for OutFile behavior including support for .env file generation on multiple platforms.

@heaths
Copy link
Member Author

heaths commented May 8, 2025

See Azure/azure-sdk-for-rust#2498 for history and comments. This was developed initially in the Azure/azure-sdk-for-rust repo so I could test it. This does not include the reformatting with the .editorconfig file, which I'll include in a subsequent PR.

heaths added 2 commits May 8, 2025 17:18
If a language repo opts into it *and* if a `test-resources.bicep` file exists and lints clean of writing secrets *and* if the `.env` file is gitignore'd, write a `.env` file next to `test-resources.bicep`.
@heaths heaths force-pushed the testresources-dotenv branch from dcaa516 to da5aca8 Compare May 9, 2025 00:21
@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@heaths
Copy link
Member Author

heaths commented May 9, 2025

Blocking this on review because I want to test this in at least a couple languages and need to update Rust's LanguageSettings.ps1 anyway since I changed the variable name.

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@heaths heaths force-pushed the testresources-dotenv branch from 46a6fec to 7b1488f Compare May 9, 2025 03:28
@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@heaths
Copy link
Member Author

heaths commented May 9, 2025

I've tested the following:

  1. Azure/azure-sdk-for-rust in Ubuntu (WSL) w/ support for .env files.
  2. Azure/azure-sdk-for-net in Windows to verify no regressions to existing DPAPI-encrypted .env-like protocol.
  3. Azure/azure-sdk-for-go in Ubuntu (WSL) w/o support for .env files.

All tests were done setting AZURE_TEST_MODE=live.

heaths added a commit to Azure/azure-sdk-for-js that referenced this pull request May 10, 2025
Sync eng/common directory with azure-sdk-tools for PR
Azure/azure-sdk-tools#10579 See [eng/common
workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)

---------

Co-authored-by: Heath Stewart <heaths@microsoft.com>
@weshaggard weshaggard enabled auto-merge (squash) May 12, 2025 15:23
@weshaggard weshaggard merged commit bd00846 into Azure:main May 12, 2025
12 checks passed
@heaths heaths deleted the testresources-dotenv branch May 12, 2025 20:26
JoshLove-msft pushed a commit to JoshLove-msft/azure-sdk-tools that referenced this pull request May 29, 2025
* Support writing .env files from Test Resources

If a language repo opts into it *and* if a `test-resources.bicep` file exists and lints clean of writing secrets *and* if the `.env` file is gitignore'd, write a `.env` file next to `test-resources.bicep`.

* Resolve PR feedback

* Pass -Force for . hidden files on non-Windows
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