Skip to content

Commit c5c8333

Browse files
fix(front): default simple template for new project onboarding (#430)
## πŸ“ Description `simple.yml` template was removed by misstake here: https://github.com/semaphoreio/semaphore/pull/31/files add template validation ## βœ… Checklist - [ ] I have tested this change - [ ] This change requires documentation update
1 parent 4a2d7ca commit c5c8333

File tree

7 files changed

+212
-7
lines changed

7 files changed

+212
-7
lines changed

β€Žfront/Makefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ pb.gen.public:
8383
scripts/vagrant_sudo chown -R $$(id -u $${USER}):$$(id -g $${USER}) lib/public_api
8484
rm -rf $(TMP_REPO_DIR)
8585

86-
workflow.templates.gen:
87-
@echo "Generating workflow templates"
88-
rm -rf $(TMP_REPO_DIR)
89-
git clone [email protected]:renderedtext/app-design.git $(TMP_REPO_DIR) && (cd $(TMP_REPO_DIR) && git checkout $(APP_DESIGN_BRANCH) && make check.templates && cd -)
90-
./scripts/generate-workflow-templates.sh $(TMP_REPO_DIR)
91-
rm -rf $(TMP_REPO_DIR)
92-
9386
deps.check: build
9487
ifeq ($(CI),)
9588
docker compose $(DOCKER_COMPOSE_OPTS) run --no-deps -e MIX_ENV=dev app ash -c 'mix deps.unlock --check-unused'
@@ -158,3 +151,8 @@ dev.ce.server: build
158151

159152
console.ce.bash:
160153
DOCKER_COMPOSE_RUN_OPTS="--service-ports $(CONTAINER_CE_ENV_VARS)" $(MAKE) console.bash
154+
155+
workflow.templates.check:
156+
@echo "πŸ“¦ Checking templates..."
157+
./scripts/check-templates.sh workflow_templates/saas_new
158+
./scripts/check-templates.sh workflow_templates/ce_new

β€Žfront/scripts/check-templates.sh

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
if [ $# -lt 1 ]; then
7+
echo "Usage: $0 <root_directory>"
8+
exit 1
9+
fi
10+
11+
root_dir="$1"
12+
properties_dir="${root_dir}/properties"
13+
setup_json="${root_dir}/setup.json"
14+
15+
# First check if setup.json exists and is valid
16+
if [ ! -f "$setup_json" ]; then
17+
echo "❗️ Error: setup.json not found in root directory"
18+
exit 1
19+
fi
20+
21+
# Validate setup.json
22+
if ! jq empty "$setup_json" 2>/dev/null; then
23+
echo "❗️ Error: setup.json is not a valid JSON file"
24+
exit 1
25+
else
26+
echo "βœ… setup.json is valid"
27+
fi
28+
29+
if [ ! -d "$properties_dir" ]; then
30+
echo "❗️ Error: Properties directory not found: $properties_dir"
31+
exit 1
32+
fi
33+
34+
required_fields=(
35+
"title"
36+
"description"
37+
"short_description"
38+
"environment"
39+
"icon"
40+
"template_path"
41+
)
42+
43+
exit_code=0
44+
templates_checked=0
45+
46+
# Function to validate YAML block dependencies
47+
validate_yaml_blocks() {
48+
local yaml_file="$1"
49+
local title="$2"
50+
51+
# First check if the YAML is valid
52+
if ! yq eval '.' "$yaml_file" > /dev/null 2>&1; then
53+
echo "❌ Error: Invalid YAML in template for '${title}': ${yaml_file}"
54+
return 1
55+
fi
56+
57+
# Get all block names
58+
local block_names
59+
block_names=$(yq eval '.blocks[].name' "$yaml_file")
60+
61+
if [ -z "$block_names" ]; then
62+
echo "⚠️ Warning: No blocks found in template for '${title}': ${yaml_file}"
63+
return 0
64+
fi
65+
66+
# Check blocks for valid dependencies (if present)
67+
local invalid_deps=0
68+
while IFS= read -r block; do
69+
local block_name
70+
block_name=$(yq eval '.blocks[] | select(.name == "'$block'") | .name' "$yaml_file")
71+
72+
# Check if dependencies field exists (optional)
73+
local deps_field
74+
deps_field=$(yq eval '.blocks[] | select(.name == "'$block'") | has("dependencies")' "$yaml_file")
75+
76+
# Only validate dependencies if the field exists
77+
if [ "$deps_field" = "true" ]; then
78+
# Check if dependencies field is an array
79+
local deps_type
80+
deps_type=$(yq eval '.blocks[] | select(.name == "'$block'") | .dependencies | type' "$yaml_file")
81+
82+
if [ "$deps_type" != "!!seq" ]; then
83+
echo "❌ Error: Block '${block_name}' in '${title}' has dependencies field that is not an array"
84+
((invalid_deps++))
85+
else
86+
# Validate each dependency in this block
87+
while IFS= read -r dep; do
88+
if [ ! -z "$dep" ] && ! echo "$block_names" | grep -Fxq "$dep"; then
89+
echo "❌ Error: Block '${block_name}' in '${title}' has undefined dependency: ${dep}"
90+
((invalid_deps++))
91+
fi
92+
done < <(yq eval '.blocks[] | select(.name == "'$block'") | .dependencies[]' "$yaml_file")
93+
fi
94+
fi
95+
done < <(yq eval '.blocks[].name' "$yaml_file")
96+
97+
if [ $invalid_deps -eq 0 ]; then
98+
echo "βœ… Block dependencies valid in template for '${title}': ${yaml_file}"
99+
fi
100+
101+
return $invalid_deps
102+
}
103+
104+
for json_file in "$properties_dir"/*.properties.json; do
105+
if [ ! -f "$json_file" ]; then
106+
continue
107+
fi
108+
109+
# Check if the JSON file is valid
110+
if ! jq empty "$json_file" 2>/dev/null; then
111+
echo "❌ Error: $(basename "$json_file") is not a valid JSON file"
112+
exit_code=1
113+
continue
114+
fi
115+
116+
# Check required fields
117+
for field in "${required_fields[@]}"; do
118+
value=$(jq -r ".$field" "$json_file")
119+
if [ "$value" = "null" ] || [ -z "$value" ]; then
120+
echo "❗️ Error: Required field '$field' is missing in $(basename "$json_file")"
121+
exit_code=1
122+
fi
123+
done
124+
125+
template_path=$(jq -r '.template_path' "$json_file")
126+
title=$(jq -r '.title' "$json_file")
127+
128+
if [ "$template_path" = "null" ]; then
129+
echo "❗️ Warning: No template_path found in $json_file"
130+
continue
131+
fi
132+
133+
full_template_path="${root_dir}/${template_path}"
134+
if [ ! -f "$full_template_path" ]; then
135+
echo "❌ Error: Template not found for '${title}', properties define template as: ${template_path}"
136+
exit_code=1
137+
else
138+
# Validate YAML block dependencies
139+
if ! validate_yaml_blocks "$full_template_path" "$title"; then
140+
exit_code=1
141+
fi
142+
fi
143+
templates_checked=$((templates_checked + 1))
144+
done
145+
146+
if [ $exit_code -eq 0 ] && [ $templates_checked -gt 0 ]; then
147+
echo "βœ… All templates in ${root_dir} are valid"
148+
fi
149+
150+
exit $exit_code

β€Žfront/workflow_templates/ce_new/templates/elixir_docker_etl.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ global_job_config:
4141

4242
blocks:
4343
- name: "πŸ› οΈ Setup"
44+
dependencies: []
4445
task:
4546
jobs:
4647
- name: "Compile Code"
4748
commands:
4849
- mix compile # Compile the project
4950

5051
- name: "πŸ” Analyze Code"
52+
dependencies: ["πŸ› οΈ Setup"]
5153
task:
5254
jobs:
5355
- name: "Run Credo"
@@ -58,6 +60,7 @@ blocks:
5860
- mix format --check-formatted # Ensure all code is properly formatted
5961

6062
- name: "πŸ§ͺ Run Tests"
63+
dependencies: ["πŸ” Analyze Code"]
6164
task:
6265
jobs:
6366
- name: "Run Tests and Generate Coverage"
@@ -71,6 +74,7 @@ blocks:
7174
- cache store coverage-$SEMAPHORE_WORKFLOW_ID cover # Store coverage results
7275

7376
- name: "πŸ“¦ Build Docker Image"
77+
dependencies: ["πŸ§ͺ Run Tests"]
7478
task:
7579
prologue:
7680
commands:

β€Žfront/workflow_templates/saas_new/templates/java_saas_spring.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ global_job_config:
2424

2525
blocks:
2626
- name: "βš™οΈ Build"
27+
dependencies: []
2728
task:
2829
env_vars:
2930
- name: MAVEN_OPTS
@@ -35,6 +36,7 @@ blocks:
3536
- cache store # Cache the build output for later use
3637

3738
- name: "πŸ§ͺ Test"
39+
dependencies: ["βš™οΈ Build"]
3840
task:
3941
env_vars:
4042
- name: MAVEN_OPTS
@@ -54,6 +56,7 @@ blocks:
5456
- test-results publish target/surefire-reports/*.xml # Publish test reports to Semaphore
5557

5658
- name: "πŸš€ Performance Tests"
59+
dependencies: ["βš™οΈ Build"]
5760
task:
5861
env_vars:
5962
- name: MAVEN_OPTS
@@ -68,6 +71,7 @@ blocks:
6871
- 'mvn jmeter:results' # Process JMeter test results
6972

7073
- name: "🐳 Dockerize"
74+
dependencies: ["πŸš€ Performance Tests"]
7175
task:
7276
env_vars:
7377
- name: MAVEN_OPTS

β€Žfront/workflow_templates/saas_new/templates/phoenix_docker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ global_job_config:
4444
blocks:
4545
# βš™οΈ Block 1: Install dependencies & compile – caches Hex/Rebar & JS assets
4646
- name: "βš™οΈ Install & Compile"
47+
dependencies: []
4748
task:
4849
jobs:
4950
- name: "βš™οΈ Install & Compile"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This is a simple Semaphore configuration file
2+
# For more information about Semaphore configuration visit:
3+
# https://docs.semaphoreci.com/reference/pipeline-yaml-reference/
4+
5+
version: v1.0 # Semaphore configuration version
6+
name: "🎯 Simple CI Pipeline" # Pipeline display name
7+
8+
# Define the machine type and OS image
9+
agent:
10+
machine:
11+
type: {{ machine_type }}
12+
os_image: {{ os_image }}
13+
14+
# Configure when to stop the pipeline early
15+
fail_fast:
16+
stop:
17+
when: branch != 'main' # Stop all blocks if a job fails on non-main branches
18+
auto_cancel:
19+
running:
20+
when: branch != 'main' # Cancel running pipelines on non-main branches
21+
queued:
22+
when: branch = 'main' # Cancel queued pipelines on main branch
23+
24+
# Pipeline blocks represent groups of jobs that can run in parallel
25+
blocks:
26+
# Block for testing
27+
- name: "πŸ§ͺ Test"
28+
task:
29+
jobs:
30+
- name: "🟒 Run Tests"
31+
commands:
32+
- echo "Checking out code..."
33+
- echo "Installing dependencies..."
34+
- echo "Running test suite..."
35+
- echo "Tests completed successfully!"
36+
37+
# Block for deployment
38+
- name: "πŸš€ Deploy"
39+
dependencies: ["πŸ§ͺ Test"] # Only deploy if tests pass
40+
task:
41+
jobs:
42+
- name: "πŸ“¦ Deploy to Production"
43+
commands:
44+
- echo "Building application..."
45+
- echo "Running security checks..."
46+
- echo "Deploying to production..."
47+
- echo "Deployment completed successfully!"

β€Žfront/workflow_templates/saas_new/templates/simple_saas.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ auto_cancel:
2525
blocks:
2626
# Block for testing
2727
- name: "πŸ§ͺ Test"
28+
dependencies: []
2829
task:
2930
jobs:
3031
- name: "🟒 Run Tests"

0 commit comments

Comments
Β (0)