action-download-artifact 项目教程
1. 项目的目录结构及介绍
action-download-artifact/
├── .github/
│ └── workflows/
├── node_modules/
├── .gitignore
├── LICENSE
├── README.md
├── action.yml
├── main.js
├── package-lock.json
├── package.json
└── test/
- .github/workflows/: 包含GitHub Actions的工作流配置文件。
- node_modules/: 包含项目依赖的Node.js模块。
- .gitignore: 指定Git版本控制系统忽略的文件和目录。
- LICENSE: 项目的开源许可证文件。
- README.md: 项目的介绍和使用说明。
- action.yml: GitHub Action的配置文件。
- main.js: 项目的主要执行文件。
- package-lock.json: 锁定项目依赖的版本。
- package.json: 项目的元数据和依赖管理文件。
- test/: 包含项目的测试文件。
2. 项目的启动文件介绍
main.js
main.js
是项目的启动文件,负责执行下载和提取工作流工件的主要逻辑。它通过读取配置文件 action.yml
中的参数,与GitHub API交互,下载指定的工件并将其解压缩到指定目录。
// main.js 文件示例
const core = require('@actions/core');
const github = require('@actions/github');
const artifact = require('./artifact');
async function run() {
try {
const token = core.getInput('github_token', { required: true });
const workflow = core.getInput('workflow');
const runId = core.getInput('run_id');
const artifactName = core.getInput('name');
const path = core.getInput('path');
const octokit = github.getOctokit(token);
const artifacts = await artifact.downloadArtifact(octokit, workflow, runId, artifactName, path);
core.setOutput('artifacts', artifacts);
} catch (error) {
core.setFailed(error.message);
}
}
run();
3. 项目的配置文件介绍
action.yml
action.yml
是GitHub Action的配置文件,定义了Action的输入、输出和运行环境。以下是该文件的主要内容:
name: 'Download Artifact'
description: 'A GitHub Action to download an artifact associated with given workflow and commit or other criteria'
inputs:
github_token:
description: 'GitHub token'
required: true
workflow:
description: 'Workflow file name or ID'
required: false
run_id:
description: 'Workflow run ID'
required: false
name:
description: 'Uploaded artifact name'
required: false
path:
description: 'Directory where to extract artifact(s)'
required: false
runs:
using: 'node16'
main: 'main.js'
- github_token: 用于与GitHub API交互的令牌。
- workflow: 工作流的文件名或ID。
- run_id: 工作流运行的ID。
- name: 上传的工件名称。
- path: 提取工件的目标目录。
通过这些配置,用户可以在GitHub Actions中使用该Action,下载并提取指定的工作流工件。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考