How to automate and publish docs in CI (github actions)?

Viewed 615

I want to automate the build and publishing of the docs of an open source typescript project hosted on Github.

I tried TypeDoc and the generated docs folder is 23Mo. I don't want to commit it in the project's repo.

Ideally, on each release, I would like to use github actions to:

  • generate the docs
  • push that generated docs folder to its own github repo.

Currently I added a npm script to generate the docs: docs: typedoc --out docs src and here is the starting point of my github action file:

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

From this action, how can I commit and push this generated directory to its own repo on github?

(Maybe there is a more conventional way to do that. Let me know)

2 Answers

If you want to commit and push changes, you can refer to some actions in the Github's marketplace like github-push or push changes to see if they are fitting your situation. Also, you can write your own script to call Github's API, e.g. I use Pygithub to call Github's APT to help me generate changelog and update the file in the repo.

You can use the github-action-push-to-another-repository action for this purpose:

- 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>
Related