Skip to content

Commit

Permalink
feat: Consolidating and logging tmpdir cleanup (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
IAreKyleW00t authored Sep 8, 2024
1 parent cae7005 commit fae743c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
12 changes: 6 additions & 6 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.

15 changes: 8 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function run(): Promise<void> {

// Create temp directory for downloading non-cached versions
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'regctl_'))
core.debug(`tmpdir => ${tmpDir}`)
core.debug(`Created ${tmpDir}`)

// Check if regctl is already in the tool-cache
const cache = core.getInput('cache')
Expand Down Expand Up @@ -120,17 +120,18 @@ export async function run(): Promise<void> {
version.substring(1) // remove leading 'v'
)
} else core.info('📥 Loaded from runner cache')

// Add the cached regctl to our PATH
core.addPath(mainCachePath)

// Cleanup tmpDir
fs.rmSync(tmpDir, { recursive: true, force: true })
core.info('🎉 regctl is ready')
} catch (error) {
// Cleanup tmpDir before terminating during a failure
if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true })

if (error instanceof Error) core.setFailed(error.message)
else core.setFailed(error as string)
}

// Cleanup tmpDir if it was created at any point
if (tmpDir) {
core.debug(`Deleting ${tmpDir}`)
fs.rmSync(tmpDir, { recursive: true, force: true })
}
}

0 comments on commit fae743c

Please sign in to comment.