@actions/artifact
在方案上与 动作艺术。 。 。 .
这是核心库 授权 @actions/upload-artifact 财务报告和审定财务报表 @actions/download-artifact 行动.
v2 - 什么是新东西
[大 @actions/artifact v2+,上传-artifact@v4+,下载-artifact@v4+目前尚未在GHES上支持. 此软件包的上一个版本可见于 此标签 财务报告和审定财务报表 时间。 。 。 .
释放 @actions/artifact@v2 (包括 upload-artifact@v4 财务报告和审定财务报表 download-artifact@v4)是Artifacts后端架构的重大变化. 他们有许多表现和行为上的改进.
改进
- 所有上传和下载操作都更快,在最坏的情况下,下载时间可达80%快,上传时间可达96%快.
- 一旦上传,就会返回人工识别码,并立即在用户界面中提供人工识别码 (原始内容存档于2013-10-12) (英语). REST API. 在此之前,您必须等待运行完成后才能获得身份证或使用任何API.
- 艺术现在可以从UI下载并删除 在此之前 整个工作流程完成.
- 艺术作品的内容一起上传到 不可改变 存档 。 以后的工作不能改变她们。 这两个因素都有助于减少意外地腐蚀Artifact文件的可能性. (Digest/Intigrity hash 即将出现在API!)
- 这个图书馆(和
actions/download-artifact)现在支持下载Artiffacts from 其他项目 存储和运行,如果有GITHUB_TOKEN足够actions:read提供了权限.
中断更改
-
自营跑道所需防火墙规则.
如果你在防火墙后面使用自备跑道,你一定可以打开 动作终点。如果无法使用通配符规则设置防火墙,请参见 GitHub 元终点 对于特定的终点.
譬如说.
curl https://api.github.com/meta | jq .domains.actions -
上传到同一名称的"艺术"多次.
由于这个新版本中Artifacts是如何被创建的,因此已经无法再上传到同名的Artifact上多次. 您必须把上传内容分割成多个不同名称的艺术作品, 或者只上传一次 .
-
限制个人工作的人工活性.
工作流程运行中的每一项工作现在都有10件文物的限制.
快速启动
安装软件包 :
npm i @actions/artifact
导入模块 :
// ES6 module
import {DefaultArtifactClient} from '@actions/artifact'
// CommonJS
const {DefaultArtifactClient} = require('@actions/artifact')
然后即时:
const artifact = new DefaultArtifactClient()
iQQ 类、界面、功能和更多类的完整列表见 生成的文件。 。 。 .
实例
上传和下载
最基本的情况是将一个或多个文件上传到Artifact,然后下载Artifact. 下载基于Artifact ID,可以在响应中获取 uploadArtifact, (中文(简体) ), getArtifact, (中文(简体) ), listArtifacts 或通过 (原始内容存档于2013-10-12) (英语). REST API。 。 。 .
const {id, size} = await artifact.uploadArtifact(
// name of the artifact
'my-artifact',
// files to include (supports absolute and relative paths)
['/absolute/path/file1.txt', './relative/file2.txt'],
{
// optional: how long to retain the artifact
// if unspecified, defaults to repository/org retention settings (the limit of this value)
retentionDays: 10
}
)
console.log(`Created artifact with id: ${id} (bytes: ${size}`)
const {downloadPath} = await artifact.downloadArtifact(id, {
// optional: download destination path. otherwise defaults to $GITHUB_WORKSPACE
path: '/tmp/dst/path',
})
console.log(`Downloaded artifact ${id} to: ${downloadPath}`)
删除艺术
要删除一件文物,只需要名字.
const {id} = await artifact.deleteArtifact(
// name of the artifact
'my-artifact'
)
console.log(`Deleted Artifact ID '${id}'`)
它也支持从其他 repos/ runs 中删除选项, 给一个 github 令牌 actions:write 提供了目标寄存器上的权限.
const findBy = {
// must have actions:write permission on target repository
token: process.env['GITHUB_TOKEN'],
workflowRunId: 123,
repositoryOwner: 'actions',
repositoryName: 'toolkit'
}
const {id} = await artifact.deleteArtifact(
// name of the artifact
'my-artifact',
// options to find by other repo/owner
{ findBy }
)
console.log(`Deleted Artifact ID '${id}' from ${findBy.repositoryOwner}/ ${findBy.repositoryName}`)
从其他工作流程下载运行或重置
从其他工作流程运行甚至其他寄存器中下载Artiffacts可能是有用的. 默认情况下,权限被范围化,因此只能在当前工作流程运行范围内下载Artiffacts. 要提升此方案的权限, 您必须指定 options.findBy 改为 downloadArtifact。 。 。 .
const findBy = {
// must have actions:read permission on target repository
token: process.env['GITHUB_TOKEN'],
workflowRunId: 123,
repositoryOwner: 'actions',
repositoryName: 'toolkit'
}
await artifact.downloadArtifact(1337, {
findBy
})
// can also be used in other methods
await artifact.getArtifact('my-artifact', {
findBy
})
await artifact.listArtifacts({
findBy
})
加快大型上传
如果您有需要上传的大文件(或压缩不完善的文件类型),您可能从改变Artifact归档的压缩级别中受益. 注:这是文物上传时间和所储存数据大小之间的取舍.
await artifact.uploadArtifact('my-massive-artifact', ['big_file.bin'], {
// The level of compression for Zlib to be applied to the artifact archive.
// - 0: No compression
// - 1: Best speed
// - 6: Default compression (same as GNU Gzip)
// - 9: Best compression
compressionLevel: 0
})