Implement follow-symlinks boolean action input

This commit implements a new boolean input to the action,
`follow-symlinks`. This option configures whether the glob expansion
will follow any symlinks it finds when determining the set of of files
to be archived into the artifact.

The default value of the option, which preserves the existing behaviour,
is `true`. When set to true, symbolic links will be be followed and expanded
If `false`, symbolic links will be included in the archived artifact verbatim.

Users may wish to set this option to false if their artifact contains
internally-referencing symlinks which would result in significant bloat
(and semantic change!) in the source files when the artifact is created.

Resolves: actions#93.
This commit is contained in:
Peter Bridgman 2021-05-10 11:55:27 +01:00 committed by Peter Bridgman
parent ee69f02b3d
commit 92b91569e6
7 changed files with 62 additions and 15 deletions

View file

@ -2,7 +2,7 @@ import * as core from '@actions/core'
import * as path from 'path'
import * as io from '@actions/io'
import {promises as fs} from 'fs'
import {findFilesToUpload} from '../src/search'
import {findFilesToUpload, getDefaultGlobOptions} from '../src/search'
const root = path.join(__dirname, '_temp', 'search')
const searchItem1Path = path.join(
@ -110,6 +110,12 @@ describe('Search', () => {
await fs.writeFile(amazingFileInFolderHPath, 'amazing file')
await fs.writeFile(lonelyFilePath, 'all by itself')
await fs.symlink(
path.join(root, 'folder-d'),
path.join(root, 'symlink-to-folder-d')
)
/*
Directory structure of files that get created:
root/
@ -136,6 +142,7 @@ describe('Search', () => {
folder-j/
folder-k/
lonely-file.txt
symlink-to-folder-d/ -> ./folder-d/
search-item5.txt
*/
})
@ -227,7 +234,8 @@ describe('Search', () => {
it('Wildcard search - Absolute Path', async () => {
const searchPath = path.join(root, '**/*[Ss]earch*')
const searchResult = await findFilesToUpload(searchPath)
expect(searchResult.filesToUpload.length).toEqual(10)
// folder-d items included twice because symlink is followed by default
expect(searchResult.filesToUpload.length).toEqual(14)
expect(searchResult.filesToUpload.includes(searchItem1Path)).toEqual(true)
expect(searchResult.filesToUpload.includes(searchItem2Path)).toEqual(true)
@ -261,7 +269,8 @@ describe('Search', () => {
'**/*[Ss]earch*'
)
const searchResult = await findFilesToUpload(searchPath)
expect(searchResult.filesToUpload.length).toEqual(10)
// folder-d items included twice because symlink is followed by default
expect(searchResult.filesToUpload.length).toEqual(14)
expect(searchResult.filesToUpload.includes(searchItem1Path)).toEqual(true)
expect(searchResult.filesToUpload.includes(searchItem2Path)).toEqual(true)
@ -352,4 +361,15 @@ describe('Search', () => {
)
expect(searchResult.filesToUpload.includes(lonelyFilePath)).toEqual(true)
})
it('Declines to follow symlinks when requested', async () => {
const searchPath = path.join(root, 'symlink-to-folder-d')
const globOptions = {
...getDefaultGlobOptions(),
followSymbolicLinks: false
}
const searchResult = await findFilesToUpload(searchPath, globOptions)
expect(searchResult.filesToUpload.length).toEqual(1)
})
})