如何多次运行同一个github操作作业



我正在使用gradle。我有这样的项目:

project/
--- sub1/
--- sub2/

我想把工件上传为两个不同的文件(即sub1.jarsub2.jar分别(。

事实上,我正在使用这份工作:

- uses: actions/upload-artifact@v3
with:
name: Artifacts
path: project*/build/libs/*.jar

但上传的文件只是一个文件,有子文件夹到文件。

我尝试运行相同的upload-artifact作业,但使用了不同的参数。我不能那样做。

我不想复制/粘贴同一份工作,因为在未来我会有多个子项目,我不想有50行或相同的代码。。。

如何上传生成的文件,或多次运行同一作业?

因此,使用矩阵策略可以对输入列表执行此操作。

您可以在工作流中执行类似的操作,对矩阵中的每个值执行相同的步骤。

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

这似乎不可能,所以我制作了自己的脚本。我正在使用与actions/upload-artifact相同的代码进行上传。

我们应该运行具有所需依赖@actions/artifact的JS脚本。因此,有两个操作来设置节点和dep.

我的代码是这样的:

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 }
)
}

最新更新