记录一次失败的定时导出语雀笔记到 github 仓库经历 (1)

github 有一个功能叫 Actions,可以用来指定定时任务。

再通过语雀的批量导出功能,就可以实现自动定时同步语雀笔记到github仓库。

第一步:导出文档

可惜,官方的 API 需要充值较贵的会员。因此,这里使用第三方开源的工具进行导出。这个工具叫 ytools 地址: https://github.com/vannvan/yuque-tools/

由于是第三方,建议各位谨慎使用。

通过阅读 ytools 的文档,得知我们可以通过以下命令,进行全部文档的导出。注: 需要 NodeJS 环境。

  1. 安装仓库
shell
复制代码
# 全局安装 ytool npm i yuque-tools -g
  1. 进行导出全部仓库
shell
复制代码
# secrets.YUQUE_USERNAME 语雀的用户名 一般是手机号 # secrets.YUQUE_PASSWORD 语雀的密码 # 不清楚是否为 Bug all 那里写两个才有效 ytool pull ${{ secrets.YUQUE_USERNAME }} ${{ secrets.YUQUE_PASSWORD }} all all lb

在本地进行测试,一切正常。

第二步:编排 Action

现在开始编排 Github Actions.

按照这个列表依次操作即可

  1. 新建一个仓库,用于保存笔记。
  2. 进入仓库的 Settings 页面
  • 打开你的 GitHub 仓库页面。
  • 在顶部菜单中,点击 Settings(设置)。
  1. 找到 Secrets and Variables
  • 在左侧菜单中,点击 Secrets and Variables。
  • 选择 Actions。这将显示你当前仓库中所有的 GitHub Secrets。
  1. 添加新的 Secret
  • 点击右上角的 New repository secret 按钮。
  • 依次添加 YUQUE_USERNAME YUQUE_PASSWORD

  1. 在本地项目根目录初始化 Git 仓库
shell
复制代码
git init git remote add origin https://github.com/your-username/your-repo.git
  1. 创建 .github/workflows/ 目录并在其中编写 Action YAML 文件。这里我让 GPT 生成的,供参考:
yaml
复制代码
name: Sync Notes to Private Repository on: schedule: - cron: '0 0 * * *' # 每天午夜 12 点运行 workflow_dispatch: # 允许手动触发 jobs: sync-notes: runs-on: ubuntu-latest steps: # Step 1: Checkout the repository - name: Checkout repository uses: actions/checkout@v3 # Step 2: Set up Node.js environment - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '16' # Step 3: Install ytool globally - name: Install ytool run: | npm i yuque-tools -g # Step 4: Pull notes from Yuque - name: Pull notes from Yuque run: | ytool pull ${{ secrets.YUQUE_USERNAME }} ${{ secrets.YUQUE_PASSWORD }} all all lb # Step 5: Move the notes to the root folder (i.e., from docs to root) - name: Move notes to root folder run: | mv docs/* ./ # 将 docs 文件夹中的内容移动到仓库根目录 # Step 6: Commit and push the pulled notes to the private repository - name: Commit and push changes run: | git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" git add . git commit -m "Sync notes from Yuque" git push env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  1. 提交这次的更改,并推送到远程仓库。这样就大功告成了。
yaml
复制代码
git add . git commit -m "Add GitHub Actions workflow" git branch -M main git push -u origin main

第三步:使用我们写的 Action 同步笔记

打开仓库的 Actions 选项就可以发现我们创建的 Action

根据 GPT 写的 YAML 文件,这个 Action 既可以当天晚上同步,也可以手动点击这个页面的 run workflow 进行同步。

触发条件后,就会自动执行 YAML 文件中的命令。

失败了

由于网络因素 这个无法在 Github Action 的环境进行成功导出

接下来 我还会继续研究 希望可以成功吧 🤣

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
JavierChen
下载 APP