-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-build docs and auto-update version merge
- Loading branch information
Showing
10 changed files
with
219 additions
and
67 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Update package version | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
permissions: | ||
contents: write | ||
jobs: | ||
update_version: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Run _version.py | ||
run: python lair/_version.py | ||
|
||
- name: Commit changes | ||
run: | | ||
git config --local user.name "GitHub Actions" | ||
git config --local user.email "[email protected]" | ||
git add lair/__init__.py | ||
git commit -m "auto-update package version" | ||
git push |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
0 0 * * * ~/lair/docs/dev-docs.sh | ||
0 0 * * * ~/.lair-docs/docs/latest-docs.sh | ||
0 0 * * * ~/software/python/miniconda3/envs/lair-dev/bin/python ~/.lair-docs/docs/make_docs.py --version dev latest |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
""" | ||
Build the documentation for the project. | ||
""" | ||
|
||
import argparse | ||
import os | ||
from pathlib import Path | ||
import subprocess | ||
import requests | ||
|
||
# Load the git module on CHPC | ||
subprocess.run('module load git', shell=True) | ||
|
||
# Parse args | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
'--version', | ||
nargs='*', # Accepts zero or more arguments | ||
default='all', # Default to 'all' if no version is specified | ||
help='The version of the documentation to build. Specify one or more versions, or "all" for all versions. Default: all', | ||
type=str | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
def sphinx_build(version: str, source: str | Path, build: str | Path): | ||
""" | ||
Build the documentation for a specific version of the project. | ||
Parameters | ||
---------- | ||
version : str | ||
The version of the project to build the documentation for. | ||
source : str | ||
The path to the source documentation. | ||
build : str | ||
The path to the built documentation. | ||
latest : str, optional | ||
The path to the latest documentation. Default: None | ||
""" | ||
|
||
# Set the version in the environment | ||
os.environ['LAIR_DOCS_VERSION'] = version | ||
|
||
# Build the docs | ||
os.system(f'sphinx-build {source} {build}') | ||
|
||
|
||
def checkout_version(version: str): | ||
""" | ||
Checkout the specified version of the project. | ||
Parameters | ||
---------- | ||
version : str | ||
The version of the project to checkout. | ||
""" | ||
target = 'main' if version == 'latest' else f'v{version}' | ||
try: | ||
subprocess.run(['git', 'checkout', target], check=True) | ||
print(f"Checked out {target} successfully.") | ||
except subprocess.CalledProcessError as e: | ||
print(f"An error occurred while checking out {target}: {e}") | ||
|
||
|
||
host = Path('~/public_html/lair').expanduser() | ||
dev = Path('~/lair/docs').expanduser() | ||
docs = Path('~/.lair-docs/docs').expanduser() | ||
source = docs / 'source' | ||
|
||
# Get list of versions from switcher | ||
switcher_url = 'https://raw.githubusercontent.com/jmineau/lair/main/docs/versions.json' | ||
switcher = requests.get(switcher_url).json() | ||
|
||
# Determine which versions to build | ||
to_build: list = args.version | ||
if to_build == 'all': | ||
to_build = [v['version'] for v in switcher] | ||
|
||
print('to_build:', to_build) | ||
|
||
# Change to the docs directory | ||
os.chdir(docs) | ||
|
||
# Pull the latest changes from the git repository | ||
subprocess.run(['git', 'pull'], check=True) | ||
|
||
# Iterate over the versions in the switcher | ||
for v in switcher: | ||
version = v['version'] | ||
name = v.get('name', '') | ||
|
||
if version == 'dev' and 'dev' in to_build: | ||
print(f"Building version {version} ({name})") | ||
# Build the dev version from my local clone | ||
sphinx_build('dev', source=dev / 'source', build=host / 'dev') | ||
|
||
elif 'latest' in name: | ||
if 'latest' not in to_build and version not in to_build: | ||
# Skip building the latest version if it's not specified | ||
continue | ||
print(f"Building version {version} ({name})") | ||
# Build the latest version from the head of main branch | ||
checkout_version('latest') | ||
sphinx_build(version, source=source, build=host / 'latest') | ||
else: | ||
if version not in to_build and name != '' and name not in to_build: | ||
# Skip building the version if it's not specified | ||
continue | ||
print(f"Building version {version} ({name})") | ||
# Checkout the specified version | ||
checkout_version(version) | ||
sphinx_build(version, source=source, build=host / version) | ||
|
||
# Checkout the main branch | ||
checkout_version('latest') |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ | |
from . import utils | ||
|
||
|
||
__version__ = '2024.07.0' | ||
__version__ = '2024.08.1' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Automatically update the version of the package. | ||
To be used with pre-commit hooks. | ||
CalVer format: YYYY.MM.PATCH | ||
Publishing versions in May, August, and December. | ||
""" | ||
import datetime | ||
import os | ||
import re | ||
|
||
init_file = os.path.join(os.path.dirname(__file__), '__init__.py') | ||
|
||
# Get the current version | ||
with open(init_file, 'r') as f: | ||
current_version = re.search(r'__version__ = [\'\"](\d{4}\.\d{2}\.\d+)[\'\"]', | ||
f.read()).group(1) | ||
cur_year, cur_month, cur_patch = current_version.split('.') | ||
|
||
is_major_change = False | ||
|
||
def get_version() -> str: | ||
global is_major_change | ||
now = datetime.datetime.now() | ||
year = now.year | ||
month = now.month | ||
|
||
if month <= 5: | ||
month = 5 | ||
elif month > 5 and month <= 8: | ||
month = 8 | ||
else: | ||
month = 12 | ||
|
||
# If the month has changed, reset the patch | ||
if month != int(cur_month): | ||
is_major_change = True | ||
return f'{year}.{month:02d}.0' | ||
|
||
patch = int(cur_patch) + 1 | ||
|
||
return f'{year}.{month:02d}.{patch}' | ||
|
||
|
||
def update(version: str): | ||
with open(init_file, 'r') as f: | ||
lines = f.readlines() | ||
|
||
updated_lines = [] | ||
for line in lines: | ||
if line.startswith('__version__'): | ||
updated_lines.append(f"__version__ = '{version}'\n") | ||
else: | ||
updated_lines.append(line) | ||
|
||
with open(init_file, 'w') as f: | ||
f.writelines(updated_lines) | ||
|
||
|
||
if __name__ == "__main__": | ||
version = get_version() | ||
update(version) | ||
print(f'Updated version to {version}') |