Skip to content

Commit 3eb236d

Browse files
Reusable workflow for matrix
1 parent 0c6444d commit 3eb236d

File tree

1 file changed

+5
-51
lines changed

1 file changed

+5
-51
lines changed

.github/workflows/deploy-sandbox.yml

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,11 @@ permissions:
1010

1111
jobs:
1212
build-matrix:
13-
runs-on: ubuntu-latest
14-
outputs:
15-
matrix: ${{ steps.build-matrix.outputs.matrix }}
16-
steps:
17-
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
18-
- name: Build Environment Matrix
19-
id: build-matrix
20-
shell: python
21-
env:
22-
PLATFORM_ENVIRONMENT: "sandbox"
23-
run: |
24-
from pathlib import Path
25-
import os
26-
import json
27-
28-
def discover_environments(platform_path: Path = Path("platform")) -> list[Path]:
29-
return [d for d in platform_path.iterdir() if d.is_dir()]
30-
31-
def discover_regions(environment_path: Path) -> list[Path]:
32-
return [d for d in environment_path.iterdir() if d.is_dir()]
33-
34-
def discover_instances(region_path: Path) -> list[Path]:
35-
return [d for d in region_path.iterdir() if d.is_dir()]
36-
37-
try:
38-
ENVIRONMENT = os.environ['PLATFORM_ENVIRONMENT']
39-
except KeyError as ke:
40-
raise ValueError("Environment variable named PLATFORM_ENVIRONMENT was not found. This variable must be supplied so that a matrix of environments can be built!")
41-
42-
if len(ENVIRONMENT) == 0:
43-
raise ValueError("Environment variable PLATFORM_ENVIRONMENT was empty. This variable must be supplied so that a matrix of environments can be built!")
44-
45-
all_environments = discover_environments()
46-
matrix = {"terragrunt_environment": []}
47-
try:
48-
selected_environment = list(filter(lambda x: x.name == ENVIRONMENT, all_environments))[0]
49-
except Exception:
50-
raise ValueError(f"Expected environment '{ENVIRONMENT}' not found in {all_environments}")
51-
52-
regions = discover_regions(environment_path=selected_environment)
53-
54-
for region_path in regions:
55-
region_instances = discover_instances(region_path=region_path)
56-
for instance in region_instances:
57-
matrix["terragrunt_environment"].append({"environment": selected_environment.name, "region": region_path.name, "instance": instance.name})
58-
59-
print("Generated the following environment matrix:")
60-
print(json.dumps(matrix, indent=4))
61-
62-
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
63-
f.write(f"matrix={json.dumps(matrix, separators=(',', ':'))}")
13+
permissions:
14+
contents: read
15+
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-github-matrix-tg.yml@0.1.0
16+
with:
17+
platform_environment: sandbox
6418

6519
call-terragrunt-deploy:
6620
needs: build-matrix

0 commit comments

Comments
 (0)