Skip to content

Commit

Permalink
Converting some CI actions from GitLab to GitHub (#1)
Browse files Browse the repository at this point in the history
Add initial python-based github workflow.

* Create python-package.yml
* Addnew github action workflows for linting, packaging, and pages
* Test using a different branch for now.
* Add missing dependencies
* Add a check to verify if we want to create the model component documentation.
* Revert debugging branch to target main.
* Remove unneeded push branches line
* Allow running linting for pushes to all branches

---------

Signed-off-by: Steven Elliott <[email protected]>
  • Loading branch information
sdelliot authored Nov 15, 2024
1 parent 843fbdb commit ec3a83e
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 11 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Documentation

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Build Documentation
run: |
tox -e dependencies,docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/build/html/

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
36 changes: 36 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Linting

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "main" ]

jobs:
lint:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Lint code
run: |
tox -e lint
- name: Lint documentation
run: |
tox -e lint-docs
39 changes: 39 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
24 changes: 13 additions & 11 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def make_index(self, basepath):
This function overwrites the existing ``model_components/index.rst`` file.
Args:
basepath (str): The path for adding the index file.
basepath (pathlib.Path): The path for adding the index file.
"""
# Get the list of model components
index = """.. _available_model_components:
Expand All @@ -349,7 +349,7 @@ def make_index(self, basepath):
"""

# First remove all existing symlinks
all_files = [basepath / f for f in Path(basepath).iterdir()]
all_files = [basepath / f for f in basepath.iterdir()]
for f in all_files:
if f.is_symlink():
f.unlink()
Expand Down Expand Up @@ -402,13 +402,13 @@ def make_index(self, basepath):

print(f"README PATH={readme_path}")
self.sym_link_directories(
readme_path, Path(basepath) / f"{mc.name}{readme_path.suffix}"
readme_path, basepath / f"{mc.name}{readme_path.suffix}"
)
index += f" {mc.name}\n"

index += "\n"

with (Path(basepath) / "index.rst").open("w") as index_file:
with (basepath / "index.rst").open("w") as index_file:
index_file.write(index)

def sym_link_directories(self, curr, new):
Expand All @@ -424,11 +424,13 @@ def sym_link_directories(self, curr, new):
new.symlink_to(curr)


# Load all model components into the path
mcd = ModelComponentDocumentation()
mcd.get_mc_list()
# Check to see if we should include model component documentation
path = Path("model_components")
if path.exists():
# Load all model components into the path
mcd = ModelComponentDocumentation()
mcd.get_mc_list()

# Build out the new model components TOCTREE
path = "model_components"
mcd.make_index(path)
autodoc_mock_imports = list(mcd.mock_import_set)
# Build out the new model components TOCTREE
mcd.make_index(path)
autodoc_mock_imports = list(mcd.mock_import_set)

0 comments on commit ec3a83e

Please sign in to comment.