博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用 Github Actions 自动更新 docfx 文档
阅读量:4034 次
发布时间:2019-05-24

本文共 3029 字,大约阅读时间需要 10 分钟。

利用 Github Actions 自动更新 docfx 文档

Intro

docfx 是微软出品一个 .NET API 文档框架,有一个理念是代码即文档,会根据项目代码自动生成 API 文档,即使没有写任何注释也会生成 API 文档,也有一些默认的主题可以配置,也可以自定义主题配置,详细介绍可以参考官方介绍 https://dotnet.github.io/docfx/

目前也有很多项目在使用 docfx 来生成文档,比如前段时间介绍过的 Reserver-Proxy 项目,也是看到了 reservse-proxy 项目配置了一个 Github Actions 来自动更新文档所以在我自己的项目里也增加了类似的配置,除了微软的项目还有很多社区开源项目在用,如果你也在做一些 .NET 类库类的开源项目,可以尝试一下

docfx 怎么使用可以参考官方文档,本文主要介绍如何使用 Github Actions 实现自动更新文档

文档示例

更多可以参考: https://weihanli.github.io/WeihanLi.Npoi/index.html

自动更新文档流程

  1. 检出要使用的用于生成文档的分支代码

  2. 安装 docfx 命令行工具,推荐使用 choco 安装,因为执行 build 的 agent 上已经安装了 Chocolatey

  3. 使用 docfx 生成文档

  4. 检出 gh-pages 分支,用于托管文档的分支

  5. 删除 gh-pages 之前的文件(.git目录包含git信息,不能删除)

  6. 把第三步操作生成的文档复制到 gh-pages 分支下

  7. commit && push,提交代码并推送更新在线文档

Github Actions 示例配置

Actions 示例,源链接:https://github.com/WeihanLi/WeihanLi.Npoi/blob/dev/.github/workflows/docfx.yml

name: docfx buildon:  push:    branches:      - devjobs:  build:    name: Build    runs-on: windows-latest    steps:      # Check out the branch that triggered this workflow to the 'source' subdirectory      - name: Checkout Code        uses: actions/checkout@v2        with:          ref: dev          path: source      - name: install DocFX        run: "& choco install docfx -y"      # Run a build      - name: Build docs        run: "& docfx ./docfx.json"        working-directory: ./source      # Check out gh-pages branch to the 'docs' subdirectory      - name: Checkout docs        uses: actions/checkout@v2        with:          ref: gh-pages          path: docs      # Sync the site      - name: Clear docs repo        run: Get-ChildItem -Force -Exclude .git | ForEach-Object { Remove-Item -Recurse -Verbose -Force $_ }        working-directory: ./docs      - name: Sync new content        run: Copy-Item -Recurse -Verbose -Force "$env:GITHUB_WORKSPACE/source/_site/*" "$env:GITHUB_WORKSPACE/docs"        working-directory: ./docs        # update docs      - name: Commit to gh-pages and push        run: |          $ErrorActionPreference = "Continue"          git add -A          git diff HEAD --exit-code          if ($LASTEXITCODE -eq 0) {            Write-Host "No changes to commit!"          } else {            git config --global user.name "github-actions-docfx[bot]"            git config --global user.email "weihanli@outlook.com"            git commit -m "Updated docs from commit $env:GITHUB_SHA on $env:GITHUB_REF"            git remote set-url origin https://x-access-token:${
{ secrets.GITHUB_TOKEN }}@github.com/${
{ github.repository }} git push origin gh-pages } working-directory: ./docs

我这里是只要 dev 分支更新了就更新,你也可以根据需要当 master 分支更新时再更新,修改分支名称即可

More

现在用的还是 2.x 版本,3.x 版本还没发布,3.x版本发布之后可以直接通过 dotnet tool 来安装更加方便和可扩展,目前 2.x 使用 choco 来安装命令行工具,需要依赖 Chocolatey,如果是 dotnet tool 有 dotnet 环境就可以了,就可以方便很多了

不仅仅是 docfx 生成文档,你也可以扩展其他类似的需求,使用 Github Actions 实现自动同步,更新

Reference

  • https://github.com/dotnet/docfx

  • https://dotnet.github.io/docfx/tutorial/docfx_getting_started.html

  • https://github.com/WeihanLi/WeihanLi.Npoi

  • https://github.com/microsoft/reverse-proxy

转载地址:http://oqzdi.baihongyu.com/

你可能感兴趣的文章
linux 驱动开发 头文件
查看>>
/etc/resolv.conf
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>
ipconfig,ifconfig,iwconfig
查看>>
opensuse12.2 PL2303 minicom
查看>>
电平触发方式和边沿触发的区别
查看>>
网络视频服务器移植
查看>>
Encoding Schemes
查看>>
移植QT
查看>>
如此调用
查看>>
计算机的发展史
查看>>
带WiringPi库的交叉编译如何处理一
查看>>
带WiringPi库的交叉笔译如何处理二之软链接概念
查看>>
Spring事务的七种传播行为
查看>>
ES写入找不到主节点问题排查
查看>>
Java8 HashMap集合解析
查看>>
ArrayList集合解析
查看>>
欢迎使用CSDN-markdown编辑器
查看>>
Android计算器实现源码分析
查看>>