Generate docs #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate docs | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
type: string | |
required: true | |
description: "Documentation version to generate" | |
source-repo: | |
type: string | |
required: true | |
description: "Repository to build from" | |
source-ref: | |
type: string | |
required: true | |
description: "Git ref of the source repo" | |
output-prefix: | |
type: string | |
required: true | |
description: "Output path prefix" | |
publish-mode: | |
type: choice | |
required: true | |
description: "Publish mode" | |
options: | |
- "none" | |
- "auto-merge" | |
- "pull-request" | |
default: "pull-request" | |
jobs: | |
generate-docs: | |
name: Generate docs | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.BOT_GITHUB_TOKEN }} | |
- name: Checkout ${{ github.event.inputs.source-repo }} | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.inputs.source-repo }} | |
ref: ${{ github.event.inputs.source-ref }} | |
path: source | |
fetch-depth: 0 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
architecture: x64 | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install -r source/requirements.txt | |
- name: Configure Git | |
run: | | |
git config user.name "afakebot" | |
git config user.email "[email protected]" | |
- name: Get latest tag | |
id: get-latest-tag | |
uses: ./.github/actions/latest-stable-tag | |
with: | |
repo-path: source | |
- name: Get source commit | |
id: get-source-commit | |
working-directory: source | |
run: | | |
echo "sha1=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Generate the docs | |
id: generate-docs | |
env: | |
SNIPPETS_REPO_ROOT: source | |
run: | | |
version=${{ github.event.inputs.version }} | |
aliasClause= | |
versionForMessage=$version | |
if [ "$version" = "${{ steps.get-latest-tag.outputs.latest-tag }}" ]; then | |
aliasClause="stable --update-aliases" | |
versionForMessage="$versionForMessage, stable" | |
fi | |
message="Generate docs from ${{ github.event.inputs.source-repo }}@${{ steps.get-source-commit.outputs.sha1 }} ($versionForMessage)" | |
targetBranch=update-$version-docs | |
echo "docs-branch=$targetBranch" >> $GITHUB_OUTPUT | |
git branch $targetBranch | |
mike deploy "$version" $aliasClause \ | |
--branch "$targetBranch" \ | |
--prefix "${{ github.event.inputs.output-prefix }}" \ | |
--config-file source/mkdocs.yml \ | |
--message "$message" | |
- name: Create pull request | |
if: github.event.inputs.publish-mode == 'pull-request' | |
env: | |
GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} | |
run: | | |
docsBranch="${{ steps.generate-docs.outputs.docs-branch }}" | |
git push origin "$docsBranch:$docsBranch" | |
gh pr create --base master --head "$docsBranch" --fill | |
- name: Merge changes | |
if: github.event.inputs.publish-mode == 'auto-merge' | |
run: | | |
git merge "${{ steps.generate-docs.outputs.docs-branch }}" | |
git push |