如何在 GitHub Actions 中自动化并发布文档?

6

我希望自动化构建和发布托管在Github上的开源TypeScript项目的文档。

我尝试了TypeDoc,生成的docs文件夹大小为23Mo。我不想将其提交到项目的存储库中。

理想情况下,每次发布时,我都希望使用GitHub Actions来:

  • 生成文档
  • 将生成的docs文件夹推送到自己的GitHub存储库中

目前,我已添加了一个npm脚本以生成文档:docs: typedoc --out docs src,以下是我的github action文件的起始点:

name: Docs

on:
  release:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12
      - name: Generate docs
        run: |
          npm ci
          npm run docs

从这个操作中,我该如何将这个生成的目录提交并推送到它自己在Github上的仓库?(也许有更常规的方法来完成这个操作。请告诉我)
2个回答

0

如果你想提交并推送变更,可以参考 Github 市场中的一些操作,例如 github-pushpush changes 等,以查看它们是否适合你的情况。另外,你可以编写自己的脚本来调用 Github 的 API,例如我使用 Pygithub 调用 Github 的 API 来帮助我生成变更日志并更新存储库中的文件。


0

您可以使用github-action-push-to-another-repository操作来实现此目的:

- name: Pushes to another repository
  uses: cpina/github-action-push-to-another-repository@main
  env:
    API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
  with:
    source-directory: <directory-where-the-dist-is-generated>
    destination-github-username: <github-username>
    destination-repository-name: <github-repository-name>
    user-email: <github-email>
    target-branch: <main/master>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接