Compare commits

...

6 Commits

Author SHA1 Message Date
John Sudol fe6f73865e
. 2022-12-19 19:27:30 +00:00
John Sudol 9e67f6e707
other path method 2022-12-19 18:56:43 +00:00
John Sudol bf8696f8ed
use resolve instead 2022-12-19 18:38:33 +00:00
John Sudol b802b32103
update directories 2022-12-19 17:09:58 +00:00
John Sudol 2f31e7278d
undo workflow changes 2022-12-19 17:04:18 +00:00
John Sudol 9a01ddca95
parse the root Dir path 2022-12-19 17:01:27 +00:00
2 changed files with 15 additions and 13 deletions

View File

@ -62,9 +62,9 @@ jobs:
# We're using node -e to call the functions directly available in the @actions/artifact package
- name: Upload artifacts using uploadArtifact()
run: |
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-1',['artifact-path/world.txt'], process.argv[1]))" "${{ github.workspace }}"
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-2',['artifact-path/gzip.txt'], process.argv[1]))" "${{ github.workspace }}"
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-3',['artifact-path/empty.txt'], process.argv[1]))" "${{ github.workspace }}"
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-1',['artifact-path/world.txt'], '${{ github.workspace }}'))"
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-2',['artifact-path/gzip.txt'], '${{ github.workspace }}'))"
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-3',['artifact-path/empty.txt'], '${{ github.workspace }}'))"
- name: Download artifacts using downloadArtifact()
run: |

View File

@ -1,6 +1,6 @@
import * as fs from 'fs'
import {debug} from '@actions/core'
import {join, normalize, resolve} from 'path'
import {join, normalize, resolve, toNamespacedPath} from 'path'
import {checkArtifactFilePath} from './path-and-artifact-name-validation'
export interface UploadSpecification {
@ -22,17 +22,19 @@ export function getUploadSpecification(
// artifact name was checked earlier on, no need to check again
const specifications: UploadSpecification[] = []
if (!fs.existsSync(rootDirectory)) {
throw new Error(`Provided rootDirectory ${rootDirectory} does not exist`)
const rootPath = join(rootDirectory)
if (!fs.existsSync(rootPath)) {
throw new Error(`Provided rootDirectory ${rootPath} does not exist`)
}
if (!fs.lstatSync(rootDirectory).isDirectory()) {
if (!fs.lstatSync(rootPath).isDirectory()) {
throw new Error(
`Provided rootDirectory ${rootDirectory} is not a valid directory`
`Provided rootDirectory ${rootPath} is not a valid directory`
)
}
// Normalize and resolve, this allows for either absolute or relative paths to be used
rootDirectory = normalize(rootDirectory)
rootDirectory = resolve(rootDirectory)
rootDirectory = normalize(rootPath)
rootDirectory = resolve(rootPath)
/*
Example to demonstrate behavior
@ -61,14 +63,14 @@ export function getUploadSpecification(
// Normalize and resolve, this allows for either absolute or relative paths to be used
file = normalize(file)
file = resolve(file)
if (!file.startsWith(rootDirectory)) {
if (!file.startsWith(rootPath)) {
throw new Error(
`The rootDirectory: ${rootDirectory} is not a parent directory of the file: ${file}`
`The rootDirectory: ${rootPath} is not a parent directory of the file: ${file}`
)
}
// Check for forbidden characters in file paths that will be rejected during upload
const uploadPath = file.replace(rootDirectory, '')
const uploadPath = file.replace(rootPath, '')
checkArtifactFilePath(uploadPath)
/*