|
1 | 1 | 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 }} |
3 | 11 |
|
4 | 12 | runs: |
5 | 13 | using: "composite" |
6 | 14 | steps: |
7 | 15 | - name: load shared variables |
| 16 | + id: load |
8 | 17 | shell: bash |
9 | 18 | run: | |
10 | 19 | # Read shared-vars.yml and set environment variables |
11 | 20 | python << 'EOF' |
12 | 21 | import yaml |
13 | 22 | 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) |
14 | 38 |
|
15 | 39 | # Load shared variables file |
16 | 40 | with open('.github/shared-vars.yml', 'r') as f: |
17 | 41 | config = yaml.safe_load(f) |
18 | 42 |
|
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) |
27 | 45 |
|
28 | 46 | # Write to GITHUB_ENV |
29 | 47 | 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()): |
31 | 49 | env_file.write(f"{key}={value}\n") |
32 | 50 | print(f"✅ Set {key}={value}") |
33 | 51 |
|
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', {}) |
36 | 54 | test_matrix = python_config.get('test_matrix', []) |
37 | 55 | 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}") |
40 | 64 | EOF |
0 commit comments