243 lines
No EOL
6.3 KiB
YAML
243 lines
No EOL
6.3 KiB
YAML
name: Build the web book
|
|
|
|
on:
|
|
push:
|
|
workflow_dispatch:
|
|
inputs:
|
|
publish:
|
|
description: Package index to publish the docgen to
|
|
type: choice
|
|
options:
|
|
- none
|
|
- PyPI (release)
|
|
- TestPyPI
|
|
segment:
|
|
description: Version segment to bump with Hatch
|
|
type: string
|
|
required: false
|
|
|
|
env:
|
|
PYPI_PACKAGE: hexdoc
|
|
HEXDOC: hexdoc 0.10.3/doc/properties.toml --ci
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: "docgen"
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
# only execute on the default branch or when invoked manually
|
|
if: |-
|
|
github.event_name == 'workflow_dispatch' ||
|
|
github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
permissions:
|
|
pages: read
|
|
|
|
outputs:
|
|
pages-url: ${{ steps.get-url.outputs.pages-url }}
|
|
matrix: ${{ steps.list-langs.outputs.matrix }}
|
|
release: ${{ steps.check-release.outputs.release }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-python@v4
|
|
with:
|
|
python-version: "3.11"
|
|
cache: pip
|
|
|
|
- name: Install docgen from source
|
|
run: pip install . hatch
|
|
|
|
- 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: List book languages
|
|
id: list-langs
|
|
run: echo "matrix=$($HEXDOC --list-langs)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Check if this is a release
|
|
id: check-release
|
|
run: |
|
|
release=${{ github.event_name == 'workflow_dispatch' && inputs.publish == 'PyPI (release)' || startsWith(github.ref, 'refs/tags') || startsWith(github.event.head_commit.message, '[Release]') }}
|
|
echo "release=$release" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Export web book
|
|
run: $HEXDOC --export-only --is-release ${{ steps.check-release.outputs.release }}
|
|
|
|
- name: Bump version
|
|
if: github.event_name == 'workflow_dispatch' && inputs.segment
|
|
run: hatch version "${{ inputs.segment }}"
|
|
|
|
- name: Commit changes
|
|
uses: stefanzweifel/git-auto-commit-action@v4
|
|
with:
|
|
commit_message: Build web book from ${{ github.ref }}
|
|
|
|
- name: Build docgen
|
|
run: hatch build
|
|
|
|
- name: Upload docgen artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: docgen-build
|
|
path: dist
|
|
|
|
- name: Copy build to Pages
|
|
run: |
|
|
mkdir -p _site/dist
|
|
cp dist/*.whl _site/dist/latest.whl
|
|
cp dist/*.tar.gz _site/dist/latest.tar.gz
|
|
|
|
- name: Upload temporary Pages artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: github-pages-tmp
|
|
path: _site
|
|
|
|
generate:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
continue-on-error: true
|
|
|
|
env:
|
|
GITHUB_PAGES_URL: ${{ needs.build.outputs.pages-url }}
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
lang: ${{ fromJson(needs.build.outputs.matrix) }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: ./.github/actions/install-artifact-wheel
|
|
with:
|
|
name: docgen-build
|
|
python-version: "3.11"
|
|
|
|
- name: Build web book
|
|
run: $HEXDOC --lang "${{ matrix.lang }}" -o _site --clean --is-release "${{ needs.build.outputs.release }}"
|
|
|
|
- name: Build web book with missing translations
|
|
if: failure()
|
|
run: $HEXDOC --lang "${{ matrix.lang }}" -o _site --clean --is-release "${{ needs.build.outputs.release }}" --allow-missing
|
|
|
|
- name: Upload temporary Pages artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: github-pages-tmp
|
|
path: _site
|
|
|
|
bundle-pages:
|
|
runs-on: ubuntu-latest
|
|
needs: [build, generate]
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: ./.github/actions/install-artifact-wheel
|
|
with:
|
|
name: docgen-build
|
|
python-version: "3.11"
|
|
|
|
- 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 --src _site/src/docs --dst _site/dst/docs --is-release "${{ needs.build.outputs.release == true }}"
|
|
|
|
- name: Upload Pages artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: github-pages
|
|
path: _site/dst/docs
|
|
|
|
deploy-pages:
|
|
runs-on: ubuntu-latest
|
|
needs: bundle-pages
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Download Pages artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: github-pages
|
|
path: _site
|
|
|
|
- name: Deploy to Pages
|
|
uses: JamesIves/github-pages-deploy-action@v4
|
|
with:
|
|
folder: _site
|
|
target-folder: docs
|
|
|
|
publish-pypi:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
if: needs.build.outputs.release == 'true'
|
|
|
|
environment:
|
|
name: pypi
|
|
url: https://pypi.org/p/${{ env.PYPI_PACKAGE }}
|
|
|
|
permissions:
|
|
id-token: write
|
|
|
|
steps:
|
|
- name: Download docgen artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: docgen-build
|
|
path: dist
|
|
|
|
- name: Publish to PyPI
|
|
uses: pypa/gh-action-pypi-publish@release/v1
|
|
|
|
publish-testpypi:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
if: github.event_name == 'workflow_dispatch' && inputs.publish == 'TestPyPI'
|
|
|
|
environment:
|
|
name: testpypi
|
|
url: https://test.pypi.org/p/${{ env.PYPI_PACKAGE }}
|
|
|
|
permissions:
|
|
id-token: write
|
|
|
|
steps:
|
|
- name: Download docgen artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: docgen-build
|
|
path: dist
|
|
|
|
- name: Publish to TestPyPI
|
|
uses: pypa/gh-action-pypi-publish@release/v1
|
|
with:
|
|
repository-url: https://test.pypi.org/legacy/
|
|
|