Skip to content

Commit

Permalink
Merge pull request #411 from tj-actions/dependabot/npm_and_yarn/temp-…
Browse files Browse the repository at this point in the history
…dir-3.0.0
  • Loading branch information
jackton1 authored Oct 4, 2022
2 parents 5d732b5 + 5b3b074 commit 051fefc
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 59 deletions.
2 changes: 1 addition & 1 deletion __tests__/cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {tempfile} from '../src/utils'
import {run} from '../src/cleanup'

describe('cleanup test', () => {
const pathsOutputFile = tempfile('.txt')

it('deletes the paths-output-file', async () => {
const pathsOutputFile = await tempfile('.txt')
await fs.writeFile(pathsOutputFile, '12345')

const fileExists = async (path: string) =>
Expand Down
17 changes: 8 additions & 9 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test('returns the paths of the filtered files (input files, input source files)'

await run()

expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES)
})

test('returns the paths of the all other files (input files)', async () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ test('returns the paths of the all other files (input files)', async () => {

await run()

expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES)
})

test('returns the paths of the filtered files (input files)', async () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ test('returns the paths of the filtered files (input files)', async () => {

await run()

expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES)
})

test('returns the paths of the filtered files (input source files)', async () => {
Expand All @@ -136,7 +136,7 @@ test('returns the paths of the filtered files (input source files)', async () =>

await run()

expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES)
})

test('returns true when no custom patterns are used', async () => {
Expand Down Expand Up @@ -170,19 +170,18 @@ test('returns the paths of the filtered files in the paths-output-file', async (
// @ts-ignore
core.setOutput = jest.fn()

const pathsOutputFile = tempfile('.txt')
const pathsOutputFile = await tempfile('.txt')

// @ts-ignore
tempfile = jest.fn().mockReturnValue(pathsOutputFile)
tempfile = jest.fn().mockResolvedValue(pathsOutputFile)

await run()

expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)

expect(core.setOutput).toHaveBeenNthCalledWith(
2,
1,
'paths-output-file',
pathsOutputFile
)
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES)
expect(core.setOutput).toHaveBeenNthCalledWith(3, 'has-custom-patterns', true)
})
32 changes: 7 additions & 25 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@actions/core": "1.10.0",
"@actions/exec": "1.1.1",
"@actions/glob": "0.3.0",
"temp-dir": "2.0.0",
"temp-dir": "3.0.0",
"uuid": "9.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ export async function run(): Promise<void> {
}

const pathsOutput = paths.join(separator)
core.setOutput('paths', pathsOutput)

if (pathsOutput) {
const pathsOutputFile = tempfile('.txt')
const pathsOutputFile = await tempfile('.txt')

await fs.writeFile(pathsOutputFile, pathsOutput)
core.setOutput('paths-output-file', pathsOutputFile)
core.saveState('paths-output-file', pathsOutputFile)
core.info(`Successfully created paths-output-file: ${pathsOutputFile}`)
}

core.setOutput('paths', pathsOutput)
core.setOutput(
'has-custom-patterns',
files !== '' ||
Expand Down
7 changes: 4 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*global AsyncIterableIterator*/
import {createReadStream} from 'fs'
import {createReadStream, promises as fs} from 'fs'
import {tmpdir} from 'os'
import path from 'path'
import {createInterface} from 'readline'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as patternHelper from '@actions/glob/lib/internal-pattern-helper'
import {Pattern} from '@actions/glob/lib/internal-pattern'
import {v4 as uuidv4} from 'uuid'
import tempDirectory from 'temp-dir'

export const IS_WINDOWS: boolean = process.platform === 'win32'

Expand Down Expand Up @@ -168,7 +168,8 @@ export async function getFilesFromSourceFile({
return lines
}

export function tempfile(extension = ''): string {
export async function tempfile(extension = ''): Promise<string> {
const tempDirectory = await fs.realpath(tmpdir())
return path.join(tempDirectory, `${uuidv4()}${extension}`)
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3316,10 +3316,10 @@ svg-element-attributes@^1.3.1:
resolved "https://registry.yarnpkg.com/svg-element-attributes/-/svg-element-attributes-1.3.1.tgz#0c55afac6284291ab563d0913c062cf78a8c0ddb"
integrity sha512-Bh05dSOnJBf3miNMqpsormfNtfidA/GxQVakhtn0T4DECWKeXQRQUceYjJ+OxYiiLdGe4Jo9iFV8wICFapFeIA==

temp-dir@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-2.0.0.tgz#bde92b05bdfeb1516e804c9c00ad45177f31321e"
integrity sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==
temp-dir@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-3.0.0.tgz#7f147b42ee41234cc6ba3138cd8e8aa2302acffa"
integrity sha512-nHc6S/bwIilKHNRgK/3jlhDoIHcp45YgyiwcAk46Tr0LfEqGBVpmiAyuiuxeVE44m3mXnEeVhaipLOEWmH+Njw==

terminal-link@^2.0.0:
version "2.1.1"
Expand Down

0 comments on commit 051fefc

Please sign in to comment.