-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(5955): ensure getEnvironment() function to return the correct environment values #38614
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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c36137b
fix(5955): ensure getEnvironment() function to return the correct env…
DDDDDanica ec732ff
Merge remote-tracking branch 'origin/main' into fix/5955-env-logic
DDDDDanica b1516e9
chore(5956): lint fix
DDDDDanica 6d9fdfb
chore(5956): fix Empty string GITHUB_HEAD_REF breaks branch detection
DDDDDanica 16cdd36
chore(5956): fix Falsy empty string causes incorrect environment fall…
DDDDDanica da8f9d0
chore(5956): throw error when getBuildTargetFromTask has no match
DDDDDanica 01644ef
chore(5956): guard type and remove undefine param
DDDDDanica b48d5c6
chore(5956): fix unit test
DDDDDanica ac66e77
Merge branch 'main' into fix/5955-env-logic
DDDDDanica 70b4725
Merge branch 'main' into fix/5955-env-logic
DDDDDanica 4f10319
chore(5956): fix remove the type assertion
DDDDDanica 3fadd50
Merge remote-tracking branch 'origin/main' into fix/5955-env-logic
DDDDDanica ba57673
chore(5956): fix Build fails for low-level tasks passed as entry
DDDDDanica 6c8e6d7
fix: rename metamaskEnvironment to targetEnvironment
DDDDDanica 29f6262
fix: make resolvedEnvironment mandatory
DDDDDanica 569936c
fix: Dry-run message shows incorrect auto-detection status
DDDDDanica 1fcca68
fix: expand SPECIAL_TASK_MAPPINGS for remaining standalone tasks
DDDDDanica 3dddcb9
chore(5956): add all task mappings to SPECIAL_TASK_MAPPINGS
DDDDDanica 05e582b
Merge branch 'main' into fix/5955-env-logic
DDDDDanica b0f9784
Merge branch 'main' into fix/5955-env-logic
DDDDDanica 2d31221
Merge branch 'main' into fix/5955-env-logic
DDDDDanica 86ad1cc
Merge branch 'main' into fix/5955-env-logic
DDDDDanica 60fb0ed
fix: remove incorrect changes, fix fragile getIgnoredFiles() logic
DDDDDanica 0ac4bd5
fix: fix lint and ts type
DDDDDanica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { getBuildTargetFromTask, getEnvironment } from './utils'; | ||
|
|
||
| describe('getBuildTargetFromTask', () => { | ||
| it('passes through valid build targets unchanged', () => { | ||
| expect(getBuildTargetFromTask('dev')).toBe('dev'); | ||
| expect(getBuildTargetFromTask('test')).toBe('test'); | ||
| expect(getBuildTargetFromTask('testDev')).toBe('testDev'); | ||
| expect(getBuildTargetFromTask('prod')).toBe('prod'); | ||
| expect(getBuildTargetFromTask('dist')).toBe('dist'); | ||
| }); | ||
|
|
||
| it('extracts build target from script task names', () => { | ||
| expect(getBuildTargetFromTask('scripts:core:dev:standardEntryPoints')).toBe( | ||
| 'dev', | ||
| ); | ||
| expect(getBuildTargetFromTask('scripts:core:dev:contentscript')).toBe( | ||
| 'dev', | ||
| ); | ||
| expect( | ||
| getBuildTargetFromTask('scripts:core:test:standardEntryPoints'), | ||
| ).toBe('test'); | ||
| expect(getBuildTargetFromTask('scripts:core:test:sentry')).toBe('test'); | ||
| expect( | ||
| getBuildTargetFromTask('scripts:core:test-live:standardEntryPoints'), | ||
| ).toBe('testDev'); | ||
| expect( | ||
| getBuildTargetFromTask('scripts:core:prod:standardEntryPoints'), | ||
| ).toBe('prod'); | ||
| expect( | ||
| getBuildTargetFromTask('scripts:core:dist:standardEntryPoints'), | ||
| ).toBe('dist'); | ||
| }); | ||
|
|
||
| it('returns original taskName for unknown patterns (backwards compatibility)', () => { | ||
| expect(getBuildTargetFromTask('unknown:task')).toBe('unknown:task'); | ||
| expect(getBuildTargetFromTask('manifest:dev')).toBe('manifest:dev'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getEnvironment', () => { | ||
| const { env } = process; | ||
|
|
||
| beforeEach(() => { | ||
| process.env = { ...env }; | ||
| // Clear GitHub env vars that CI sets | ||
| delete process.env.GITHUB_HEAD_REF; | ||
| delete process.env.GITHUB_REF_NAME; | ||
| delete process.env.GITHUB_EVENT_NAME; | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| process.env = env; | ||
| }); | ||
|
|
||
| it('returns correct environment for build targets', () => { | ||
| expect(getEnvironment({ buildTarget: 'prod' as never })).toBe('production'); | ||
| expect(getEnvironment({ buildTarget: 'dev' as never })).toBe('development'); | ||
| expect(getEnvironment({ buildTarget: 'test' as never })).toBe('testing'); | ||
| expect(getEnvironment({ buildTarget: 'testDev' as never })).toBe( | ||
| 'development', | ||
| ); | ||
| expect(getEnvironment({ buildTarget: 'dist' as never })).toBe('other'); | ||
| }); | ||
|
|
||
| it('returns RELEASE_CANDIDATE for dist on release branch', () => { | ||
| process.env.GITHUB_REF_NAME = 'release/13.12.0'; | ||
| expect(getEnvironment({ buildTarget: 'dist' as never })).toBe( | ||
| 'release-candidate', | ||
| ); | ||
| }); | ||
|
|
||
| it('returns STAGING for dist on main branch', () => { | ||
| process.env.GITHUB_REF_NAME = 'main'; | ||
| expect(getEnvironment({ buildTarget: 'dist' as never })).toBe('staging'); | ||
| }); | ||
|
|
||
| it('returns PULL_REQUEST for dist on pull_request event', () => { | ||
| process.env.GITHUB_EVENT_NAME = 'pull_request'; | ||
| expect(getEnvironment({ buildTarget: 'dist' as never })).toBe( | ||
| 'pull-request', | ||
| ); | ||
| }); | ||
|
|
||
| it('returns TESTING for test even with pull_request event', () => { | ||
| process.env.GITHUB_EVENT_NAME = 'pull_request'; | ||
| expect(getEnvironment({ buildTarget: 'test' as never })).toBe('testing'); | ||
| }); | ||
|
|
||
| it('prefers GITHUB_HEAD_REF over GITHUB_REF_NAME', () => { | ||
| process.env.GITHUB_HEAD_REF = 'release/15.0.0'; | ||
| process.env.GITHUB_REF_NAME = 'main'; | ||
| expect(getEnvironment({ buildTarget: 'dist' as never })).toBe( | ||
| 'release-candidate', | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Child processes receive task names (e.g.,
scripts:core:test:standardEntryPoints) instead of build targets (test). This function extracts the correct build target from task names sogetEnvironment()works correctly in child processes.