Publish docs to GitHub pages #159
Workflow file for this run
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
# | |
# Copyright (c) 2020, 2022 by Delphix. All rights reserved. | |
# | |
name: Publish docs to GitHub pages | |
on: | |
create: | |
branches: | |
- 'docs/**' | |
push: | |
branches: | |
- 'docs/**' | |
paths: | |
- 'docs/**' | |
- '.github/workflows/publish-docs.yml' | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [ 3.11 ] | |
package: [ docs ] | |
repository: [ 'delphix/virtualization-sdk' ] | |
steps: | |
### | |
# Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. | |
# Set fetch-depth: 0 to fetch all history for all branches and tags. | |
### | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
### | |
# Set CURRENT_BRANCH environment variable to the current branch name. Refrain from using 'set-env' as | |
# GitHub has identified the command as a moderate security vulnerability. | |
### | |
- name: Set the current branch environment variable | |
working-directory: ${{ matrix.package }} | |
run: | | |
CURRENT_BRANCH_VAR=${GITHUB_REF#refs/heads/} | |
echo "Current branch: $CURRENT_BRANCH_VAR" | |
echo "CURRENT_BRANCH=$(echo $CURRENT_BRANCH_VAR)" >> $GITHUB_ENV | |
# Display all remote branches | |
- name: Display all remote branches | |
working-directory: ${{ matrix.package }} | |
run: git branch -r | |
### | |
# Get only docs branches, extract the "docs/x.y.z" part, sort them in descending order, and get the first one. | |
# Set the LATEST_DOCS_BRANCH environment variable. Refrain from using 'set-env' as GitHub has identified the | |
# command as a moderate security vulnerability. | |
### | |
- name: Set the latest docs branch environment variable | |
working-directory: ${{ matrix.package }} | |
run: | | |
LATEST_DOCS_BRANCH_VAR=$(git branch -r | grep -e ".*\/*docs\/[0-9].[0-9].[0-9]" | sed -n "s/.*\/*\(docs\/[0-9].[0-9].[0-9]\).*/\1/p" | sort -r | head -n 1) | |
echo "Latest docs branch: $LATEST_DOCS_BRANCH_VAR" | |
echo "LATEST_DOCS_BRANCH=$(echo $LATEST_DOCS_BRANCH_VAR)" >> $GITHUB_ENV | |
- name: Check that the current branch is the latest docs branch, fail otherwise | |
working-directory: ${{ matrix.package }} | |
run: | | |
if [ $CURRENT_BRANCH != $LATEST_DOCS_BRANCH ]; then | |
echo "The action is running on branch $CURRENT_BRANCH which is not the latest docs branch ($LATEST_DOCS_BRANCH)." | |
exit 1 | |
else | |
echo "The action is running on the latest docs branch." | |
fi | |
- name: Install Pipenv | |
uses: dschep/install-pipenv-action@v1 | |
- name: Install dependencies for building documenation | |
working-directory: ${{ matrix.package }} | |
run: pipenv install | |
- name: Build documentation | |
working-directory: ${{ matrix.package }} | |
run: pipenv run mkdocs build --clean | |
# Docs will be pushed to developer.delphix.com if the repository is delphix/virtualization-sdk. | |
- name: Deploy the contents of docs/site to gh-pages (developer.delphix.com) π | |
if: ${{ github.repository == matrix.repository }} | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
deploy_key: ${{ secrets.SDK_DEPLOY_KEY }} | |
publish_dir: docs/site | |
commit_message: Deploy to gh-pages π | |
user_name: "github-actions[bot]" | |
user_email: "github-actions[bot]@users.noreply.github.com" | |
cname: developer.delphix.com | |
- name: Deploy the contents of docs/site to personal gh-pages π | |
if: ${{ github.repository != matrix.repository }} | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: docs/site | |
commit_message: Deploy to gh-pages π | |
user_name: "github-actions[bot]" | |
user_email: "github-actions[bot]@users.noreply.github.com" |