Skip to content

Commit b59b8c4

Browse files
committed
Sorting env
1 parent 904e6ba commit b59b8c4

4 files changed

Lines changed: 13 additions & 14 deletions

File tree

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "collect-env",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Collect env values and write to a file",
55
"author": "JeongMin Oh",
66
"license": "Apache-2.0",

src/__tests__/run.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ test('should filter environment variables by prefix', async () => {
129129

130130
const expectedContent = [
131131
'API_KEY=secret123',
132-
'API_URL=https://api.example.com',
133132
'API_TIMEOUT=5000',
133+
'API_URL=https://api.example.com',
134134
].join('\n')
135135

136136
expect(mockWriteFile).toHaveBeenCalledWith(testOutput, expectedContent)
@@ -162,8 +162,8 @@ test('should remove prefix from environment variables', async () => {
162162

163163
const expectedContent = [
164164
'KEY=secret123',
165-
'URL=https://api.example.com',
166165
'TIMEOUT=5000',
166+
'URL=https://api.example.com',
167167
].join('\n')
168168

169169
expect(mockWriteFile).toHaveBeenCalledWith(testOutput, expectedContent)

src/run.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ export async function run() {
1313
debug(`process.env: ${JSON.stringify(process.env)}`)
1414
debug(`secrets: ${JSON.stringify(secrets)}`)
1515

16-
try {
17-
await writeFile(
18-
output,
19-
Object.entries({ ...secrets, ...process.env })
20-
.filter(([key]) => key.startsWith(prefix))
21-
.map(
22-
([key, value]) =>
23-
`${removePrefix ? key.substring(prefix.length) : key}=${value}`,
24-
)
25-
.join('\n'),
16+
const result = Object.entries({ ...secrets, ...process.env })
17+
.filter(([key]) => key.startsWith(prefix))
18+
.map(
19+
([key, value]) =>
20+
`${removePrefix ? key.substring(prefix.length) : key}=${value}`,
2621
)
22+
result.sort()
23+
24+
try {
25+
await writeFile(output, result.join('\n'))
2726
} catch (err: unknown) {
2827
setFailed(err as Error)
2928
}

0 commit comments

Comments
 (0)