WIP GitHub Action 使用教程

WIP GitHub Action 使用教程

action The WIP GitHub Action 项目地址: https://gitcode.com/gh_mirrors/action3/action

1. 项目的目录结构及介绍

WIP GitHub Action 项目的目录结构如下:

.
├── github
│   └── workflows
├── dist
├── test
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── action.yml
├── index.js
├── package-lock.json
└── package.json

目录结构介绍

  • github/workflows: 存放 GitHub Actions 的工作流文件。
  • dist: 存放编译后的文件。
  • test: 存放测试文件。
  • .gitignore: 指定 Git 忽略的文件和目录。
  • CODE_OF_CONDUCT.md: 项目的行为准则。
  • LICENSE: 项目的开源许可证。
  • README.md: 项目的介绍和使用说明。
  • action.yml: GitHub Action 的配置文件。
  • index.js: 项目的主入口文件。
  • package-lock.json: 锁定项目依赖的版本。
  • package.json: 项目的依赖和脚本配置文件。

2. 项目的启动文件介绍

项目的启动文件是 index.js。这个文件是 WIP GitHub Action 的核心逻辑所在,负责检查 Pull Request 的标题是否包含 "WIP",并根据检查结果设置 Pull Request 的状态。

index.js 文件内容概述

// index.js 文件内容概述
const core = require('@actions/core');
const github = require('@actions/github');

async function run() {
  try {
    const title = github.context.payload.pull_request.title;
    const isWip = title.includes('WIP');

    if (isWip) {
      core.setFailed('Work in progress');
    } else {
      core.info('Ready for review');
    }
  } catch (error) {
    core.setFailed(error.message);
  }
}

run();

功能介绍

  • 检查标题: 通过 github.context.payload.pull_request.title 获取 Pull Request 的标题。
  • 判断是否为 WIP: 使用 title.includes('WIP') 判断标题是否包含 "WIP"。
  • 设置状态: 如果标题包含 "WIP",则设置状态为失败,否则设置为成功。

3. 项目的配置文件介绍

项目的配置文件主要包括 action.ymlpackage.json

action.yml

action.yml 是 GitHub Action 的配置文件,定义了 Action 的输入、输出、运行环境等信息。

# action.yml 文件内容概述
name: 'WIP'
description: 'Sets a pull request status to pending if the title includes "WIP"'
author: 'wip'
inputs:
  GITHUB_TOKEN:
    description: 'GitHub token'
    required: true
runs:
  using: 'node12'
  main: 'index.js'

配置项介绍

  • name: Action 的名称。
  • description: Action 的描述。
  • author: Action 的作者。
  • inputs: 定义 Action 的输入参数,例如 GITHUB_TOKEN
  • runs: 定义 Action 的运行环境,使用 node12,并指定主入口文件为 index.js

package.json

package.json 是 Node.js 项目的配置文件,定义了项目的依赖、脚本等信息。

{
  "name": "wip-action",
  "version": "1.0.0",
  "description": "A GitHub Action to set a pull request status to pending if the title includes 'WIP'",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "wip",
  "license": "Apache-2.0",
  "dependencies": {
    "@actions/core": "^1.2.6",
    "@actions/github": "^4.0.0"
  }
}

配置项介绍

  • name: 项目的名称。
  • version: 项目的版本号。
  • description: 项目的描述。
  • main: 项目的主入口文件。
  • scripts: 定义项目的脚本,例如 test
  • author: 项目的作者。
  • license: 项目的开源许可证。
  • dependencies: 项目的依赖,例如 @actions/core@actions/github

通过以上介绍,您可以更好地理解和使用 WIP GitHub Action 项目。

action The WIP GitHub Action 项目地址: https://gitcode.com/gh_mirrors/action3/action

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

孔岱怀

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

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

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

打赏作者

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

抵扣说明:

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

余额充值