generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when the required parameters are provided the runner performs the installation in the configured directory by creating symlinks in that folder pointing to the contents of `build-root/build_name`
- Loading branch information
Showing
7 changed files
with
203 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,79 @@ | ||
const fs = require('fs').promises | ||
const path = require('path') | ||
|
||
/* Creates symlinks recursively, sub-directories that already exist in | ||
* `sourceDir` are not overwritten, they are accessed and symlinks are created | ||
* inside them for the corresponding files in the `destDir` tree. This is to | ||
* avoid (as much as possible) to lose files from `sourceDir` by replacing | ||
* non-empty directories with symlinks. | ||
*/ | ||
const createSymlinks = async (sourceDir, destDir) => { | ||
const filesCreated = [] | ||
const destFiles = await fs.readdir(destDir) | ||
|
||
for (const destFile of destFiles) { | ||
const sourceFilePath = path.join(sourceDir, destFile) | ||
const destFilePath = path.join(destDir, destFile) | ||
|
||
try { | ||
const sourceStats = await fs.lstat(sourceFilePath) | ||
if (sourceStats.isDirectory()) { | ||
// if source file is a directory continue recursively | ||
filesCreated.push( | ||
...(await createSymlinks(sourceFilePath, destFilePath)), | ||
) | ||
continue | ||
} | ||
// delete source file if it already exists (and is not a directory) | ||
await fs.unlink(sourceFilePath) | ||
} catch (error) { | ||
if (error.code !== 'ENOENT') { | ||
console.error(error) | ||
} | ||
} | ||
|
||
// Create the symlink | ||
await fs.symlink(destFilePath, sourceFilePath) | ||
filesCreated.push(sourceFilePath) | ||
} | ||
|
||
return filesCreated | ||
} | ||
|
||
const setup = async (buildRootPath, buildName, sourceDirPath) => { | ||
if (!buildRootPath || !buildName || !sourceDirPath) { | ||
console.error( | ||
'One or more required parameters are missing, skipping installation', | ||
) | ||
return | ||
} | ||
console.debug('Installation started') | ||
const buildPath = path.join(buildRootPath, buildName) | ||
const files = await createSymlinks(sourceDirPath, buildPath) | ||
console.debug('Installation completed') | ||
return files | ||
} | ||
|
||
const cleanup = async (files) => { | ||
if (!files) { | ||
console.log('No files to cleanup') | ||
return | ||
} | ||
|
||
console.debug('Cleanup started') | ||
for (const file of files) { | ||
try { | ||
await fs.unlink(file) | ||
} catch (error) { | ||
if (error.code !== 'ENOENT') { | ||
console.error(error) | ||
} | ||
} | ||
} | ||
console.debug('Cleanup completed') | ||
} | ||
|
||
module.exports = { | ||
setup, | ||
cleanup, | ||
} |
This file contains 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