Skip to content

Commit 97e223f

Browse files
committed
Update gh workflows to update "latest" and avoid docs pull clash
- include docs build as part of release and push to avoid a pull clash - update checkout/python action versions for 4 and 5 - separate prerelease and release workflows - prerelease workflow pushes on any main push and wont collide with versions - fix typo referring to other repo - make pyproject.toml dependencies recursive so tests also includes docs and viz
1 parent 8fdf83c commit 97e223f

File tree

7 files changed

+186
-124
lines changed

7 files changed

+186
-124
lines changed

.github/workflows/docs.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/prerelease.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This workflow will build and upload a Python Package to TestPyPI
2+
# https://github.com/marketplace/actions/pypi-publish
3+
name: Testing Building and Publish Python Package to TestPyPI
4+
on:
5+
push:
6+
branches: [main, develop]
7+
workflow_dispatch: # Manual trigger
8+
jobs:
9+
build:
10+
name: Build distribution 📦
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.x"
18+
- name: Install pypa/build
19+
run: >-
20+
python3 -m
21+
pip install
22+
build
23+
--user
24+
- name: Build a binary wheel and a source tarball
25+
run: python3 -m build
26+
- name: Store the distribution packages
27+
uses: actions/upload-artifact@v3
28+
with:
29+
name: python-package-distributions
30+
path: dist/
31+
publish-to-testpypi:
32+
name: Publish Python 🐍 distribution 📦 to TestPyPI
33+
needs:
34+
- build
35+
runs-on: ubuntu-latest
36+
environment:
37+
name: testpypi
38+
url: https://test.pypi.org/p/network-wrangler
39+
permissions:
40+
id-token: write # IMPORTANT: mandatory for trusted publishing
41+
steps:
42+
- name: Download all the dists
43+
uses: actions/download-artifact@v3
44+
with:
45+
name: python-package-distributions
46+
path: dist/
47+
- name: Publish distribution 📦 to TestPyPI
48+
if: steps.compare-versions.outputs.publish == 'true'
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
with:
51+
repository-url: https://test.pypi.org/legacy/
52+
skip-existing: true
53+
verbose: true

.github/workflows/publish.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

.github/workflows/push.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,24 @@ jobs:
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
30-
pip install -r requirements.txt
31-
pip install -r requirements.tests.txt
32-
pip install -r requirements.docs.txt
33-
- name: Install package
34-
run: |
35-
pip install -e .
30+
pip install -e .[tests]
3631
- name: Run Ruff
3732
run: ruff check --output-format=github network_wrangler
3833
- name: Run tests with coverage and benchmarking
3934
run: |
40-
pytest --junitxml=coverage.xml --benchmark-save=pr_benchmark --benchmark-json=pr_benchmark.json
35+
pytest --junitxml=coverage.xml --benchmark-save=benchmark --benchmark-json=benchmark.json
36+
- name: Build docs
37+
run: |
38+
mike deploy --push ${{ github.ref_name }}
39+
- name: Update latest alias if on main branch
40+
if: github.ref == 'refs/heads/main'
41+
run: |
42+
mike alias latest ${{ github.ref_name }} --push
4143
- name: Store benchmark result
4244
uses: benchmark-action/github-action-benchmark@v1
4345
with:
4446
tool: 'pytest'
45-
output-file-path: pr_benchmark.json
47+
output-file-path: benchmark.json
4648
github-token: ${{ secrets.GITHUB_TOKEN }}
4749
comment-on-alert: true
4850
summary-always: true
@@ -51,3 +53,10 @@ jobs:
5153
uses: MishaKav/pytest-coverage-comment@main
5254
with:
5355
junitxml-path: ./coverage.xml
56+
- name: Upload coverage and benchmark artifacts
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: coverage-and-benchmark
60+
path: |
61+
coverage.xml
62+
benchmark.json

.github/workflows/release.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# This workflow will build and upload a Python Package to PyPI
2+
# https://github.com/marketplace/actions/pypi-publish
3+
name: Publish Python Package 📦 to PyPI
4+
on:
5+
release:
6+
types: [created]
7+
workflow_dispatch: # Manual trigger
8+
jobs:
9+
build:
10+
name: Build distribution 📦
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.x"
18+
- name: Install pypa/build
19+
run: >-
20+
python3 -m
21+
pip install
22+
build
23+
--user
24+
- name: Build a binary wheel and a source tarball
25+
run: python3 -m build
26+
- name: Store the distribution packages
27+
uses: actions/upload-artifact@v3
28+
with:
29+
name: python-package-distributions
30+
path: dist/
31+
publish-to-pypi:
32+
name: >-
33+
Publish Python 🐍 distribution 📦 to PyPI
34+
needs:
35+
- build
36+
runs-on: ubuntu-latest
37+
environment:
38+
name: pypi
39+
url: https://pypi.org/p/network-wrangler
40+
permissions:
41+
id-token: write # IMPORTANT: mandatory for trusted publishing
42+
steps:
43+
- name: Download all the dists
44+
uses: actions/download-artifact@v3
45+
with:
46+
name: python-package-distributions
47+
path: dist/
48+
- name: Publish distribution 📦 to PyPI
49+
uses: pypa/gh-action-pypi-publish@release/v1
50+
publish-docs:
51+
name: Publish documentation 📚 to GitHub Pages
52+
needs:
53+
- build
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
- name: Set up Python ${{ matrix.python-version }}
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: ${{ matrix.python-version }}
62+
- name: Configure Git user
63+
run: |
64+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
65+
git config --local user.name "github-actions[bot]"
66+
- name: Install dependencies
67+
run: |
68+
python -m pip install --upgrade pip
69+
pip install -e .[docs]
70+
- name: Build docs
71+
run: |
72+
mike deploy --push --update-aliases latest ${{ github.ref_name }}

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ tests = [
7575
"ruff",
7676
"snakeviz",
7777
"vulture",
78+
"network-wrangler[viz]",
79+
"network-wrangler[docs]",
7880
]
7981

8082

tests/test_setup.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,57 @@ def test_setup(request):
99
"""Create virtual environment and test that network wrangler can be installed and imported."""
1010
WranglerLogger.info(f"--Starting: {request.node.name}")
1111
WranglerLogger.debug("Creating virtual environment...")
12-
subprocess.run(["python", "-m", "venv", "wranglertest"], check=True)
12+
venv_name = "wranglertest"
13+
subprocess.run(["python", "-m", "venv", f"{venv_name}"], check=True)
1314
WranglerLogger.debug("Created virtual environment.\nInstalling Wrangler...")
14-
install_process = subprocess.run(["wranglertest/bin/pip", "install", "-e", "."], check=True)
15+
install_process = subprocess.run([f"{venv_name}/bin/pip", "install", "-e", "."], check=True)
1516
WranglerLogger.debug(f"Installed Wrangler.\n{install_process.stdout}")
1617
pip_list_process = subprocess.run(
17-
["wranglertest/bin/pip", "list"], capture_output=True, text=True, check=False
18+
[f"{venv_name}/bin/pip", "list"], capture_output=True, text=True, check=False
1819
)
1920
WranglerLogger.debug(f"Venv contents:\n{pip_list_process.stdout}")
2021
WranglerLogger.debug("Testing import...")
2122

2223
# Capture output and error messages
2324
import_process = subprocess.run(
24-
["wranglertest/bin/python", "-c", "import network_wrangler"],
25+
[f"{venv_name}/bin/python", "-c", "import network_wrangler"],
26+
capture_output=True,
27+
text=True,
28+
check=False,
29+
)
30+
31+
if import_process.returncode != 0:
32+
WranglerLogger.error(f"Import failed with error:\n{import_process.stderr}")
33+
raise subprocess.CalledProcessError(
34+
import_process.returncode,
35+
import_process.args,
36+
output=import_process.stdout,
37+
stderr=import_process.stderr,
38+
)
39+
40+
WranglerLogger.debug("Import successful.")
41+
42+
43+
def test_setup_testingenv(request):
44+
"""Create virtual environment and test that network wrangler can be installed and imported."""
45+
WranglerLogger.info(f"--Starting: {request.node.name}")
46+
venv_name = "wranglertest"
47+
WranglerLogger.debug("Creating virtual environment for testing...")
48+
subprocess.run(["python", "-m", "venv", f"{venv_name}"], check=True)
49+
WranglerLogger.debug("Created virtual environment.\nInstalling Wrangler...")
50+
install_process = subprocess.run(
51+
[f"{venv_name}/bin/pip", "install", "-e", ".[tests]"], check=True
52+
)
53+
WranglerLogger.debug(f"Installed Wrangler.\n{install_process.stdout}")
54+
pip_list_process = subprocess.run(
55+
[f"{venv_name}/bin/pip", "list"], capture_output=True, text=True, check=False
56+
)
57+
WranglerLogger.debug(f"Venv contents:\n{pip_list_process.stdout}")
58+
WranglerLogger.debug("Testing import...")
59+
60+
# Capture output and error messages
61+
import_process = subprocess.run(
62+
[f"{venv_name}/bin/python", "-c", "import network_wrangler"],
2563
capture_output=True,
2664
text=True,
2765
check=False,

0 commit comments

Comments
 (0)