mirror of
https://github.com/actions/upload-artifact.git
synced 2024-12-01 19:55:21 +01:00
fix: add path key for pathObject
This commit is contained in:
parent
7f0c9eaa6d
commit
bbe4504729
4 changed files with 55 additions and 25 deletions
10
.github/workflows/test-per-file.yml
vendored
10
.github/workflows/test-per-file.yml
vendored
|
@ -64,14 +64,12 @@ jobs:
|
|||
|
||||
tar -zvcf path/to/dir-3/all.gz path/to/dir-3/*
|
||||
|
||||
# Upload a single file artifact
|
||||
- name: 'Upload artifact #1'
|
||||
uses: ./
|
||||
with:
|
||||
path: path/to/dir-1/file1.txt
|
||||
artifact-per-file: true
|
||||
|
||||
# Upload using a wildcard pattern, name should default to 'artifact' if not provided
|
||||
- name: 'Upload artifact #2'
|
||||
uses: ./
|
||||
with:
|
||||
|
@ -79,20 +77,18 @@ jobs:
|
|||
artifact-per-file: true
|
||||
artifact-name-rule: ${dir}-${base}
|
||||
|
||||
# Upload a directory that contains a file that will be uploaded with GZip
|
||||
- name: 'Upload artifact #3'
|
||||
uses: ./
|
||||
with:
|
||||
path: path/to/dir-3/*.gz
|
||||
artifact-per-file: true
|
||||
artifact-name-rule: ${dir}-${name}${ext}
|
||||
artifact-name-rule: ${path}-${name}${ext}
|
||||
|
||||
# Upload a directory that contains a file that will be uploaded with GZip
|
||||
- name: 'Upload artifact #4'
|
||||
uses: ./
|
||||
with:
|
||||
path: |
|
||||
path/**/dir*/
|
||||
path/**/dir-1/
|
||||
!path/to/dir-3/*.gz
|
||||
artifact-per-file: true
|
||||
artifact-name-rule: ${{ matrix.runs-on }}-${base}
|
||||
artifact-name-rule: ${{ matrix.runs-on }}-${name}
|
||||
|
|
11
action.yml
11
action.yml
|
@ -28,25 +28,28 @@ inputs:
|
|||
default: "false"
|
||||
artifact-name-rule:
|
||||
description: >
|
||||
https://nodejs.org/docs/latest-v16.x/api/path.html#pathparsepath
|
||||
// https://nodejs.org/docs/latest-v16.x/api/path.html#pathparsepath
|
||||
// Modified from path.parse()
|
||||
|
||||
path.parse('/home/user/dir/file.txt');
|
||||
// Returns:
|
||||
// { root: '/',
|
||||
// dir: '/home/user/dir',
|
||||
// path: 'home/user/dir'
|
||||
// base: 'file.txt',
|
||||
// ext: '.txt',
|
||||
// name: 'file' }
|
||||
|
||||
┌─────────────────────┬────────────┐
|
||||
│ dir │ base │
|
||||
├──────┬ ├──────┬─────┤
|
||||
│ root │ │ name │ ext │
|
||||
│ dir sep base │
|
||||
├──────┬──────────────┼──────┬─────┤
|
||||
│ root │ path │ name │ ext │
|
||||
" / home/user/dir / file .txt "
|
||||
└──────┴──────────────┴──────┴─────┘
|
||||
(All spaces in the "" line should be ignored. They are purely for formatting.)
|
||||
|
||||
Every key need in wrapper: ${}
|
||||
sep just for prompt, can't be used
|
||||
default: ${base}
|
||||
runs:
|
||||
using: 'node16'
|
||||
|
|
26
dist/index.js
vendored
26
dist/index.js
vendored
|
@ -4781,8 +4781,10 @@ function run() {
|
|||
}
|
||||
const artifactsName = inputs['artifactsName'] || 'artifacts';
|
||||
const artifactPerFile = inputs['artifactPerFile'] || false;
|
||||
const rootDirectory = searchResult.rootDirectory;
|
||||
core.info('rootDirectory: ' + rootDirectory);
|
||||
if (!artifactPerFile) {
|
||||
const uploadResponse = yield artifactClient.uploadArtifact(artifactsName, searchResult.filesToUpload, searchResult.rootDirectory, options);
|
||||
const uploadResponse = yield artifactClient.uploadArtifact(artifactsName, searchResult.filesToUpload, rootDirectory, options);
|
||||
if (uploadResponse.failedItems.length > 0) {
|
||||
core.setFailed(`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
|
||||
}
|
||||
|
@ -4797,8 +4799,14 @@ function run() {
|
|||
const artifactNameRule = inputs['artifactNameRule'];
|
||||
for (let i = 0; i < filesToUpload.length; i++) {
|
||||
const file = filesToUpload[i];
|
||||
core.info(file);
|
||||
const pathObject = path_1.default.parse(file);
|
||||
core.info('file: ' + file);
|
||||
const pathObject = Object.assign({}, path_1.default.parse(file));
|
||||
const pathBase = pathObject.base;
|
||||
const pathRoot = path_1.default.parse(rootDirectory).dir;
|
||||
pathObject.root = pathRoot;
|
||||
core.info('root: ' + pathRoot);
|
||||
pathObject['path'] = file.slice(pathRoot.length, file.length - path_1.default.sep.length - pathBase.length);
|
||||
core.info('path: ' + pathObject['path']);
|
||||
let artifactName = artifactNameRule;
|
||||
for (const key of Object.keys(pathObject)) {
|
||||
const re = `$\{${key}}`;
|
||||
|
@ -4807,15 +4815,19 @@ function run() {
|
|||
artifactName = artifactName.replace(re, value);
|
||||
}
|
||||
}
|
||||
if (artifactName.includes(path_1.default.sep)) {
|
||||
core.warning(`${artifactName} includes ${path_1.default.sep}`);
|
||||
artifactName = artifactName.split(path_1.default.sep).join('_');
|
||||
if (artifactName.startsWith(path_1.default.sep)) {
|
||||
core.warning(`${artifactName} startsWith ${path_1.default.sep}`);
|
||||
artifactName = artifactName.slice(path_1.default.sep.length);
|
||||
}
|
||||
if (artifactName.includes(':')) {
|
||||
core.warning(`${artifactName} includes :`);
|
||||
artifactName = artifactName.split(':').join('-');
|
||||
}
|
||||
core.info(artifactName);
|
||||
if (artifactName.includes(path_1.default.sep)) {
|
||||
core.warning(`${artifactName} includes ${path_1.default.sep}`);
|
||||
artifactName = artifactName.split(path_1.default.sep).join('_');
|
||||
}
|
||||
core.debug(artifactName);
|
||||
const artifactItemExist = SuccessedItems.includes(artifactName);
|
||||
if (artifactItemExist) {
|
||||
const oldArtifactName = artifactName;
|
||||
|
|
|
@ -55,11 +55,14 @@ async function run(): Promise<void> {
|
|||
|
||||
const artifactsName = inputs['artifactsName'] || 'artifacts'
|
||||
const artifactPerFile = inputs['artifactPerFile'] || false
|
||||
const rootDirectory = searchResult.rootDirectory
|
||||
core.info('rootDirectory: ' + rootDirectory)
|
||||
|
||||
if (!artifactPerFile) {
|
||||
const uploadResponse = await artifactClient.uploadArtifact(
|
||||
artifactsName,
|
||||
searchResult.filesToUpload,
|
||||
searchResult.rootDirectory,
|
||||
rootDirectory,
|
||||
options
|
||||
)
|
||||
|
||||
|
@ -80,9 +83,20 @@ async function run(): Promise<void> {
|
|||
const artifactNameRule = inputs['artifactNameRule']
|
||||
for (let i = 0; i < filesToUpload.length; i++) {
|
||||
const file = filesToUpload[i]
|
||||
core.info(file)
|
||||
core.info('file: ' + file)
|
||||
|
||||
const pathObject = Object.assign({}, path.parse(file))
|
||||
const pathBase = pathObject.base
|
||||
const pathRoot = path.parse(rootDirectory).dir
|
||||
pathObject.root = pathRoot
|
||||
core.info('root: ' + pathRoot)
|
||||
|
||||
pathObject['path'] = file.slice(
|
||||
pathRoot.length,
|
||||
file.length - path.sep.length - pathBase.length
|
||||
)
|
||||
core.info('path: ' + pathObject['path'])
|
||||
|
||||
const pathObject = path.parse(file)
|
||||
let artifactName = artifactNameRule
|
||||
for (const key of Object.keys(pathObject)) {
|
||||
const re = `$\{${key}}`
|
||||
|
@ -91,15 +105,20 @@ async function run(): Promise<void> {
|
|||
artifactName = artifactName.replace(re, value)
|
||||
}
|
||||
}
|
||||
if (artifactName.includes(path.sep)) {
|
||||
core.warning(`${artifactName} includes ${path.sep}`)
|
||||
artifactName = artifactName.split(path.sep).join('_')
|
||||
|
||||
if (artifactName.startsWith(path.sep)) {
|
||||
core.warning(`${artifactName} startsWith ${path.sep}`)
|
||||
artifactName = artifactName.slice(path.sep.length)
|
||||
}
|
||||
if (artifactName.includes(':')) {
|
||||
core.warning(`${artifactName} includes :`)
|
||||
artifactName = artifactName.split(':').join('-')
|
||||
}
|
||||
core.info(artifactName)
|
||||
if (artifactName.includes(path.sep)) {
|
||||
core.warning(`${artifactName} includes ${path.sep}`)
|
||||
artifactName = artifactName.split(path.sep).join('_')
|
||||
}
|
||||
core.debug(artifactName)
|
||||
|
||||
const artifactItemExist = SuccessedItems.includes(artifactName)
|
||||
if (artifactItemExist) {
|
||||
|
|
Loading…
Reference in a new issue