Skip to content

Commit 78ce0e7

Browse files
committed
Fix path issue
1 parent e9743a4 commit 78ce0e7

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

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": "overwrite-env-file",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Overwrite a env file with the given content",
55
"author": "JeongMin Oh",
66
"license": "Apache-2.0",

src/__tests__/run.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mock.module('@actions/glob', () => ({
2727
create: mockCreate,
2828
}))
2929

30+
import { dirname, join } from 'node:path'
3031
import { run } from '../run'
3132

3233
test('should overwrite files successfully', async () => {
@@ -79,15 +80,20 @@ test('should overwrite files successfully', async () => {
7980

8081
// Verify writeFile was called for each file with correct content
8182
expect(mockWriteFile).toHaveBeenCalledTimes(testFiles.length)
82-
testFiles.forEach(() => {
83-
expect(mockWriteFile).toHaveBeenCalledWith(testOutputFile, testFileContent)
83+
testFiles.forEach((file) => {
84+
const newOutputFilePath = join(dirname(file), testOutputFile)
85+
expect(mockWriteFile).toHaveBeenCalledWith(
86+
newOutputFilePath,
87+
testFileContent,
88+
)
8489
})
8590

8691
// Verify info was called for each file
8792
expect(mockInfo).toHaveBeenCalledTimes(testFiles.length)
8893
testFiles.forEach((file) => {
94+
const newOutputFilePath = join(dirname(file), testOutputFile)
8995
expect(mockInfo).toHaveBeenCalledWith(
90-
`Overwrote ${file} to ${testOutputFile}`,
96+
`Overwrote ${file} to ${newOutputFilePath}`,
9197
)
9298
})
9399
})

src/run.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { readFile, writeFile } from 'node:fs/promises'
2+
import { dirname, join } from 'node:path'
23
import { error, getInput, info, setFailed } from '@actions/core'
34
import { create } from '@actions/glob'
45

@@ -12,8 +13,9 @@ export async function run() {
1213
files.map(async (file) => {
1314
try {
1415
const inputFileContent = await readFile(file, 'utf8')
15-
await writeFile(outputFile, inputFileContent)
16-
info(`Overwrote ${file} to ${outputFile}`)
16+
const newOutputFilePath = join(dirname(file), outputFile)
17+
await writeFile(newOutputFilePath, inputFileContent)
18+
info(`Overwrote ${file} to ${newOutputFilePath}`)
1719
} catch (err: unknown) {
1820
error(err as Error)
1921
throw err

0 commit comments

Comments
 (0)