HexCasting/.github/workflows/build_docs.yml

211 lines
4.9 KiB
YAML
Raw Normal View History

2023-08-07 01:27:52 +02:00
name: Build the web book
2022-05-21 17:56:52 +02:00
2022-05-21 18:42:05 +02:00
on:
push:
2023-08-07 01:27:52 +02:00
workflow_dispatch:
2023-08-28 07:41:53 +02:00
inputs:
publish:
2023-08-28 08:46:32 +02:00
description: Package index to publish the docgen to
2023-08-28 08:35:03 +02:00
type: choice
options:
2023-08-28 08:46:32 +02:00
- none
2023-08-28 08:35:03 +02:00
- PyPI
- TestPyPI
2023-08-28 07:41:53 +02:00
segment:
2023-08-28 08:46:32 +02:00
description: Version segment to bump with Hatch
2023-08-28 07:41:53 +02:00
type: string
required: false
2022-05-21 17:56:52 +02:00
2023-08-29 04:33:57 +02:00
env:
HEXDOC: hexdoc doc/properties.toml --ci
2023-08-28 01:21:09 +02:00
permissions:
contents: read
concurrency:
2023-08-28 07:45:38 +02:00
group: "hexdoc"
2023-08-28 01:21:09 +02:00
cancel-in-progress: false
2022-05-21 17:56:52 +02:00
jobs:
2023-08-28 01:06:20 +02:00
build:
2022-05-21 17:56:52 +02:00
runs-on: ubuntu-latest
2023-08-29 04:33:57 +02:00
2023-08-28 07:41:53 +02:00
# only execute on the default branch or when invoked manually
2023-08-28 09:12:13 +02:00
if: |-
github.event_name == 'workflow_dispatch' ||
github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
2023-08-29 04:33:57 +02:00
outputs:
matrix: ${{ steps.list-langs.outputs.matrix }}
2023-08-28 01:06:20 +02:00
2022-05-21 17:56:52 +02:00
steps:
2023-08-28 07:41:53 +02:00
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
2023-08-07 01:27:52 +02:00
2023-08-28 07:41:53 +02:00
- name: Install docgen
run: pip install . hatch
2023-08-28 08:05:42 +02:00
2023-08-29 04:33:57 +02:00
- name: List languages
id: list-langs
run: echo "matrix=$($HEXDOC --list-langs)" >> "$GITHUB_OUTPUT"
- name: Export web book
run: $HEXDOC --export-only
2023-08-07 01:27:52 +02:00
2023-08-28 07:41:53 +02:00
- name: Bump version
2023-08-28 08:05:42 +02:00
if: github.event_name == 'workflow_dispatch' && inputs.segment
2023-08-28 07:41:53 +02:00
run: hatch version ${{ inputs.segment }}
2023-08-28 08:05:42 +02:00
- name: Commit changes
2023-08-28 07:41:53 +02:00
uses: stefanzweifel/git-auto-commit-action@v4
with:
2023-08-28 08:05:42 +02:00
commit_message: Build web book from ${{ github.ref }}
2023-08-28 07:41:53 +02:00
- name: Build docgen
run: hatch build
- name: Upload hexdoc artifact
uses: actions/upload-artifact@v3
with:
name: hexdoc-build
path: dist/
- name: Copy build to Pages
run: |
2023-08-29 04:33:57 +02:00
mkdir -p _site/dist
cp dist/*.whl _site/dist/latest.whl
cp dist/*.tar.gz _site/dist/latest.tar.gz
2023-08-07 01:27:52 +02:00
2023-08-28 07:48:16 +02:00
- name: Fix permissions
run: |
chmod -c -R +rX "out/" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
- name: Upload temporary Pages artifact
uses: actions/upload-artifact@v3
with:
name: github-pages-tmp
path: _site/
2023-08-28 01:06:20 +02:00
2023-08-29 04:33:57 +02:00
generate:
2023-08-28 01:06:20 +02:00
runs-on: ubuntu-latest
2023-08-28 01:21:09 +02:00
needs: build
2023-08-29 04:57:26 +02:00
continue-on-error: true
2023-08-28 01:06:20 +02:00
2023-08-29 04:33:57 +02:00
strategy:
fail-fast: false
matrix:
lang: ${{ fromJson(needs.build.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Download hexdoc artifact
uses: actions/download-artifact@v3
with:
name: hexdoc-build
2023-08-29 04:33:57 +02:00
- name: Install docgen
run: pip install *.whl
2023-08-29 04:33:57 +02:00
- name: Build web book
2023-08-29 04:57:26 +02:00
run: $HEXDOC --lang ${{ matrix.lang }} -o _site
2023-08-29 04:39:12 +02:00
- name: Upload temporary Pages artifact
uses: actions/upload-artifact@v3
with:
name: github-pages-tmp
path: _site/
bundle-pages:
runs-on: ubuntu-latest
needs: generate
steps:
- name: Download temporary Pages artifact
uses: actions/download-artifact@v3
with:
name: github-pages-tmp
path: _site/
2023-08-29 04:33:57 +02:00
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
deploy-pages:
runs-on: ubuntu-latest
needs: bundle-pages
2023-08-29 04:33:57 +02:00
2023-08-28 01:06:20 +02:00
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
2023-08-28 07:45:38 +02:00
permissions:
id-token: write
pages: write
2023-08-28 01:06:20 +02:00
steps:
- name: Deploy to Pages
id: deployment
uses: actions/deploy-pages@v2
2023-08-29 05:03:46 +02:00
with:
timeout: 300000 # 5 minutes
2023-08-28 07:41:53 +02:00
2023-08-28 09:12:13 +02:00
publish-pypi:
2023-08-28 08:35:03 +02:00
runs-on: ubuntu-latest
needs: build
2023-08-28 09:12:13 +02:00
if: |-
github.event_name == 'workflow_dispatch' && inputs.publish == 'PyPI' ||
startsWith(github.ref, 'refs/tags') ||
startsWith(github.event.head_commit.message, '[Release]')
2023-08-28 08:35:03 +02:00
environment:
2023-08-28 09:12:13 +02:00
name: pypi
url: https://pypi.org/p/hexdoc
2023-08-28 08:35:03 +02:00
permissions:
id-token: write
steps:
- name: Download hexdoc artifact
uses: actions/download-artifact@v3
with:
name: hexdoc-build
2023-08-28 08:57:22 +02:00
path: dist
2023-08-28 08:35:03 +02:00
2023-08-28 09:12:13 +02:00
- name: Publish to PyPI
2023-08-28 08:35:03 +02:00
uses: pypa/gh-action-pypi-publish@release/v1
2023-08-28 09:12:13 +02:00
publish-testpypi:
2023-08-28 07:41:53 +02:00
runs-on: ubuntu-latest
needs: build
2023-08-28 09:12:13 +02:00
if: github.event_name == 'workflow_dispatch' && inputs.publish == 'TestPyPI'
2023-08-28 07:41:53 +02:00
environment:
2023-08-28 09:12:13 +02:00
name: testpypi
url: https://test.pypi.org/p/hexdoc
2023-08-28 08:35:03 +02:00
2023-08-28 07:41:53 +02:00
permissions:
id-token: write
steps:
- name: Download hexdoc artifact
uses: actions/download-artifact@v3
with:
name: hexdoc-build
2023-08-28 09:06:31 +02:00
path: dist
2023-08-28 07:41:53 +02:00
2023-08-28 09:12:13 +02:00
- name: Publish to TestPyPI
2023-08-28 07:41:53 +02:00
uses: pypa/gh-action-pypi-publish@release/v1
2023-08-28 09:12:13 +02:00
with:
repository-url: https://test.pypi.org/legacy/