mirror of
https://gitea.com/actions/upload-artifact.git
synced 2024-11-23 09:05:58 +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/*
|
tar -zvcf path/to/dir-3/all.gz path/to/dir-3/*
|
||||||
|
|
||||||
# Upload a single file artifact
|
|
||||||
- name: 'Upload artifact #1'
|
- name: 'Upload artifact #1'
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
path: path/to/dir-1/file1.txt
|
path: path/to/dir-1/file1.txt
|
||||||
artifact-per-file: true
|
artifact-per-file: true
|
||||||
|
|
||||||
# Upload using a wildcard pattern, name should default to 'artifact' if not provided
|
|
||||||
- name: 'Upload artifact #2'
|
- name: 'Upload artifact #2'
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
@ -79,20 +77,18 @@ jobs:
|
||||||
artifact-per-file: true
|
artifact-per-file: true
|
||||||
artifact-name-rule: ${dir}-${base}
|
artifact-name-rule: ${dir}-${base}
|
||||||
|
|
||||||
# Upload a directory that contains a file that will be uploaded with GZip
|
|
||||||
- name: 'Upload artifact #3'
|
- name: 'Upload artifact #3'
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
path: path/to/dir-3/*.gz
|
path: path/to/dir-3/*.gz
|
||||||
artifact-per-file: true
|
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'
|
- name: 'Upload artifact #4'
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
path/**/dir*/
|
path/**/dir-1/
|
||||||
!path/to/dir-3/*.gz
|
!path/to/dir-3/*.gz
|
||||||
artifact-per-file: true
|
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"
|
default: "false"
|
||||||
artifact-name-rule:
|
artifact-name-rule:
|
||||||
description: >
|
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');
|
path.parse('/home/user/dir/file.txt');
|
||||||
// Returns:
|
// Returns:
|
||||||
// { root: '/',
|
// { root: '/',
|
||||||
// dir: '/home/user/dir',
|
// dir: '/home/user/dir',
|
||||||
|
// path: 'home/user/dir'
|
||||||
// base: 'file.txt',
|
// base: 'file.txt',
|
||||||
// ext: '.txt',
|
// ext: '.txt',
|
||||||
// name: 'file' }
|
// name: 'file' }
|
||||||
|
|
||||||
┌─────────────────────┬────────────┐
|
┌─────────────────────┬────────────┐
|
||||||
│ dir │ base │
|
│ dir sep base │
|
||||||
├──────┬ ├──────┬─────┤
|
├──────┬──────────────┼──────┬─────┤
|
||||||
│ root │ │ name │ ext │
|
│ root │ path │ name │ ext │
|
||||||
" / home/user/dir / file .txt "
|
" / home/user/dir / file .txt "
|
||||||
└──────┴──────────────┴──────┴─────┘
|
└──────┴──────────────┴──────┴─────┘
|
||||||
(All spaces in the "" line should be ignored. They are purely for formatting.)
|
(All spaces in the "" line should be ignored. They are purely for formatting.)
|
||||||
|
|
||||||
Every key need in wrapper: ${}
|
Every key need in wrapper: ${}
|
||||||
|
sep just for prompt, can't be used
|
||||||
default: ${base}
|
default: ${base}
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node16'
|
||||||
|
|
26
dist/index.js
vendored
26
dist/index.js
vendored
|
@ -4781,8 +4781,10 @@ function run() {
|
||||||
}
|
}
|
||||||
const artifactsName = inputs['artifactsName'] || 'artifacts';
|
const artifactsName = inputs['artifactsName'] || 'artifacts';
|
||||||
const artifactPerFile = inputs['artifactPerFile'] || false;
|
const artifactPerFile = inputs['artifactPerFile'] || false;
|
||||||
|
const rootDirectory = searchResult.rootDirectory;
|
||||||
|
core.info('rootDirectory: ' + rootDirectory);
|
||||||
if (!artifactPerFile) {
|
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) {
|
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.`);
|
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'];
|
const artifactNameRule = inputs['artifactNameRule'];
|
||||||
for (let i = 0; i < filesToUpload.length; i++) {
|
for (let i = 0; i < filesToUpload.length; i++) {
|
||||||
const file = filesToUpload[i];
|
const file = filesToUpload[i];
|
||||||
core.info(file);
|
core.info('file: ' + file);
|
||||||
const pathObject = path_1.default.parse(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;
|
let artifactName = artifactNameRule;
|
||||||
for (const key of Object.keys(pathObject)) {
|
for (const key of Object.keys(pathObject)) {
|
||||||
const re = `$\{${key}}`;
|
const re = `$\{${key}}`;
|
||||||
|
@ -4807,15 +4815,19 @@ function run() {
|
||||||
artifactName = artifactName.replace(re, value);
|
artifactName = artifactName.replace(re, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (artifactName.includes(path_1.default.sep)) {
|
if (artifactName.startsWith(path_1.default.sep)) {
|
||||||
core.warning(`${artifactName} includes ${path_1.default.sep}`);
|
core.warning(`${artifactName} startsWith ${path_1.default.sep}`);
|
||||||
artifactName = artifactName.split(path_1.default.sep).join('_');
|
artifactName = artifactName.slice(path_1.default.sep.length);
|
||||||
}
|
}
|
||||||
if (artifactName.includes(':')) {
|
if (artifactName.includes(':')) {
|
||||||
core.warning(`${artifactName} includes :`);
|
core.warning(`${artifactName} includes :`);
|
||||||
artifactName = artifactName.split(':').join('-');
|
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);
|
const artifactItemExist = SuccessedItems.includes(artifactName);
|
||||||
if (artifactItemExist) {
|
if (artifactItemExist) {
|
||||||
const oldArtifactName = artifactName;
|
const oldArtifactName = artifactName;
|
||||||
|
|
|
@ -55,11 +55,14 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
const artifactsName = inputs['artifactsName'] || 'artifacts'
|
const artifactsName = inputs['artifactsName'] || 'artifacts'
|
||||||
const artifactPerFile = inputs['artifactPerFile'] || false
|
const artifactPerFile = inputs['artifactPerFile'] || false
|
||||||
|
const rootDirectory = searchResult.rootDirectory
|
||||||
|
core.info('rootDirectory: ' + rootDirectory)
|
||||||
|
|
||||||
if (!artifactPerFile) {
|
if (!artifactPerFile) {
|
||||||
const uploadResponse = await artifactClient.uploadArtifact(
|
const uploadResponse = await artifactClient.uploadArtifact(
|
||||||
artifactsName,
|
artifactsName,
|
||||||
searchResult.filesToUpload,
|
searchResult.filesToUpload,
|
||||||
searchResult.rootDirectory,
|
rootDirectory,
|
||||||
options
|
options
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,9 +83,20 @@ async function run(): Promise<void> {
|
||||||
const artifactNameRule = inputs['artifactNameRule']
|
const artifactNameRule = inputs['artifactNameRule']
|
||||||
for (let i = 0; i < filesToUpload.length; i++) {
|
for (let i = 0; i < filesToUpload.length; i++) {
|
||||||
const file = filesToUpload[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
|
let artifactName = artifactNameRule
|
||||||
for (const key of Object.keys(pathObject)) {
|
for (const key of Object.keys(pathObject)) {
|
||||||
const re = `$\{${key}}`
|
const re = `$\{${key}}`
|
||||||
|
@ -91,15 +105,20 @@ async function run(): Promise<void> {
|
||||||
artifactName = artifactName.replace(re, value)
|
artifactName = artifactName.replace(re, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (artifactName.includes(path.sep)) {
|
|
||||||
core.warning(`${artifactName} includes ${path.sep}`)
|
if (artifactName.startsWith(path.sep)) {
|
||||||
artifactName = artifactName.split(path.sep).join('_')
|
core.warning(`${artifactName} startsWith ${path.sep}`)
|
||||||
|
artifactName = artifactName.slice(path.sep.length)
|
||||||
}
|
}
|
||||||
if (artifactName.includes(':')) {
|
if (artifactName.includes(':')) {
|
||||||
core.warning(`${artifactName} includes :`)
|
core.warning(`${artifactName} includes :`)
|
||||||
artifactName = artifactName.split(':').join('-')
|
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)
|
const artifactItemExist = SuccessedItems.includes(artifactName)
|
||||||
if (artifactItemExist) {
|
if (artifactItemExist) {
|
||||||
|
|
Loading…
Reference in a new issue