248 lines
7.4 KiB
YAML
248 lines
7.4 KiB
YAML
name: "[Reusable] Build and publish a hexdoc project"
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
python-version:
|
|
description: Python version to install
|
|
type: string
|
|
required: true
|
|
checkout:
|
|
description: Whether to check out the branch specified in `branch`
|
|
type: boolean
|
|
required: true
|
|
branch:
|
|
description: Branch to generate docs from
|
|
type: string
|
|
required: false
|
|
publish-latest-and-root:
|
|
description: Overwrite `/v/latest` (and `/`, if releasing)
|
|
type: boolean
|
|
required: true
|
|
publish-release:
|
|
description: Overwrite `/v/<current_version>`
|
|
type: boolean
|
|
required: true
|
|
bump-version-segment:
|
|
description: Version segment to bump with Hatch
|
|
type: string
|
|
required: false
|
|
outputs:
|
|
publish-release:
|
|
description: Value of publish-release input for convenience.
|
|
value: ${{ jobs.build.outputs.release }}
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
permissions:
|
|
contents: write
|
|
pages: read
|
|
|
|
outputs:
|
|
pages-url: ${{ steps.get-url.outputs.pages-url }}
|
|
matrix: ${{ steps.list-langs.outputs.matrix }}
|
|
release: ${{ steps.parse-inputs.outputs.release }}
|
|
branch: ${{ steps.parse-inputs.outputs.branch }}
|
|
hexdoc-common: ${{ steps.parse-inputs.outputs.hexdoc-common }}
|
|
hexdoc-props: ${{ steps.parse-inputs.outputs.hexdoc }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-python@v4
|
|
with:
|
|
python-version: ${{ inputs.python-version }}
|
|
cache: pip
|
|
|
|
- name: Get Pages url
|
|
id: get-url
|
|
run: |
|
|
url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url')
|
|
echo "pages-url=$url" >> "$GITHUB_OUTPUT"
|
|
echo "GITHUB_PAGES_URL=$url" >> "$GITHUB_ENV"
|
|
|
|
- name: Parse inputs
|
|
id: parse-inputs
|
|
run: |
|
|
release=${{ inputs.publish-release }}
|
|
update_latest=${{ inputs.publish-latest-and-root }}
|
|
|
|
if [[ ${{ inputs.checkout }} == true ]]; then
|
|
branch='${{ inputs.branch }}'
|
|
props=_checkout/doc/properties.toml
|
|
echo "HATCH_GRADLE_DIR=_checkout" >> "$GITHUB_ENV"
|
|
else
|
|
branch=none
|
|
props=doc/properties.toml
|
|
fi
|
|
|
|
if [[ $release == true ]]; then
|
|
release_flag="--release"
|
|
else
|
|
release_flag="--no-release"
|
|
fi
|
|
|
|
if [[ $update_latest == true ]]; then
|
|
update_latest_flag="--update-latest"
|
|
else
|
|
update_latest_flag="--no-update-latest"
|
|
fi
|
|
|
|
hexdoc_common="$release_flag $update_latest_flag"
|
|
|
|
echo "HEXDOC_COMMON=$props" >> "$GITHUB_ENV"
|
|
echo "HEXDOC_PROPS=$hexdoc_common" >> "$GITHUB_ENV"
|
|
|
|
echo "release=$release" >> "$GITHUB_OUTPUT"
|
|
echo "update-latest=$update_latest" >> "$GITHUB_OUTPUT"
|
|
echo "branch=$branch" >> "$GITHUB_OUTPUT"
|
|
echo "hexdoc-common=$hexdoc_common" >> "$GITHUB_OUTPUT"
|
|
echo "hexdoc-props=$props" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Checkout input branch
|
|
if: steps.parse-inputs.outputs.branch != 'none'
|
|
id: checkout-input
|
|
uses: actions/checkout@v3
|
|
with:
|
|
ref: ${{ steps.parse-inputs.outputs.branch }}
|
|
path: _checkout
|
|
|
|
- name: Install docgen from source
|
|
run: pip install . hatch
|
|
|
|
- name: List book languages
|
|
id: list-langs
|
|
run: |
|
|
echo "matrix=$(hexdoc list-langs $HEXDOC_PROPS $HEXDOC_COMMON)" >> "$GITHUB_OUTPUT"
|
|
if [[ $RUNNER_DEBUG ]]; then
|
|
tree -I '__pycache__|Common|Fabric|Forge|venv'
|
|
fi
|
|
|
|
- name: Export web book
|
|
run: hexdoc export $HEXDOC_PROPS $HEXDOC_COMMON
|
|
|
|
- name: Bump version
|
|
if: inputs.bump-version-segment
|
|
run: hatch version "${{ inputs.bump-version-segment }}"
|
|
|
|
- name: Commit changes
|
|
uses: stefanzweifel/git-auto-commit-action@v4
|
|
with:
|
|
commit_message: Build web book from ${{ github.ref }}
|
|
|
|
- name: Build package
|
|
run: hatch build
|
|
|
|
- name: Upload package artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: hexdoc-build
|
|
path: dist
|
|
|
|
- name: Copy build to Pages
|
|
if: steps.parse-inputs.outputs.update-latest
|
|
run: |
|
|
mkdir -p _site/v/latest/dist
|
|
cp -r dist _site/v/latest/dist
|
|
|
|
- name: Upload temporary Pages artifact
|
|
if: steps.parse-inputs.outputs.update-latest
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: github-pages-tmp
|
|
path: _site
|
|
|
|
- name: Add job summary
|
|
run: echo "Built version \`$(hatch version)\` from commit \`$(git rev-parse --short "$GITHUB_SHA")\`." >> $GITHUB_STEP_SUMMARY
|
|
|
|
generate:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
continue-on-error: true
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
lang: ${{ fromJson(needs.build.outputs.matrix) }}
|
|
|
|
env:
|
|
GITHUB_PAGES_URL: ${{ needs.build.outputs.pages-url }}
|
|
HEXDOC: hexdoc render ${{ needs.build.outputs.hexdoc-props }} _site ${{ needs.build.outputs.hexdoc-common }} --lang ${{ matrix.lang }} --clean
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: object-Object/HexMod/.github/actions/install-artifact-wheel@hexdoc-v1
|
|
with:
|
|
name: hexdoc-build
|
|
python-version: ${{ inputs.python-version }}
|
|
|
|
- name: Checkout input branch
|
|
if: needs.build.outputs.branch != 'none'
|
|
uses: actions/checkout@v3
|
|
with:
|
|
ref: ${{ needs.build.outputs.branch }}
|
|
path: _checkout
|
|
|
|
- name: Generate web book
|
|
id: gen-normal
|
|
continue-on-error: true
|
|
run: $HEXDOC
|
|
|
|
- name: Generate web book with missing translations
|
|
if: steps.gen-normal.outcome == 'failure'
|
|
run: $HEXDOC --allow-missing
|
|
|
|
- name: Upload temporary Pages artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: github-pages-tmp
|
|
path: _site
|
|
|
|
- name: Fail if the first generate step failed
|
|
if: steps.gen-normal.outcome == 'failure'
|
|
run: |
|
|
echo "::error::Missing some i18n keys."
|
|
exit 1
|
|
|
|
deploy-pages:
|
|
runs-on: ubuntu-latest
|
|
needs: [build, generate]
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: object-Object/HexMod/.github/actions/install-artifact-wheel@hexdoc-v1
|
|
with:
|
|
name: hexdoc-build
|
|
python-version: ${{ inputs.python-version }}
|
|
|
|
- name: Checkout current Pages
|
|
uses: actions/checkout@v3
|
|
continue-on-error: true
|
|
with:
|
|
ref: gh-pages
|
|
path: _site/dst
|
|
|
|
- name: Download temporary Pages artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: github-pages-tmp
|
|
path: _site/src/docs
|
|
|
|
- name: Add new docs to site
|
|
run: hexdoc merge ${{ needs.build.outputs.hexdoc-common }} --src _site/src/docs --dst _site/dst/docs
|
|
|
|
- name: Deploy to Pages
|
|
uses: JamesIves/github-pages-deploy-action@v4
|
|
with:
|
|
folder: _site/dst/docs
|
|
target-folder: docs
|