forked from radius-project/resource-types-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-all.sh
More file actions
executable file
·107 lines (94 loc) · 3.96 KB
/
Copy pathbuild-all.sh
File metadata and controls
executable file
·107 lines (94 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# ------------------------------------------------------------
# Copyright 2025 The Radius Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------
# =============================================================================
# build-all.sh
# -----------------------------------------------------------------------------
# Build all resource types and their associated Bicep and Terraform recipes.
#
# Behavior:
# - Discovers resource type folders using list-resource-type-folders.sh
# (optionally scoped to a provided root directory argument).
# - For each resource type folder, runs `make build-resource-type`.
# - For each Bicep file found under <resource>/recipes/**/<name>.bicep,
# runs `make build-bicep-recipe`.
# - For each Terraform directory found under <resource>/recipes/**/terraform/,
# runs `make build-terraform-recipe`.
#
# Usage:
# ./build-all.sh [ROOT_DIR]
# If ROOT_DIR is omitted, discovery defaults to the current working directory.
# =============================================================================
set -euo pipefail
ROOT_DIR="${1:-}"
PLATFORM_FILTER_RAW="${RECIPE_PLATFORM_FILTER:-}"
declare -a PLATFORM_FILTERS=()
if [[ -n "$PLATFORM_FILTER_RAW" ]]; then
IFS=',' read -ra _raw_filters <<< "$PLATFORM_FILTER_RAW"
for _entry in "${_raw_filters[@]}"; do
_trimmed="$(printf '%s' "$_entry" | xargs)"
if [[ -n "$_trimmed" ]]; then
PLATFORM_FILTERS+=("$_trimmed")
fi
done
fi
should_include_platform() {
local recipe_path="$1"
if [[ ${#PLATFORM_FILTERS[@]} -eq 0 ]]; then
return 0
fi
# Extract segment after recipes/ (path is relative: recipes/platform/...)
# Remove "recipes/" prefix if present
local rel="${recipe_path#recipes/}"
# Get the first path segment (the platform)
local platform="${rel%%/*}"
for _filter in "${PLATFORM_FILTERS[@]}"; do
if [[ "$platform" == "$_filter" ]]; then
return 0
fi
done
return 1
}
# Iterate over all resource type folders
while IFS= read -r type_dir; do
[[ -z "$type_dir" ]] && continue
make -s build-resource-type TYPE_FOLDER="$type_dir"
# Build/publish all Bicep recipes under this resource type, if any
recipes_root="$type_dir/recipes"
if [[ -d "$recipes_root" ]]; then
while IFS= read -r -d '' recipe_file; do
recipe_rel_path="${recipe_file#$type_dir/}"
if should_include_platform "$recipe_rel_path"; then
echo "Building Bicep recipe: $recipe_file"
make -s build-bicep-recipe RECIPE_PATH="$recipe_file"
else
echo "Skipping Bicep recipe (platform filter): $recipe_file"
fi
done < <(find "$recipes_root" -type f -name '*.bicep' -print0)
fi
# Build/publish all Terraform recipes under this resource type, if any
if [[ -d "$recipes_root" ]]; then
while IFS= read -r -d '' recipe_dir; do
recipe_rel_path="${recipe_dir#$type_dir/}"
if should_include_platform "$recipe_rel_path"; then
echo "Building Terraform recipe: $recipe_dir"
make -s build-terraform-recipe RECIPE_PATH="$recipe_dir"
else
echo "Skipping Terraform recipe (platform filter): $recipe_dir"
fi
done < <(find "$recipes_root" -type d -name 'terraform' -print0)
fi
done < <(./.github/scripts/list-resource-type-folders.sh ${ROOT_DIR:+"$ROOT_DIR"})