我正在使用gradle。我有這樣的專案:
project/
--- sub1/
--- sub2/
我想將工件上傳為 2 個不同的檔案(即sub1.jar 分別上傳sub2.jar)。
實際上,我正在使用這份作業:
- uses: actions/upload-artifact@v3
with:
name: Artifacts
path: project*/build/libs/*.jar
但上傳的檔案只有一個檔案,檔案有子檔案夾。
我試圖運行相同的upload-artifact作業,但有不同的論點。我不能那樣做。
我不想復制/粘貼同一個作業,因為在未來我會有多個子專案,我不想有 50 行或相同的代碼......
如何上傳生成的檔案,或多次運行相同的作業?
uj5u.com熱心網友回復:
因此,使用矩陣策略將允許您對輸入串列執行此操作。
您可以在作業流程中執行類似的操作,該作業流程將對矩陣中的每個值執行相同的步驟。
some-job:
name: Job 1
runs-on: ubuntu-latest
strategy:
matrix:
subdir: [sub1, sub2]
steps:
- name: Create some files
run: echo "test data" > /tmp/${{ matrix.subdir }}/.test.jar
- uses: actions/upload-artifact@v3
with:
name: Artifacts
path: /tmp/${{ matrix.subdir }}/*.jar
uj5u.com熱心網友回復:
這似乎不可能,所以我制作了自己的腳本。我使用與actions/upload-artifact上傳本身相同的代碼。
我們應該運行具有所需依賴項的 JS 腳本@actions/artifact。因此,設定節點和 dep 有 2 個操作。
我的代碼是這樣的:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install NPM package
run: npm install @actions/artifact
- uses: actions/github-script@v6
name: Artifact script
with:
script: CHECK MY SCRIPT BELOW
我正在使用此腳本上傳所有子檔案夾中的所有檔案:
let artifact = require('@actions/artifact');
const fs = require('fs');
function getContentFrom(path, check) {
return fs.readdirSync(path).filter(function (file) {
return check == fs.statSync(path '/' file).isDirectory();
});
}
function getDirectories(path) {
return getContentFrom(path, true);
}
function getFiles(path) {
return getContentFrom(path, false);
}
const artifactClient = artifact.create();
for(let sub of getDirectories("./")) { // get all folders
console.log("Checking for", sub);
let filesDir = "./" sub; // if you are using multiples folder
let files = [];
for(let build of getFiles(filesDir)) {
// here you can filter which files to upload
files.push(filesDir "/" build);
}
console.log("Uploading", files);
await artifactClient.uploadArtifact(
"Project " sub,
files,
filesDir,
{ continueOnError: false }
)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/509864.html
