Skip to content

Commit

Permalink
Add doc site
Browse files Browse the repository at this point in the history
  • Loading branch information
Jash Parekh committed Apr 17, 2021
1 parent c99c8d4 commit c5602f5
Show file tree
Hide file tree
Showing 41 changed files with 1,508 additions and 609 deletions.
8 changes: 8 additions & 0 deletions .github/actions/build-dist/action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set -euo pipefail

echo "Ensuring pip is up to date"
python -m pip install --upgrade pip
echo "Installing the latest version of pypa/build"
pip install build

python -m build --sdist --wheel --outdir dist/ .
8 changes: 8 additions & 0 deletions .github/actions/build-dist/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: "Build Python package"
description: "Build a wheel and sdist for the package"
runs:
using: "composite"
steps:
- name: "Build wheel"
run: "$GITHUB_ACTION_PATH/action.sh"
shell: "bash"
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python -m pip install --upgrade pip

if [[ "${INSTALL_REQUIREMENTS}" == "true" ]]; then
echo "Installing code requirements"
pip install -r requirements.txt
pip install -r requirements.lock
fi

if [[ "${INSTALL_TEST_REQUIREMENTS}" == "true" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Install Dependencies"
description: "Install Python dependencies"
inputs:
requirements:
description: "Should requirements.txt be installed"
description: "Should requirements.lock be installed"
default: "false"
required: false
test-requirements:
Expand Down
30 changes: 30 additions & 0 deletions .github/actions/publish-docs-with-mike/action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -eo pipefail

echo "::group::Configure Git User"
"${GITHUB_ACTION_PATH}/configure_git_user.sh"
echo "::endgroup::"

echo "::group::Pull down latest docs commit"
git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin gh-pages
echo "::endgroup::"

echo "::group::Publish documentation"
if [[ "${NEW_VERSION}" == "false" ]]; then
if [[ "${VERSION_NAME}" == "" ]]; then
echo "::error::'version_name' must be specified when 'NEW_VERSION' is false."
exit 1
fi
echo "mike deploy \"${VERSION_NAME}\""
mike deploy "${VERSION_NAME}"
elif [[ "${GITHUB_EVENT_NAME:-}" != "release" ]]; then
echo "::error::new_version can only be used for release events."
exit 1
else
# drop leading "v" from tag name to have just the version number
"${GITHUB_ACTION_PATH}/update_docs_for_version.sh" "${RELEASE_TAG:1}"
fi
echo "git push origin gh-pages"
git push origin gh-pages
echo "::endgroup::"
37 changes: 37 additions & 0 deletions .github/actions/publish-docs-with-mike/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "Publish Docs with Mike"
description: |
Publish versioned documentation with Mike.
Requires a python environment to already be setup with mike and any other documentation dependencies installed.
inputs:
version_name:
description: |
Name a version to publish.
Required when new_version is false.
required: false
default: ""
new_version:
description: |
If true, publish a new docs version. If an existing version uses the alias/tile "latest",
update the records so that the new version becomes the latest version.
If version_name is given, that value will be used. Otherwise the release tag will be used.
required: false
default: "false"
commit_user_name:
description: "User name to use for commits. When omitted, the event values will be inspected to derive the name."
default: ""
required: false
commit_user_email:
description: "User email to use for commits. When omitted, the event values will be inspected to derive the email."
default: ""
required: false
runs:
using: "composite"
steps:
- run: "$GITHUB_ACTION_PATH/action.sh"
shell: "bash"
env:
USER_NAME: ${{ inputs.name }}
USER_EMAIL: ${{ inputs.email }}
VERSION_NAME: ${{ inputs.version_name }}
NEW_VERSION: ${{ inputs.new_version }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
45 changes: 45 additions & 0 deletions .github/actions/publish-docs-with-mike/configure_git_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -euo pipefail

NO_REPLY_SUFFIX="@users.noreply.github.com"

function set_and_exit() {
local name="${USER_NAME:-$1}"
local email="${USER_EMAIL:-$2}"
git config --local user.name "${name}"
git config --local user.email "${email}"
exit 0
}

function json_query() {
jq -e "${1}" "${GITHUB_EVENT_PATH}"
}

if [[ "${USER_NAME}" != "" && "${USER_EMAIL}" != "" ]]; then
set_and_exit
fi

echo "::debug::Attempting push event pusher"
if json_query ".push.pusher" > /dev/null ; then
echo "::debug::Found push event pusher"
set_and_exit "$(json_query '.push.pusher.name')" "$(json_query '.push.pusher.email')"
fi

echo "::debug::Attempting merge merged by"
if json_query ".pull_request.merged_by" > /dev/null ; then
echo "::debug::Found pull request event merged by"
LOGIN="$(json_query '.pull_request.merged_by.login')"
set_and_exit "${LOGIN}" "${LOGIN}${NO_REPLY_SUFFIX}"
fi

echo "::debug::Attempting event sender"
if json_query ".sender" > /dev/null ; then
echo "::debug::Found pull event sender"
LOGIN="$(json_query '.sender.login')"
set_and_exit "${LOGIN}" "${LOGIN}${NO_REPLY_SUFFIX}"
fi

echo "::debug::Falling back to GITHUB_ACTOR"
LOGIN="${GITHUB_ACTOR:-github_action}"
set_and_exit "${LOGIN}" "${LOGIN}${NO_REPLY_SUFFIX}"
15 changes: 15 additions & 0 deletions .github/actions/publish-docs-with-mike/update_docs_for_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -eo pipefail

NEW_VERSION="${1}"
PREV_LATEST="$(mike list --json | jq --raw-output '.[] | select(.aliases == ["latest"]) | .version')"

if [[ "${PREV_LATEST}" == "" ]]; then
echo "No previous version found using the latest alias. Nothing to retitle."
else
echo "mike retitle --message \"Remove latest from title of ${PREV_LATEST}\" \"${PREV_LATEST}\" \"${PREV_LATEST}\""
mike retitle --message "Remove latest from title of ${PREV_LATEST}" "${PREV_LATEST}" "${PREV_LATEST}"
fi
echo "mike deploy --update-aliases --title \"${NEW_VERSION} (latest)\" \"${NEW_VERSION}\" \"latest\""
mike deploy --update-aliases --title "${NEW_VERSION} (latest)" "${NEW_VERSION}" "latest"
19 changes: 19 additions & 0 deletions .github/actions/verify-wheel/action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -euo pipefail

MODULE_NAME=$1
WHEEL_LOCATION=$2

echo "Ensuring pip is up to date"
python -m pip install --upgrade pip

APP_DIR=$(pwd)

# move into root dir so Python will import the installed package instead of the local source files
cd /
echo "------------------"
echo "Installing package"
pip install ${APP_DIR}/${WHEEL_LOCATION}/*.whl

echo "-----------------------------"
echo "Attempting to import package"
python "${GITHUB_ACTION_PATH}/test_module_import.py" "${MODULE_NAME}"
16 changes: 16 additions & 0 deletions .github/actions/verify-wheel/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Verify Python Wheel"
description: "Verify importing the package doesn't cause an error"
inputs:
package-import-name:
description: "Name used to import the package from python code"
required: true
packages-dir:
description: The target directory for distribution
required: false
default: dist
runs:
using: "composite"
steps:
- name: "Verify wheel"
run: "$GITHUB_ACTION_PATH/action.sh ${{ inputs.package-import-name }} ${{ inputs.packages-dir }}"
shell: "bash"
15 changes: 15 additions & 0 deletions .github/actions/verify-wheel/test_module_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import importlib
import sys

try:
module_name = sys.argv[1]
except IndexError:
print("module_name must be provided as first argument to test_module_import.py script")
sys.exit(1)

try:
module = importlib.import_module(module_name)
except Exception as e:
print(f"Error importing module {module_name}: {e}")
sys.exit(1)
print(f"Imported {module_name} version {module.__version__}")
68 changes: 68 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,71 @@ jobs:

- name: Run test
run: python -m unittest tests.FakeClientTestCase tests.ClientPublicTestCase

verify-wheel:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
steps:
- name: Check out code
uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Build wheel
uses: ./.github/actions/build-dist
- name: Verify wheel
uses: ./.github/actions/verify-wheel
with:
package-import-name: "instagrapi"

build-docs:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Check out code
uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
requirements: "true"
test-requirements: "true"

- name: Build Docs
run: mkdocs build --strict

# upload artifact for dev build
- name: Upload coverage results artifact
if: github.ref != 'refs/heads/main'
uses: actions/upload-artifact@v2
with:
name: docs-site
path: site/

update-dev-docs:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Check out code
uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
uses: ./.github/actions/install-dependencies
with:
requirements: "true"
test-requirements: "true"

- name: Push documentaiton changes
uses: ./.github/actions/publish-docs-with-mike
with:
version_name: dev
Loading

0 comments on commit c5602f5

Please sign in to comment.