From b39382b52d64eeb1425ab92a81a0542affffe145 Mon Sep 17 00:00:00 2001 From: Emmanuel Lampe Date: Tue, 22 Aug 2023 18:56:01 +0200 Subject: [PATCH] feat: glob pattern for source inputs --- action.yml | 3 +++ package-lock.json | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/index.js | 34 ++++++++++++++++++++++++++-------- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 8e2680f..7b134fe 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,9 @@ inputs: description: "Decompress archive file after upload in target" required: false default: false + follow-symbolic-links: + description: "Indicates whether to follow symbolic links" + default: true runs: using: "node16" main: "dist/index.js" diff --git a/package-lock.json b/package-lock.json index b4f7297..5a79429 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", + "@actions/glob": "^0.4.0", "axios": "^1.4.0" }, "devDependencies": { @@ -37,6 +38,15 @@ "@octokit/plugin-rest-endpoint-methods": "^5.13.0" } }, + "node_modules/@actions/glob": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.4.0.tgz", + "integrity": "sha512-+eKIGFhsFa4EBwaf/GMyzCdWrXWymGXfFmZU3FHQvYS8mPcHtTtZONbkcqqUMzw9mJ/pImEBFET1JNifhqGsAQ==", + "dependencies": { + "@actions/core": "^1.9.1", + "minimatch": "^3.0.4" + } + }, "node_modules/@actions/http-client": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.0.tgz", @@ -170,11 +180,25 @@ "proxy-from-env": "^1.1.0" } }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==" }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -186,6 +210,11 @@ "node": ">= 0.8" } }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -258,6 +287,17 @@ "node": ">= 0.6" } }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/node-fetch": { "version": "2.6.11", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz", diff --git a/package.json b/package.json index f3f9363..4c75748 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", + "@actions/glob": "^0.4.0", "axios": "^1.4.0" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index d8b50e7..1ecd525 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ const core = require("@actions/core"); const axios = require("axios").default; const fs = require("fs").promises; const path = require("path"); +const glob = require("@actions/glob"); axios.defaults.headers.common.Accept = "application/json"; @@ -19,8 +20,17 @@ async function main() { decompressTarget, } = settings; + let fileSourcePaths = []; + for (const source of sourceListPath) { + const globber = await glob.create(source, { + followSymbolicLinks: settings.followSymbolicLinks, + }); + const files = await globber.glob(); + fileSourcePaths = [...fileSourcePaths, ...files]; + } + for (const serverId of serverIds) { - for (const source of sourceListPath) { + for (const source of fileSourcePaths) { await validateSourceFile(source); const targetFile = getTargetFile(targetPath, source); const buffer = await fs.readFile(source); @@ -35,15 +45,21 @@ async function main() { for (const element of targets) { const { source, target } = element; - await validateSourceFile(source); - const targetFile = getTargetFile(target, source); - const buffer = await fs.readFile(source); + const globber = await glob.create(source, { + followSymbolicLinks: settings.followSymbolicLinks, + }); + const paths = await globber.glob(); + for (const source of paths) { + await validateSourceFile(source); + const targetFile = getTargetFile(target, source); + const buffer = await fs.readFile(source); - await uploadFile(serverId, targetFile, buffer); + await uploadFile(serverId, targetFile, buffer); - if (decompressTarget && isArchiveFile(targetFile)) { - await decompressFile(serverId, targetFile); - await deleteFile(serverId, targetFile); + if (decompressTarget && isArchiveFile(targetFile)) { + await decompressFile(serverId, targetFile); + await deleteFile(serverId, targetFile); + } } } @@ -62,6 +78,7 @@ async function getSettings() { const restart = getInput("restart") == "true"; const proxy = getInput("proxy"); const decompressTarget = getInput("decompress-target") == "true"; + const followSymbolicLinks = getInput("follow-symbolic-links") == "true"; let sourcePath = getInput("source"); let sourceListPath = getMultilineInput("sources"); @@ -125,6 +142,7 @@ async function getSettings() { serverIds, targets, decompressTarget, + followSymbolicLinks, }; }