Keepalive Workflow 使用教程
1. 项目目录结构及介绍
Keepalive Workflow 是一个用于保持 GitHub 仓库活跃状态的 GitHub Action。以下是项目的目录结构及其说明:
.
├── .github/
│ ├── workflows/
│ │ └── keepalive.yml # GitHub Action 工作流配置文件
├── dist/
├── .all-contributorsrc
├── .editorconfig
├── .gitignore
├── .jshintrc
├── .npmignore
├── .npmrc
├── .nvmrc
├── LICENSE # 许可证文件
├── README.md # 项目说明文件
├── action.yml # GitHub Action 配置文件
├── index.js # JavaScript 执行文件
├── library.js # JavaScript 库文件
├── package.json # 项目依赖配置文件
├── util.js # 工具库文件
└── yarn.lock # Yarn 锁文件
2. 项目的启动文件介绍
项目的启动文件是 index.js
。该文件包含了 Keepalive Workflow 的主要逻辑。它会根据配置文件中的设置,通过 GitHub API 或创建一个虚拟提交(dummy commit)来保持仓库的活跃状态。
const core = require('@actions/core');
const { KeepAliveWorkflow, APIKeepAliveWorkflow } = require('keepalive-workflow');
// 使用虚拟提交模式
KeepAliveWorkflow(
githubToken,
committerUsername,
committerEmail,
commitMessage,
timeElapsed
).then(
(message) => {
core.info(message);
process.exit(0);
}
).catch(
(error) => {
core.error(error);
process.exit(1);
}
);
// 使用 GitHub API 模式
APIKeepAliveWorkflow(
githubToken,
{ timeElapsed }
).then(
(message) => {
core.info(message);
process.exit(0);
}
).catch(
(error) => {
core.error(error);
process.exit(1);
}
);
3. 项目的配置文件介绍
项目的配置文件是 action.yml
。该文件定义了 GitHub Action 的输入参数和默认值。以下是配置文件的主要内容:
name: 'Keepalive Workflow'
inputs:
gh_token:
description: 'GitHub access token with Repo scope'
required: false
commit_message:
description: 'Commit message used while committing to the repo'
required: false
committer_username:
description: 'Username used while committing to the repo'
default: 'gkr-bot'
committer_email:
description: 'Email id used while committing to the repo'
default: 'gkr@tuta.io'
time_elapsed:
description: 'Time elapsed from the previous commit to trigger a new automated commit'
default: 45
在这个配置文件中,用户可以自定义 GitHub Token、提交信息、提交者用户名、提交者邮箱以及触发自动提交的时间间隔。这些参数可以在使用 Action 时通过 with
关键字进行覆盖。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考