mirror of
https://code.forgejo.org/actions/upload-artifact.git
synced 2024-12-23 12:36:00 +01:00
parent
65d862660a
commit
c7b5199c2b
8 changed files with 51 additions and 6 deletions
|
@ -149,6 +149,17 @@ describe('Search', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Single file search - Absolute Path - Manual directory', async () => {
|
||||||
|
const rootDirectory = path.join(root, 'folder-a')
|
||||||
|
const searchResult = await findFilesToUpload(
|
||||||
|
extraFileInFolderCPath,
|
||||||
|
rootDirectory
|
||||||
|
)
|
||||||
|
expect(searchResult.filesToUpload.length).toEqual(1)
|
||||||
|
expect(searchResult.filesToUpload[0]).toEqual(extraFileInFolderCPath)
|
||||||
|
expect(searchResult.rootDirectory).toEqual(rootDirectory)
|
||||||
|
})
|
||||||
|
|
||||||
it('Single file search - Relative Path', async () => {
|
it('Single file search - Relative Path', async () => {
|
||||||
const relativePath = path.join(
|
const relativePath = path.join(
|
||||||
'__tests__',
|
'__tests__',
|
||||||
|
|
|
@ -23,6 +23,10 @@ inputs:
|
||||||
|
|
||||||
Minimum 1 day.
|
Minimum 1 day.
|
||||||
Maximum 90 days unless changed from the repository settings page.
|
Maximum 90 days unless changed from the repository settings page.
|
||||||
|
root-directory:
|
||||||
|
description: >
|
||||||
|
A file path that denotes the root directory of the files being uploaded.
|
||||||
|
This path is used to strip the provided path(s) to control how they are uploaded and structured
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node16'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|
16
dist/index.js
vendored
16
dist/index.js
vendored
|
@ -10688,6 +10688,7 @@ var Inputs;
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["IfNoFilesFound"] = "if-no-files-found";
|
Inputs["IfNoFilesFound"] = "if-no-files-found";
|
||||||
Inputs["RetentionDays"] = "retention-days";
|
Inputs["RetentionDays"] = "retention-days";
|
||||||
|
Inputs["RootDirectory"] = "root-directory";
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var NoFileOptions;
|
var NoFileOptions;
|
||||||
(function (NoFileOptions) {
|
(function (NoFileOptions) {
|
||||||
|
@ -10746,6 +10747,7 @@ const constants_1 = __nccwpck_require__(9042);
|
||||||
function getInputs() {
|
function getInputs() {
|
||||||
const name = core.getInput(constants_1.Inputs.Name);
|
const name = core.getInput(constants_1.Inputs.Name);
|
||||||
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
||||||
|
const rootDirectory = core.getInput(constants_1.Inputs.RootDirectory);
|
||||||
const ifNoFilesFound = core.getInput(constants_1.Inputs.IfNoFilesFound);
|
const ifNoFilesFound = core.getInput(constants_1.Inputs.IfNoFilesFound);
|
||||||
const noFileBehavior = constants_1.NoFileOptions[ifNoFilesFound];
|
const noFileBehavior = constants_1.NoFileOptions[ifNoFilesFound];
|
||||||
if (!noFileBehavior) {
|
if (!noFileBehavior) {
|
||||||
|
@ -10754,7 +10756,8 @@ function getInputs() {
|
||||||
const inputs = {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName: name,
|
||||||
searchPath: path,
|
searchPath: path,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior,
|
||||||
|
rootDirectory: rootDirectory
|
||||||
};
|
};
|
||||||
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
||||||
if (retentionDaysStr) {
|
if (retentionDaysStr) {
|
||||||
|
@ -10874,7 +10877,7 @@ function getMultiPathLCA(searchPaths) {
|
||||||
}
|
}
|
||||||
return path.join(...commonPaths);
|
return path.join(...commonPaths);
|
||||||
}
|
}
|
||||||
function findFilesToUpload(searchPath, globOptions) {
|
function findFilesToUpload(searchPath, manualRootDirectory, globOptions) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const searchResults = [];
|
const searchResults = [];
|
||||||
const globber = yield glob.create(searchPath, globOptions || getDefaultGlobOptions());
|
const globber = yield glob.create(searchPath, globOptions || getDefaultGlobOptions());
|
||||||
|
@ -10906,6 +10909,13 @@ function findFilesToUpload(searchPath, globOptions) {
|
||||||
(0, core_1.debug)(`Removing ${searchResult} from rawSearchResults because it is a directory`);
|
(0, core_1.debug)(`Removing ${searchResult} from rawSearchResults because it is a directory`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Root directory manually set in inputs
|
||||||
|
if (manualRootDirectory) {
|
||||||
|
return {
|
||||||
|
filesToUpload: searchResults,
|
||||||
|
rootDirectory: manualRootDirectory
|
||||||
|
};
|
||||||
|
}
|
||||||
// Calculate the root directory for the artifact using the search paths that were utilized
|
// Calculate the root directory for the artifact using the search paths that were utilized
|
||||||
const searchPaths = globber.getSearchPaths();
|
const searchPaths = globber.getSearchPaths();
|
||||||
if (searchPaths.length > 1) {
|
if (searchPaths.length > 1) {
|
||||||
|
@ -10985,7 +10995,7 @@ function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const inputs = (0, input_helper_1.getInputs)();
|
const inputs = (0, input_helper_1.getInputs)();
|
||||||
const searchResult = yield (0, search_1.findFilesToUpload)(inputs.searchPath);
|
const searchResult = yield (0, search_1.findFilesToUpload)(inputs.searchPath, inputs.rootDirectory);
|
||||||
if (searchResult.filesToUpload.length === 0) {
|
if (searchResult.filesToUpload.length === 0) {
|
||||||
// No files were found, different use cases warrant different types of behavior if nothing is found
|
// No files were found, different use cases warrant different types of behavior if nothing is found
|
||||||
switch (inputs.ifNoFilesFound) {
|
switch (inputs.ifNoFilesFound) {
|
||||||
|
|
|
@ -3,7 +3,8 @@ export enum Inputs {
|
||||||
Name = 'name',
|
Name = 'name',
|
||||||
Path = 'path',
|
Path = 'path',
|
||||||
IfNoFilesFound = 'if-no-files-found',
|
IfNoFilesFound = 'if-no-files-found',
|
||||||
RetentionDays = 'retention-days'
|
RetentionDays = 'retention-days',
|
||||||
|
RootDirectory = 'root-directory'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum NoFileOptions {
|
export enum NoFileOptions {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {UploadInputs} from './upload-inputs'
|
||||||
export function getInputs(): UploadInputs {
|
export function getInputs(): UploadInputs {
|
||||||
const name = core.getInput(Inputs.Name)
|
const name = core.getInput(Inputs.Name)
|
||||||
const path = core.getInput(Inputs.Path, {required: true})
|
const path = core.getInput(Inputs.Path, {required: true})
|
||||||
|
const rootDirectory = core.getInput(Inputs.RootDirectory)
|
||||||
|
|
||||||
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
||||||
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
||||||
|
@ -25,7 +26,8 @@ export function getInputs(): UploadInputs {
|
||||||
const inputs = {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName: name,
|
||||||
searchPath: path,
|
searchPath: path,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior,
|
||||||
|
rootDirectory: rootDirectory
|
||||||
} as UploadInputs
|
} as UploadInputs
|
||||||
|
|
||||||
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
||||||
|
|
|
@ -80,6 +80,7 @@ function getMultiPathLCA(searchPaths: string[]): string {
|
||||||
|
|
||||||
export async function findFilesToUpload(
|
export async function findFilesToUpload(
|
||||||
searchPath: string,
|
searchPath: string,
|
||||||
|
manualRootDirectory?: string,
|
||||||
globOptions?: glob.GlobOptions
|
globOptions?: glob.GlobOptions
|
||||||
): Promise<SearchResult> {
|
): Promise<SearchResult> {
|
||||||
const searchResults: string[] = []
|
const searchResults: string[] = []
|
||||||
|
@ -121,6 +122,14 @@ export async function findFilesToUpload(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Root directory manually set in inputs
|
||||||
|
if (manualRootDirectory) {
|
||||||
|
return {
|
||||||
|
filesToUpload: searchResults,
|
||||||
|
rootDirectory: manualRootDirectory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the root directory for the artifact using the search paths that were utilized
|
// Calculate the root directory for the artifact using the search paths that were utilized
|
||||||
const searchPaths: string[] = globber.getSearchPaths()
|
const searchPaths: string[] = globber.getSearchPaths()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,10 @@ import {NoFileOptions} from './constants'
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
const searchResult = await findFilesToUpload(inputs.searchPath)
|
const searchResult = await findFilesToUpload(
|
||||||
|
inputs.searchPath,
|
||||||
|
inputs.rootDirectory
|
||||||
|
)
|
||||||
if (searchResult.filesToUpload.length === 0) {
|
if (searchResult.filesToUpload.length === 0) {
|
||||||
// No files were found, different use cases warrant different types of behavior if nothing is found
|
// No files were found, different use cases warrant different types of behavior if nothing is found
|
||||||
switch (inputs.ifNoFilesFound) {
|
switch (inputs.ifNoFilesFound) {
|
||||||
|
|
|
@ -20,4 +20,9 @@ export interface UploadInputs {
|
||||||
* Duration after which artifact will expire in days
|
* Duration after which artifact will expire in days
|
||||||
*/
|
*/
|
||||||
retentionDays: number
|
retentionDays: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A file path that denotes the root directory of the files being uploaded
|
||||||
|
*/
|
||||||
|
rootDirectory: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue