action-download-artifact 项目教程

action-download-artifact 项目教程

action-download-artifact :gear: A GitHub Action to download an artifact associated with given workflow and commit or other criteria action-download-artifact 项目地址: https://gitcode.com/gh_mirrors/ac/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,下载并提取指定的工作流工件。

action-download-artifact :gear: A GitHub Action to download an artifact associated with given workflow and commit or other criteria action-download-artifact 项目地址: https://gitcode.com/gh_mirrors/ac/action-download-artifact

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冯海莎Eliot

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值