- client 里的文件
- google sheet,暂时不包括俄语和繁体中文
通过修改client 里的文件
- 单独创建一个分支来修改表格里的内容,之后发起该分支 ->
master的 pull request - 合并 PR 之后,会自动生成各平台所需的字符串
- 修改 google sheet 内容后,会自动给该项目创建一个
script分支 - 需用户手动发起
script->master的 pull request,会自动把 google sheet 里修改的内容同步到 client.md 和 client 文件夹 - 合并 PR 之后,会自动生成各平台所需的字符串
因为暂时不支持 client 里的文件 同步到 google sheet 的功能,所以
俄语和繁体中文请修改 client 里的文件- 其他语言请 通过 google sheet 修改
如果项目中用到的平台生成工具出现 bug,那么修改完 bug 之后可手动运行生成平台字符串的脚本
创建 Google Sheet 到设置自动化的完整流程:
- 访问 Google Drive
- 点击左上角的"新建" → "Google 表格"
- 给表格一个合适的名字(点击左上角的"无标题的电子表格"进行重命名)
- 在 Google Sheet 中点击"扩展程序" → "Apps Script"
- 在打开的 Apps Script 编辑器中,将默认的
myFunction替换为你的代码 - 示例代码(根据你的需求):
function onSheetEdit(e) {
// 获取当前活动的表格
const sheet = SpreadsheetApp.getActiveSheet();
// 获取最后一行
const lastRow = sheet.getLastRow();
// 获取最后一列
const lastColumn = sheet.getLastColumn();
// 获取数据范围
const range = sheet.getRange(1, 1, lastRow, lastColumn);
const values = range.getValues();
// 导出为 XLSX
exportSheetToXLSX();
}
function exportSheetToXLSX() {
// 你的导出逻辑
}- 在 Apps Script 编辑器中,点击左侧的"触发器"图标(闹钟样式)
- 点击右下角的"添加触发器"
- 设置触发器:
- 选择要运行的函数:
onSheetEdit - 选择部署:
测试版本 - 事件源:
来自电子表格 - 事件类型:
编辑时
- 选择要运行的函数:
- 点击保存,并授予必要的权限
- 在 GitHub 创建新仓库
- 设置 GitHub Actions:
- 在仓库中创建
.github/workflows目录 - 创建 workflow 文件(例如
sync.yml):
- 在仓库中创建
name: Sync Google Sheet
on:
push:
paths:
- '**.xlsx' # 当 xlsx 文件发生变化时触发
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'
- name: Pull changes
run: git pull --rebase origin master
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master- 在 Apps Script 中添加 GitHub 相关的代码:
function pushToGitHub(fileBlob, fileName) {
// 这里需要你的 GitHub 个人访问令牌
const GITHUB_TOKEN = '你的GitHub Token';
const REPO_OWNER = '你的GitHub用户名';
const REPO_NAME = '仓库名称';
// GitHub API 端点
const apiUrl = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/contents/${fileName}`;
// 构建请求头
const headers = {
'Authorization': `token ${GITHUB_TOKEN}`,
'Accept': 'application/vnd.github.v3+json'
};
// 发送请求到 GitHub
const response = UrlFetchApp.fetch(apiUrl, {
method: 'PUT',
headers: headers,
payload: JSON.stringify({
message: 'Update from Google Sheet',
content: Utilities.base64Encode(fileBlob.getBytes()),
branch: 'master'
})
});
}- 创建 GitHub 个人访问令牌:
- 访问 GitHub Settings → Developer settings → Personal access tokens
- 生成新令牌,确保有适当的权限(repo 权限)
- 在 Apps Script 中保存令牌:
- 使用 Properties Service 存储令牌
- 或直接在代码中使用(不推荐)
- 在 Google Sheet 中做一些修改
- 检查 Apps Script 执行日志是否有错误
- 检查 GitHub 仓库是否正确更新
- 检查 GitHub Actions 是否正常运行
- 确保所有权限都正确设置
- 保护好你的令牌和敏感信息
- 考虑添加错误处理和日志记录
- 考虑添加重试机制
- 定期检查和维护自动化流程
