Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .github/workflows/build_documentation.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/build_pr_documentation.yml

This file was deleted.

173 changes: 173 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: Docs

# Builds the docs with HF doc-builder and publishes them to GitHub Pages (gh-pages
# branch), with no Hugging Face token:
# - push to main -> <site>/main/
# - release tag vX.Y.Z -> <site>/vX.Y.Z/
# - manual run + version -> rebuilds that release from its tag
# - pull request -> build only; docs_pr_preview.yml publishes it to
# <site>/pr-preview/pr-N/
# docs/pages/ adds the site layout that huggingface.co provides for doc-builder pages.

on:
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
pull_request:
paths:
- "docs/**"
- "src/openenv/**"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/docs.yml"
workflow_dispatch:
inputs:
version:
description: "Release tag to rebuild, e.g. v0.14.0. Leave empty to rebuild main."
required: false
default: ""

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || inputs.version || github.ref }}
cancel-in-progress: true

env:
# doc-builder commit used for the build. docs_builder_update.yml opens an issue
# when huggingface/doc-builder moves ahead of it.
DOC_BUILDER_SHA: 07d98817a2624c1fe067d4268e1f80d1988cfe71
# Set the DOCS_SITE_URL repository variable when moving to a custom domain.
ROOT_URL: ${{ vars.DOCS_SITE_URL || 'https://openenv.github.io/OpenEnv' }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
dest: ${{ steps.target.outputs.dest }}
publish: ${{ steps.target.outputs.publish }}
steps:
- name: Pick the target
id: target
env:
EVENT: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
INPUT_VERSION: ${{ inputs.version }}
run: |
if [ "$EVENT" = pull_request ]; then
version=main dest="pr-preview/pr-$PR_NUMBER" label="PR #$PR_NUMBER" ref="$GITHUB_SHA" publish=false noindex=true
elif [ -n "$INPUT_VERSION" ]; then
version="$INPUT_VERSION" dest="$INPUT_VERSION" label="$INPUT_VERSION" ref="refs/tags/$INPUT_VERSION"
elif [ "$GITHUB_REF_TYPE" = tag ]; then
version="$GITHUB_REF_NAME" dest="$GITHUB_REF_NAME" label="$GITHUB_REF_NAME" ref="$GITHUB_SHA"
else
version=main dest=main label=main ref="$GITHUB_SHA"
fi
if [[ ! "$version" =~ ^(main|v[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "::error::Not a release tag: $version"
exit 1
fi
if [ "$EVENT" != pull_request ]; then
# Only main publishes (a manual run from another branch only builds).
if [ "$GITHUB_REF" = refs/heads/main ] || [ "$GITHUB_REF_TYPE" = tag ]; then publish=true; else publish=false; fi
versions_url="$ROOT_URL/versions.json"
fi
{
echo "version=$version"
echo "dest=$dest"
echo "label=$label"
echo "ref=$ref"
echo "publish=$publish"
echo "versions_url=${versions_url:-}"
echo "noindex=${noindex:-}"
} >> "$GITHUB_OUTPUT"

# doc-builder derives the "Update on GitHub" links from this folder name.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ steps.target.outputs.ref }}
path: OpenEnv
persist-credentials: false

# Site scripts come from this commit, so older release tags can be rebuilt.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: tools
sparse-checkout: docs/pages
persist-credentials: false

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: huggingface/doc-builder
ref: ${{ env.DOC_BUILDER_SHA }}
path: doc-builder
persist-credentials: false

- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "20"

- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3

- name: Install doc-builder and OpenEnv
run: |
uv venv --python 3.11
uv pip install ./doc-builder "./OpenEnv[core,cli]"

- name: Build pages with doc-builder
env:
NODE_OPTIONS: --max-old-space-size=6656
VERSION: ${{ steps.target.outputs.version }}
run: |
source .venv/bin/activate
cd doc-builder
doc-builder build openenv ../OpenEnv/docs/source \
--build_dir ../build --html --clean --version "$VERSION" \
--repo_owner openenv --repo_name OpenEnv

- name: Add the site layout
env:
VERSION: ${{ steps.target.outputs.version }}
DEST: ${{ steps.target.outputs.dest }}
LABEL: ${{ steps.target.outputs.label }}
VERSIONS_URL: ${{ steps.target.outputs.versions_url }}
NOINDEX: ${{ steps.target.outputs.noindex }}
run: |
source .venv/bin/activate
python tools/docs/pages/build_site.py "build/openenv/$VERSION/en" site \
--site-url "$ROOT_URL/$DEST" --version-label "$LABEL" \
${VERSIONS_URL:+--versions-url "$VERSIONS_URL"} ${NOINDEX:+--noindex}

- name: Compile the stylesheet
run: |
npm ci --prefix doc-builder/kit --no-audit --no-fund
node tools/docs/pages/build_css.mjs doc-builder/kit site site/docs.css

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: docs-site
path: site
retention-days: 7

publish:
needs: build
if: needs.build.outputs.publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: docs-site
path: site

- name: Publish to gh-pages
env:
DEST: ${{ needs.build.outputs.dest }}
run: docs/pages/publish.sh "$DEST" site
56 changes: 56 additions & 0 deletions .github/workflows/docs_builder_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: doc-builder update check

# Dependabot cannot see the doc-builder commit pinned in docs.yml (it is not a
# `uses:` reference), so check it weekly and keep one issue open while
# huggingface/doc-builder main is ahead of the pin.

on:
schedule:
- cron: "0 7 * * 1"
workflow_dispatch:

permissions: {}

jobs:
check:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
TITLE: "Update the pinned doc-builder commit"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: .github/workflows/docs.yml
sparse-checkout-cone-mode: false
persist-credentials: false

- name: Compare the pin with doc-builder main
run: |
pinned=$(sed -nE 's/^ *DOC_BUILDER_SHA: ([0-9a-f]{40}).*/\1/p' .github/workflows/docs.yml)
latest=$(gh api repos/huggingface/doc-builder/commits/main --jq .sha)
issue=$(gh issue list -R "$REPO" --state open --search "\"$TITLE\" in:title" \
--json number,title --jq "map(select(.title == \"$TITLE\")) | .[0].number // empty")
if [ "$pinned" = "$latest" ]; then
echo "doc-builder pin is up to date"
if [ -n "$issue" ]; then
gh issue close "$issue" -R "$REPO" --comment "The pin now matches doc-builder main."
fi
exit 0
fi
ahead=$(gh api "repos/huggingface/doc-builder/compare/$pinned...$latest" --jq .ahead_by)
body="huggingface/doc-builder main is $ahead commit(s) ahead of the commit pinned in \`.github/workflows/docs.yml\`.

- Pinned: \`$pinned\`
- Latest: \`$latest\`
- Changes: https://github.com/huggingface/doc-builder/compare/$pinned...$latest

To update, set \`DOC_BUILDER_SHA\` in \`.github/workflows/docs.yml\` to the latest commit and check the docs preview on the pull request. This issue closes on its own once the pin matches."
if [ -n "$issue" ]; then
gh issue edit "$issue" -R "$REPO" --body "$body"
else
gh issue create -R "$REPO" --title "$TITLE" --body "$body"
fi
124 changes: 124 additions & 0 deletions .github/workflows/docs_pr_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Docs PR preview

# Publishes the docs built by docs.yml for a pull request to
# <site>/pr-preview/pr-N/ and removes them when the pull request closes.
#
# docs.yml builds pull requests without write access (forks included). This
# workflow runs from main with write access and never runs pull request code: it
# only copies the static files the build uploaded. Previews are served from the
# docs domain, so pull requests from outside contributors are published only
# after a maintainer adds the docs-preview label and re-runs their Docs check.
# The label is removed once used, so each new commit needs a new review.

on:
workflow_run:
workflows: [Docs]
types: [completed]
pull_request_target:
types: [closed]

permissions: {}

# Publishing and removing the preview of the same pull request run one at a time,
# so a preview published while its pull request closes is still removed.
concurrency:
group: >-
${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name || github.event.pull_request.head.repo.full_name }}:${{ github.event.workflow_run.head_branch || github.event.pull_request.head.ref }}
cancel-in-progress: false

jobs:
publish:
if: >-
github.event_name == 'workflow_run' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
actions: read
contents: write
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
ROOT_URL: ${{ vars.DOCS_SITE_URL || 'https://openenv.github.io/OpenEnv' }}
steps:
- name: Find the pull request
id: pr
env:
HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
pr=$(gh api -X GET "repos/$REPO/pulls" -f state=open -f head="$HEAD_OWNER:$HEAD_BRANCH" \
| jq --arg sha "$HEAD_SHA" 'map(select(.head.sha == $sha)) | first // empty')
if [ -z "$pr" ]; then
echo "No open pull request at $HEAD_SHA (closed or pushed again)."
exit 0
fi
echo "number=$(jq -r .number <<<"$pr")" >> "$GITHUB_OUTPUT"
jq -r --arg repo "$REPO" '
(.head.repo.full_name == $repo or (.author_association | IN("OWNER", "MEMBER", "COLLABORATOR"))) as $member
| any(.labels[]; .name == "docs-preview") as $label
| "trusted=\($member or $label)\nlabel_only=\(($member | not) and $label)"
' <<<"$pr" >> "$GITHUB_OUTPUT"

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: steps.pr.outputs.trusted == 'true'

- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
if: steps.pr.outputs.trusted == 'true'
with:
name: docs-site
path: site
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}

- name: Publish the preview
if: steps.pr.outputs.trusted == 'true'
env:
NUMBER: ${{ steps.pr.outputs.number }}
run: docs/pages/publish.sh "pr-preview/pr-$NUMBER" site

# The label approves one commit: later pushes need a maintainer to add it again.
- name: Remove the docs-preview label
if: steps.pr.outputs.label_only == 'true'
env:
NUMBER: ${{ steps.pr.outputs.number }}
run: gh api -X DELETE "repos/$REPO/issues/$NUMBER/labels/docs-preview" >/dev/null

- name: Comment on the pull request
if: steps.pr.outputs.number != ''
env:
NUMBER: ${{ steps.pr.outputs.number }}
TRUSTED: ${{ steps.pr.outputs.trusted }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
marker="<!-- docs-preview -->"
if [ "$TRUSTED" = true ]; then
body="$marker
The docs for this pull request are available at $ROOT_URL/pr-preview/pr-$NUMBER/ (commit ${HEAD_SHA:0:7}). The preview may take a minute to update and is removed when the pull request closes."
else
body="$marker
The docs for this pull request built successfully. A maintainer can publish a preview of this commit by adding the \`docs-preview\` label and re-running the Docs check."
fi
id=$(gh api --paginate "repos/$REPO/issues/$NUMBER/comments" \
--jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1)
if [ -n "$id" ]; then
gh api -X PATCH "repos/$REPO/issues/comments/$id" -f body="$body" >/dev/null
else
gh api "repos/$REPO/issues/$NUMBER/comments" -f body="$body" >/dev/null
fi

remove:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Checks out main, not the pull request.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Remove the preview
env:
NUMBER: ${{ github.event.pull_request.number }}
run: docs/pages/publish.sh "pr-preview/pr-$NUMBER"
Loading