开源项目 git-mirror-action
使用教程
1. 项目的目录结构及介绍
git-mirror-action
项目的目录结构如下:
.
├── .github
│ └── workflows
│ └── mirror.yml
├── .gitignore
├── LICENSE
├── README.md
├── action.yml
└── src
└── main.ts
目录结构介绍
.github/workflows/mirror.yml
: GitHub Actions 的工作流配置文件,用于定义镜像操作的自动化流程。.gitignore
: 指定 Git 忽略的文件和目录。LICENSE
: 项目的开源许可证。README.md
: 项目的主要说明文档。action.yml
: GitHub Actions 的自定义动作配置文件。src/main.ts
: 项目的主要源代码文件。
2. 项目的启动文件介绍
项目的启动文件是 src/main.ts
,它包含了镜像操作的主要逻辑。以下是该文件的简要介绍:
// src/main.ts
import * as core from '@actions/core';
import * as github from '@actions/github';
import { mirrorRepo } from './mirror';
async function run() {
try {
const sourceRepo = core.getInput('source_repo');
const targetRepo = core.getInput('target_repo');
await mirrorRepo(sourceRepo, targetRepo);
} catch (error) {
core.setFailed(error.message);
}
}
run();
启动文件介绍
run
函数:定义了镜像操作的主要流程,包括获取源仓库和目标仓库的输入,并调用mirrorRepo
函数进行镜像操作。mirrorRepo
函数:具体实现仓库镜像的逻辑。
3. 项目的配置文件介绍
项目的配置文件主要包括 .github/workflows/mirror.yml
和 action.yml
。
.github/workflows/mirror.yml
name: Mirroring
on: [push]
jobs:
to_foundries:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: wearerequired/git-mirror-action@main
with:
source_repo: ${{ secrets.SOURCE_REPO }}
target_repo: ${{ secrets.TARGET_REPO }}
配置文件介绍
name
: 工作流的名称。on
: 定义触发工作流的事件,这里是push
事件。jobs
: 定义工作流中的任务。to_foundries
: 任务名称。runs-on
: 指定运行任务的虚拟机环境。steps
: 定义任务的具体步骤。actions/checkout@v2
: 使用 GitHub 官方的 checkout 动作。wearerequired/git-mirror-action@main
: 使用本项目的镜像动作,并配置源仓库和目标仓库的输入。
action.yml
name: 'Git Mirror Action'
description: 'Mirror a Git repository to another'
inputs:
source_repo:
description: 'The source repository URL'
required: true
target_repo:
description: 'The target repository URL'
required: true
runs:
using: 'node12'
main: 'dist/index.js'
配置文件介绍
name
: 动作的名称。description
: 动作的描述。inputs
: 定义动作的输入参数。source_repo
: 源仓库的 URL。target_repo
: 目标仓库的 URL。
runs
: 定义动作的运行方式,使用 Node.js 12 运行dist/index.js
文件。
以上是 git-mirror-action
项目的使用教程,涵盖了项目的目录结构、启动文件和配置文件的详细介绍。