Skip to content

Commit

Permalink
💚 Fix generating docs on publish (#441)
Browse files Browse the repository at this point in the history
Fix updating docs on https://huggingface.co/docs/huggingface.js/index

The problem is that when publishing, the update to the `package.json`
file does not trigger the `documentation.yml` workflow due to safeguards
in github (triggering a workflow from another workflow)

So instead, we use `repository_dispatch` to trigger the doc build. It's
better than triggering a doc build every commit :)

cc @mishig25 for visibility
  • Loading branch information
coyotte508 authored Jan 17, 2024
1 parent 218e0a6 commit 4ce5f65
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/agents-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ jobs:
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Update Doc"
uses: peter-evans/repository-dispatch@v2
with:
event-type: doc-build
10 changes: 6 additions & 4 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ name: Build documentation

on:
workflow_dispatch:
repository_dispatch:
types: [doc-build]
push:
branches:
- main
paths:
- "README.md"
- "docs/**"
- "packages/hub/package.json"
- "packages/inference/package.json"
- "packages/agents/package.json"
- "packages/hub/README.md"
- "packages/inference/README.md"
- "packages/agents/README.md"
- ".github/workflows/documentation.yml"

jobs:
build:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/hub-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ jobs:
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Update Doc"
uses: peter-evans/repository-dispatch@v2
with:
event-type: doc-build
4 changes: 4 additions & 0 deletions .github/workflows/tasks-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ jobs:
- run: pnpm publish --no-git-checks .
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Update Doc"
uses: peter-evans/repository-dispatch@v2
with:
event-type: doc-build
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ If you want to run only specific tests, you can do `pnpm test -- -t "test name"`
- Add the package name in [`pnpm-workspace.yaml`](pnpm-workspace.yaml)
- Add a `package.json` inspired from the other packages ([`packages/hub/package.json`](packages/hub/package.json) / [`packages/agents/package.json`](packages/agents/package.json)) in `packages/<package name>/package.json`
- Run `pnpm install` at the root
- Edit [`packages/doc-internal/package.json`](packages/doc-internal/package.json) and add the two commands in the `scripts` section:
- `prepublish-<package name>`
- `doc-<package name>`
- Edit [`packages/doc-internal/package.json`](packages/doc-internal/package.json) and add the command in the `scripts` section:
- `doc-<package name>` (don't forget to edit the `start` command too)
- Add the `<package-name>-publish.yml` file in the `.github/workflows` folder, inspired from the other packages
- Add the package in the main README.md
- Add a `tsup.config.ts` file in the package folder, inspired from the other packages, or just use `tsup src/index.ts --format cjs,esm --clean --dts` as the build command
Expand Down
10 changes: 0 additions & 10 deletions packages/doc-internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ We run a few scripts in between, [fix-md-links](./fix-md-links.ts) and [update-t
```console
# Generate all docs
pnpm run start

# Generate docs for @huggingface/hub
pnpm run prepublish-hub

# Generate docs for @huggingface/inference
pnpm run prepublish-inference

# Generate docs for @huggingface/agents
pnpm run prepublish-agents

```

## HTML docs
Expand Down
3 changes: 0 additions & 3 deletions packages/doc-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"lint:check": "eslint --ext .cjs,.ts .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"prepublish-hub": "pnpm run fix-cdn-versions && pnpm run doc-hub && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"prepublish-inference": "pnpm run fix-cdn-versions && pnpm run doc-inference && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"prepublish-agents": "pnpm run fix-cdn-versions && pnpm run doc-agents && cp ../../README.md ../../docs/index.md && pnpm run update-toc && pnpm run fix-md-links && pnpm run fix-md-headinghashlinks",
"doc-hub": "typedoc --tsconfig ../hub/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/hub --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../hub/index.ts",
"doc-inference": "typedoc --tsconfig ../inference/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/inference --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../inference/src/index.ts",
"doc-agents": "typedoc --tsconfig ../agents/tsconfig.json --githubPages false --plugin typedoc-plugin-markdown --out ../../docs/agents --hideBreadcrumbs --hideInPageTOC --sourceLinkTemplate https://github.com/huggingface/huggingface.js/blob/main/{path}#L{line} ../agents/src/index.ts",
Expand Down

0 comments on commit 4ce5f65

Please sign in to comment.