Skip to content

Commit ec3a83e

Browse files
authored
Converting some CI actions from GitLab to GitHub (#1)
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]>
1 parent 843fbdb commit ec3a83e

File tree

4 files changed

+150
-11
lines changed

4 files changed

+150
-11
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Documentation
5+
6+
on:
7+
# Runs on pushes targeting the default branch
8+
push:
9+
branches: ["main"]
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
21+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
22+
concurrency:
23+
group: "pages"
24+
cancel-in-progress: false
25+
26+
jobs:
27+
build:
28+
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
- name: Setup Pages
35+
uses: actions/configure-pages@v5
36+
- name: Set up Python
37+
uses: actions/setup-python@v3
38+
with:
39+
python-version: '3.x'
40+
- name: Install dependencies
41+
run: |
42+
python -m pip install --upgrade pip
43+
python -m pip install tox
44+
- name: Build Documentation
45+
run: |
46+
tox -e dependencies,docs
47+
- name: Upload artifact
48+
uses: actions/upload-pages-artifact@v3
49+
with:
50+
path: docs/build/html/
51+
52+
# Deployment job
53+
deploy:
54+
environment:
55+
name: github-pages
56+
url: ${{ steps.deployment.outputs.page_url }}
57+
runs-on: ubuntu-latest
58+
needs: build
59+
steps:
60+
- name: Deploy to GitHub Pages
61+
id: deployment
62+
uses: actions/deploy-pages@v4

.github/workflows/linting.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Linting
5+
6+
on:
7+
push:
8+
branches: [ "*" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
lint:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ["3.9", "3.10", "3.11"]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install tox
31+
- name: Lint code
32+
run: |
33+
tox -e lint
34+
- name: Lint documentation
35+
run: |
36+
tox -e lint-docs
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
deploy:
20+
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: '3.x'
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install build
33+
- name: Build package
34+
run: python -m build
35+
- name: Publish package
36+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37+
with:
38+
user: __token__
39+
password: ${{ secrets.PYPI_API_TOKEN }}

docs/source/conf.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def make_index(self, basepath):
337337
This function overwrites the existing ``model_components/index.rst`` file.
338338
339339
Args:
340-
basepath (str): The path for adding the index file.
340+
basepath (pathlib.Path): The path for adding the index file.
341341
"""
342342
# Get the list of model components
343343
index = """.. _available_model_components:
@@ -349,7 +349,7 @@ def make_index(self, basepath):
349349
"""
350350

351351
# First remove all existing symlinks
352-
all_files = [basepath / f for f in Path(basepath).iterdir()]
352+
all_files = [basepath / f for f in basepath.iterdir()]
353353
for f in all_files:
354354
if f.is_symlink():
355355
f.unlink()
@@ -402,13 +402,13 @@ def make_index(self, basepath):
402402

403403
print(f"README PATH={readme_path}")
404404
self.sym_link_directories(
405-
readme_path, Path(basepath) / f"{mc.name}{readme_path.suffix}"
405+
readme_path, basepath / f"{mc.name}{readme_path.suffix}"
406406
)
407407
index += f" {mc.name}\n"
408408

409409
index += "\n"
410410

411-
with (Path(basepath) / "index.rst").open("w") as index_file:
411+
with (basepath / "index.rst").open("w") as index_file:
412412
index_file.write(index)
413413

414414
def sym_link_directories(self, curr, new):
@@ -424,11 +424,13 @@ def sym_link_directories(self, curr, new):
424424
new.symlink_to(curr)
425425

426426

427-
# Load all model components into the path
428-
mcd = ModelComponentDocumentation()
429-
mcd.get_mc_list()
427+
# Check to see if we should include model component documentation
428+
path = Path("model_components")
429+
if path.exists():
430+
# Load all model components into the path
431+
mcd = ModelComponentDocumentation()
432+
mcd.get_mc_list()
430433

431-
# Build out the new model components TOCTREE
432-
path = "model_components"
433-
mcd.make_index(path)
434-
autodoc_mock_imports = list(mcd.mock_import_set)
434+
# Build out the new model components TOCTREE
435+
mcd.make_index(path)
436+
autodoc_mock_imports = list(mcd.mock_import_set)

0 commit comments

Comments
 (0)