Skip to content

Commit

Permalink
Automate versioned documentation (#951)
Browse files Browse the repository at this point in the history
# Automate versioned documentation

Use `mike` for versioned documentation.
Reuse the tested setup from the OPTIMADE Gateway,

## New CD workflow for updating `master` docs.

This will deploy and update the `latest` version (alias `master`)
whenever a push event to `master` happens.
It will not update the CHANGELOG or other things. Indeed, it will fail
if the API Reference in the documentation has not been properly updated.

The "regular" CD workflow has been updated with versioned documentation
deployment, as well as a new feature:

The release description on GitHub will be updated with the changelog for
that particular version.
This changelog will be *appended* to the existing description.
One should now make sure to have a proper 1st level markdown header in
the description, since the appended changelog will introduce a similar
level header: `# Changelog`.

## Add a bunch of new pre-commit hooks and run them

Add pre-commit hook for creating API Ref. doc.

Added also:
- check-symlinks
- destroyed-symlinks
- requirements-txt-fixer

And changed settings for `trailing-whitespace` to utilize the
`markdown-linebreak-ext` option instead of excluding README.md.
This is better, since it will now find and correct single trailing white
space, but not double (which is part of markdown syntax).

To learn more about what the hooks do see:
https://github.com/pre-commit/pre-commit-hooks#readme

Update pre-commit hook `black`.

## Include untracked files in API Ref. when deploying.

Untracked files might be new files under the API Reference folder that
reflect new modules.

## Other updates

Move around and rename files under `.github`.

Update to vMAJOR for all GH Action tags.
Checking that they actually point to the latest full version number.

Only use target for `git status --porcelain`.
  • Loading branch information
CasperWA committed Oct 18, 2021
1 parent bb1baa8 commit 4a86bab
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 112 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
set -e

echo -e "\n-o- Setting commit user -o-"
git config --local user.email "dev@optimade.org"
git config --local user.name "OPTIMADE Developers"
git config --global user.email "dev@optimade.org"
git config --global user.name "OPTIMADE Developers"

echo -e "\n-o- Update 'API Reference' docs -o-"
invoke create-api-reference-docs --pre-clean

echo -e "\n-o- Commit update - API Reference -o-"
git add docs/api_reference
if [ -n "$(git status --porcelain --untracked-files=no --ignored=no docs/api_reference)" ]; then
if [ -n "$(git status --porcelain docs/api_reference)" ]; then
# Only commit if there's something to commit (git will return non-zero otherwise)
git commit -m "Release ${GITHUB_REF#refs/tags/} - API Reference"
fi
Expand All @@ -25,6 +25,6 @@ git add CHANGELOG.md
git commit -m "Release ${GITHUB_REF#refs/tags/} - Changelog"

echo -e "\n-o- Update version tag -o-"
TAG_MSG=.github/workflows/release_tag_msg.txt
TAG_MSG=.github/utils/release_tag_msg.txt
sed -i "s|TAG_NAME|${GITHUB_REF#refs/tags/}|" "${TAG_MSG}"
git tag -af -F "${TAG_MSG}" ${GITHUB_REF#refs/tags/}
File renamed without changes.
67 changes: 67 additions & 0 deletions .github/workflows/cd_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CD Documentation

on:
push:
branches:
- master

jobs:
deploy:
name: Deploy `latest` documentation
if: github.repository_owner == 'Materials-Consortia'
runs-on: ubuntu-latest

steps:
- name: Release check
run: |
COMMIT_MSG="$(gh api /repos/${{ github.repository}}/commits/main --jq '.commit.message')"
if [[ "${COMMIT_MSG}" =~ ^Release\ v.*\ -\ Changelog$ ]]; then
echo "In a release - do not run this job !"
echo "RELEASE_RUN=true" >> $GITHUB_ENV
else
echo "Not a release - update docs"
echo "RELEASE_RUN=false" >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout repository
if: env.RELEASE_RUN == 'false'
uses: actions/checkout@v2
with:
fetch-depth: 0
submodule: true

- name: Set up Python 3.8
if: env.RELEASE_RUN == 'false'
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
if: env.RELEASE_RUN == 'false'
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install -U -e .[all]
- name: Set up git user
if: env.RELEASE_RUN == 'false'
run: |
git config --global user.name "OPTIMADE Developers"
git config --global user.email "dev@optimade.org"
- name: Check API Reference and landing page
if: env.RELEASE_RUN == 'false'
run: |
invoke create-api-reference-docs --pre-clean
if [ -n "$(git status --porcelain docs/api_reference)" ]; then
echo "The following files in the documentation have not been committed:"
git status --porcelain docs/api_reference
exit 1
fi
- name: Deploy documentation
if: env.RELEASE_RUN == 'false'
run: mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest master
85 changes: 85 additions & 0 deletions .github/workflows/cd_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Publish and Deploy

on:
release:
types:
- published

jobs:

publish:
name: Publish OPTIMADE Python tools
runs-on: ubuntu-latest
if: github.repository == 'Materials-Consortia/optimade-python-tools' && startsWith(github.ref, 'refs/tags/v')
env:
PUBLISH_UPDATE_BRANCH: master

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install Python dependencies
run: |
python -m pip install -U pip
pip install -U setuptools
pip install -U -e .[all]
- name: Update changelog
uses: CharMixer/auto-changelog-action@v1
with:
token: ${{ secrets.RELEASE_PAT_CASPER }}
release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }}

- name: Update API Reference docs and version - Commit changes and update tag
run: .github/utils/update_docs.sh

- name: Update '${{ env.PUBLISH_UPDATE_BRANCH }}'
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.RELEASE_PAT_CASPER }}
branch: ${{ env.PUBLISH_UPDATE_BRANCH }}
unprotect_reviews: true
sleep: 15
force: true
tags: true

- name: Get tagged versions
run: echo "PREVIOUS_VERSION=$(git tag -l --sort -version:refname | sed -n 2p)" >> $GITHUB_ENV

- name: Create release-specific changelog
uses: CharMixer/auto-changelog-action@v1
with:
token: ${{ secrets.RELEASE_PAT_CASPER }}
release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }}
since_tag: "${{ env.PREVIOUS_VERSION }}"
output: "release_changelog.md"

- name: Append changelog to release body
run: |
gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} --jq '.body' > release_body.md
cat release_changelog.md >> release_body.md
gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} -X PATCH -F body='@release_body.md'
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT_CASPER }}

- name: Build source distribution
run: python ./setup.py sdist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}

- name: Deploy documentation
run: |
mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml ${GITHUB_REF#refs/tags/v} stable
mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest master
42 changes: 22 additions & 20 deletions .github/workflows/deps_lint.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.8

Expand All @@ -37,12 +37,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2
with:
submodules: true

- name: Set up Python 3.8
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.8

Expand All @@ -62,12 +62,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2
with:
submodules: true

- name: Set up Python 3.8
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.8

Expand All @@ -91,7 +91,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2
with:
submodules: true

Expand All @@ -101,11 +101,11 @@ jobs:
- name: Start Docker image - server
run: |
docker-compose up optimade &
.github/workflows/wait_for_it.sh localhost:3213 -t 120
.github/utils/wait_for_it.sh localhost:3213 -t 120
sleep 15
- name: Test server, including OPTIONAL base URLs
uses: Materials-Consortia/optimade-validator-action@v2.6.0
uses: Materials-Consortia/optimade-validator-action@v2
with:
port: 3213
path: /
Expand All @@ -115,11 +115,11 @@ jobs:
- name: Start Docker image - index server
run: |
docker-compose up optimade-index &
.github/workflows/wait_for_it.sh localhost:3214 -t 120
.github/utils/wait_for_it.sh localhost:3214 -t 120
sleep 15
- name: Test index server, including OPTIONAL base URLs
uses: Materials-Consortia/optimade-validator-action@v2.6.0
uses: Materials-Consortia/optimade-validator-action@v2
with:
port: 3214
path: /
Expand Down Expand Up @@ -166,13 +166,13 @@ jobs:


steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -236,15 +236,15 @@ jobs:

- name: Upload coverage to Codecov
if: matrix.python-version == 3.8 && github.repository == 'Materials-Consortia/optimade-python-tools'
uses: codecov/codecov-action@v2.1.0
uses: codecov/codecov-action@v2
with:
name: project
file: ./coverage.xml
flags: project

- name: Upload validator coverage to Codecov
if: matrix.python-version == 3.8 && github.repository == 'Materials-Consortia/optimade-python-tools'
uses: codecov/codecov-action@v2.1.0
uses: codecov/codecov-action@v2
with:
name: validator
file: ./validator_cov.xml
Expand All @@ -254,11 +254,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v2
with:
submodules: true

- uses: actions/setup-python@v2.2.2
- uses: actions/setup-python@v2
with:
python-version: 3.8

Expand All @@ -271,20 +271,22 @@ jobs:
pip install -r requirements-dev.txt
pip install -r requirements-docs.txt
# NOTE: While we're now using `mike`, this is still useful
# to test the integrity of the documentation build.
- name: Build
run: |
invoke create-api-reference-docs
invoke create-api-reference-docs --pre-clean
mkdocs build --strict
test_build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v2
with:
python-version: 3.8

Expand Down

0 comments on commit 4a86bab

Please sign in to comment.