Skip to content

Commit d39bd0e

Browse files
committed
try to fix doc build, define matricies in one place
1 parent 606a064 commit d39bd0e

File tree

5 files changed

+74
-19
lines changed

5 files changed

+74
-19
lines changed
Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,64 @@
11
name: "Load Shared Variables"
2-
description: "Loads shared variables from .github/shared-vars.yml and sets them as environment variables"
2+
description: "Loads shared variables from .github/shared-vars.yml and sets them as environment variables and outputs"
3+
4+
outputs:
5+
test-matrix:
6+
description: "Python version matrix for full tests"
7+
value: ${{ steps.load.outputs.test-matrix }}
8+
min-deps-matrix:
9+
description: "Python version matrix for minimum dependency tests"
10+
value: ${{ steps.load.outputs.min-deps-matrix }}
311

412
runs:
513
using: "composite"
614
steps:
715
- name: load shared variables
16+
id: load
817
shell: bash
918
run: |
1019
# Read shared-vars.yml and set environment variables
1120
python << 'EOF'
1221
import yaml
1322
import os
23+
import json
24+
25+
def flatten_dict(d, parent_key='', sep='_'):
26+
"""Recursively flatten nested dictionary into env var format."""
27+
items = []
28+
for k, v in d.items():
29+
new_key = f"{parent_key}{sep}{k}".upper() if parent_key else k.upper()
30+
if isinstance(v, dict):
31+
items.extend(flatten_dict(v, new_key, sep=sep).items())
32+
elif isinstance(v, list):
33+
# Convert lists to JSON strings for use in workflows
34+
items.append((new_key, json.dumps(v)))
35+
else:
36+
items.append((new_key, str(v)))
37+
return dict(items)
1438
1539
# Load shared variables file
1640
with open('.github/shared-vars.yml', 'r') as f:
1741
config = yaml.safe_load(f)
1842
19-
# Set Python version environment variables
20-
python_config = config.get('python', {})
21-
22-
env_vars = {
23-
'PYTHON_DEFAULT': python_config.get('default', '3.12'),
24-
'PYTHON_LATEST': python_config.get('latest', '3.13'),
25-
'PYTHON_RELEASE': python_config.get('release', '3.11'),
26-
}
43+
# Flatten all variables
44+
env_vars = flatten_dict(config)
2745
2846
# Write to GITHUB_ENV
2947
with open(os.environ['GITHUB_ENV'], 'a') as env_file:
30-
for key, value in env_vars.items():
48+
for key, value in sorted(env_vars.items()):
3149
env_file.write(f"{key}={value}\n")
3250
print(f"✅ Set {key}={value}")
3351
34-
# For matrix values, we can't set them directly in env
35-
# Workflows will need to read the file directly for matrix strategy
52+
# Also output specific matrices for job outputs
53+
python_config = config.get('python', {})
3654
test_matrix = python_config.get('test_matrix', [])
3755
min_deps_matrix = python_config.get('min_deps_matrix', [])
38-
print(f"📋 Test matrix available: {test_matrix}")
39-
print(f"📋 Min deps matrix available: {min_deps_matrix}")
56+
57+
# Write to GITHUB_OUTPUT for action outputs
58+
with open(os.environ['GITHUB_OUTPUT'], 'a') as output_file:
59+
output_file.write(f"test-matrix={json.dumps(test_matrix)}\n")
60+
output_file.write(f"min-deps-matrix={json.dumps(min_deps_matrix)}\n")
61+
62+
print(f"📋 Output test-matrix: {test_matrix}")
63+
print(f"📋 Output min-deps-matrix: {min_deps_matrix}")
4064
EOF

.github/doc_environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: dascore
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.12
65
- pytest
76
- pydantic>2.0
87
- pip

.github/shared-vars.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@ python:
55
# Default Python version for most workflows (docs, linting, coverage, etc.)
66
default: "3.13"
77

8+
# Full test matrix versions (runtests.yml)
9+
test_matrix:
10+
- "3.11"
11+
- "3.12"
12+
- "3.13"
13+
- "3.14"
14+
15+
# Minimum dependency test matrix versions (run_min_dep_tests.yml)
16+
min_deps_matrix:
17+
- "3.13"
18+
- "3.14"
19+
820
# Add other shared variables here as needed

.github/workflows/run_min_dep_tests.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,25 @@ concurrency:
2323
cancel-in-progress: true
2424

2525
jobs:
26+
# Load Python version matrix from shared-vars.yml
27+
setup:
28+
runs-on: ubuntu-latest
29+
outputs:
30+
python-matrix: ${{ steps.load-vars.outputs.min-deps-matrix }}
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: ./.github/actions/load-shared-vars
34+
id: load-vars
35+
2636
# Runs the tests on combinations of the supported python/os matrix.
2737
test_code_min_deps:
28-
38+
needs: setup
2939
timeout-minutes: 25
3040
runs-on: ${{ matrix.os }}
3141
strategy:
3242
matrix:
3343
os: [ ubuntu-latest, macos-latest, windows-latest ]
34-
python-version: [ '3.13', '3.14' ]
44+
python-version: ${{ fromJson(needs.setup.outputs.python-matrix) }}
3545

3646
# only run if CI isn't turned off
3747
if: github.event_name == 'push' || !contains(github.event.pull_request.labels.*.name, 'no_ci')

.github/workflows/runtests.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,25 @@ concurrency:
2525
cancel-in-progress: true
2626

2727
jobs:
28+
# Load Python version matrix from shared-vars.yml
29+
setup:
30+
runs-on: ubuntu-latest
31+
outputs:
32+
python-matrix: ${{ steps.load-vars.outputs.test-matrix }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: ./.github/actions/load-shared-vars
36+
id: load-vars
37+
2838
# Runs the tests on combinations of the supported python/os matrix.
2939
test_code:
30-
40+
needs: setup
3141
timeout-minutes: 25
3242
runs-on: ${{ matrix.os }}
3343
strategy:
3444
matrix:
3545
os: [ubuntu-latest, macos-latest, windows-latest]
36-
python-version: ['3.11', '3.12', '3.13', '3.14' ]
46+
python-version: ${{ fromJson(needs.setup.outputs.python-matrix) }}
3747

3848
# only run if CI isn't turned off
3949
if: github.event_name == 'push' || !contains(github.event.pull_request.labels.*.name, 'no_ci')

0 commit comments

Comments
 (0)