-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
416 lines (381 loc) · 16.3 KB
/
Makefile
File metadata and controls
416 lines (381 loc) · 16.3 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# Unified CLI Management for Multi-Vendor Tools
# Supports: workato, salesforce, and future vendor CLIs
.PHONY: setup status validate push pull clean help doctor workato-setup workato-status sf-setup sf-status sf-deploy start-recipes stop-recipes enable-api-endpoints create-api-client
# Default tool is workato for backward compatibility
tool ?= all
# ============================================================
# Platform Detection
# ============================================================
ifeq ($(OS),Windows_NT)
PLATFORM := windows
# MSYS2/MinGW Make (common Windows install via Chocolatey) sets HOME to
# Unix-style paths (e.g., /c/Users/foo). CLI tools use HOME to locate
# their credential and config stores:
# - Salesforce CLI: $HOME/.sf/ (OAuth tokens)
# - Workato CLI: $HOME/.workato/ (profiles & keychain refs)
# Normalize HOME to the native Windows USERPROFILE so CLIs can find
# credentials that were stored during interactive authentication.
export HOME := $(USERPROFILE)
# Prevent MSYS2 from auto-converting arguments that resemble Unix paths
# (e.g., --target-org could be mangled). These apply to recipe shell lines.
export MSYS_NO_PATHCONV := 1
export MSYS2_ARG_CONV_EXCL := *
WORKATO_CMD := workato
SF_CMD := sf
PS_EXEC := powershell -NoProfile -ExecutionPolicy Bypass -File
else
PLATFORM := unix
WORKATO_CMD ?= $(CURDIR)/bin/workato
SF_CMD ?= $(CURDIR)/bin/sf
endif
# CLI availability (evaluated by Make, not by shell)
ifeq ($(PLATFORM),windows)
HAS_WORKATO := $(or $(shell where workato >NUL 2>NUL && echo 1),$(wildcard bin/workato.cmd))
HAS_SF := $(or $(shell where sf >NUL 2>NUL && echo 1),$(wildcard bin/sf.cmd))
else
HAS_WORKATO := $(if $(wildcard $(WORKATO_CMD)),1,)
HAS_SF := $(if $(wildcard $(SF_CMD)),1,)
endif
# Script dispatch (maps to .sh on Unix, .ps1 on Windows with correct param syntax)
ifeq ($(PLATFORM),windows)
SETUP_WORKATO = $(PS_EXEC) app\scripts\setup\setup-cli.ps1 -Tool workato
SETUP_SALESFORCE = $(PS_EXEC) app\scripts\setup\setup-cli.ps1 -Tool salesforce
SETUP_TOOL = $(PS_EXEC) app\scripts\setup\setup-cli.ps1 -Tool $(tool)
CLEANUP_WORKATO = $(PS_EXEC) workato\scripts\cli\workato-cleanup.ps1
RUN_START_RECIPES = $(PS_EXEC) workato\scripts\cli\start_workato_recipes.ps1 -SkipFailed
RUN_START_STRICT = $(PS_EXEC) workato\scripts\cli\start_workato_recipes.ps1
RUN_STOP_RECIPES = $(PS_EXEC) workato\scripts\cli\stop_workato_recipes.ps1 -SkipFailed
RUN_STOP_STRICT = $(PS_EXEC) workato\scripts\cli\stop_workato_recipes.ps1
RUN_ENABLE_EP = $(PS_EXEC) workato\scripts\cli\enable_api_endpoints.ps1
RUN_WORKATO_INIT = $(PS_EXEC) workato\scripts\cli\create_workato_folders.ps1
RUN_SF_DEPLOY = $(PS_EXEC) vendor\salesforce\scripts\deploy.ps1 -TargetOrg
else
SETUP_WORKATO = bash app/scripts/setup/setup-cli.sh --tool=workato
SETUP_SALESFORCE = bash app/scripts/setup/setup-cli.sh --tool=salesforce
SETUP_TOOL = bash app/scripts/setup/setup-cli.sh --tool=$(tool)
CLEANUP_WORKATO = bash workato/scripts/cli/workato-cleanup.sh
RUN_START_RECIPES = bash workato/scripts/cli/start_workato_recipes.sh --skip-failed
RUN_START_STRICT = bash workato/scripts/cli/start_workato_recipes.sh
RUN_STOP_RECIPES = bash workato/scripts/cli/stop_workato_recipes.sh --skip-failed
RUN_STOP_STRICT = bash workato/scripts/cli/stop_workato_recipes.sh
RUN_ENABLE_EP = bash workato/scripts/cli/enable_api_endpoints.sh
RUN_WORKATO_INIT = bash workato/scripts/cli/create_workato_folders.sh
RUN_SF_DEPLOY = bash vendor/salesforce/scripts/deploy.sh
endif
# Default values for create-api-client
collection ?= sf-api-collection
client ?= SF API Client
description ?= API client for Salesforce search endpoints
# ============================================================
# Primary Commands (Unified, Multi-Tool)
# ============================================================
help:
@echo "Unified CLI Management"
@echo "======================"
@echo ""
@echo "Multi-Tool Commands:"
@echo " make setup [tool=<name>] - Install CLI(s). Options: workato, salesforce, all (default)"
@echo " make status [tool=<name>] - Check CLI status. Options: workato, salesforce, all (default)"
@echo " make clean [tool=<name>] - Remove CLI(s). Options: workato, salesforce, all (default)"
@echo ""
@echo "Workato-Specific Commands:"
@echo " make validate - Validate Workato recipes locally"
@echo " make push - Push Workato recipes to developer sandbox"
@echo " make pull - Pull Workato recipes from developer sandbox"
@echo " make start-recipes - Start all Workato recipes (skip failures, default)"
@echo " make start-recipes-stop-on-error - Start recipes (stop on first failure)"
@echo " make stop-recipes - Stop all Workato recipes (skip failures, default)"
@echo " make stop-recipes-stop-on-error - Stop recipes (stop on first failure)"
@echo " make enable-api-endpoints - Enable all API endpoints in all collections"
@echo " make create-api-client - Create API client for sf-api-collection (auto-updates .env)"
@echo ""
@echo "Salesforce-Specific Commands:"
@echo " make sf-deploy org=<alias> - Deploy Salesforce metadata to specified org"
@echo ""
@echo "Diagnostics:"
@echo " make doctor - Verify CLI wrappers and underlying binaries"
@echo ""
@echo "Backward-Compatible Aliases:"
@echo " make workato-setup - Same as: make setup tool=workato"
@echo " make workato-status - Same as: make status tool=workato"
@echo " make sf-setup - Same as: make setup tool=salesforce"
@echo " make sf-status - Same as: make status tool=salesforce"
@echo ""
@echo "Examples:"
@echo " make setup - Install all CLIs (workato + salesforce)"
@echo " make setup tool=workato - Install only Workato CLI"
@echo " make setup tool=salesforce - Install only Salesforce CLI"
@echo " make status - Check status of all CLIs"
@echo " make clean tool=salesforce - Remove only Salesforce CLI"
@echo ""
# ============================================================
# Setup Commands
# ============================================================
setup:
ifeq ($(tool),all)
@echo "Setting up all vendor CLIs..."
@$(SETUP_WORKATO)
@$(SETUP_SALESFORCE)
else
@echo "Setting up $(tool) CLI..."
@$(SETUP_TOOL)
endif
# ============================================================
# Status Commands
# ============================================================
status:
ifeq ($(tool),all)
@echo "Checking status of all vendor CLIs..."
@echo ""
-@$(MAKE) --no-print-directory status tool=workato
@echo ""
-@$(MAKE) --no-print-directory status tool=salesforce
else ifeq ($(tool),workato)
ifeq ($(HAS_WORKATO),)
@echo "❌ Workato CLI not installed. Run 'make setup tool=workato' first."
@exit 1
endif
@echo "Workato CLI Status"
@echo "------------------"
@$(WORKATO_CMD) --version
@echo ""
@echo "Testing connection to Workato..."
-@$(WORKATO_CMD) workspace || echo "⚠️ Not authenticated. Set your API key in .env"
else ifeq ($(tool),salesforce)
ifeq ($(HAS_SF),)
@echo "❌ Salesforce CLI not installed. Run 'make setup tool=salesforce' first."
@exit 1
endif
@echo "Salesforce CLI Status"
@echo "---------------------"
@$(SF_CMD) --version
@echo ""
@echo "Authenticated orgs:"
-@$(SF_CMD) org list || echo "⚠️ No orgs authenticated. Run: $(SF_CMD) org login web"
else
@echo "❌ Unknown tool: $(tool)"
@echo "Valid options: workato, salesforce, all"
@exit 1
endif
# ============================================================
# Clean Commands
# ============================================================
clean:
ifeq ($(tool),all)
@echo "Cleaning up all vendor CLIs..."
-@$(CLEANUP_WORKATO)
ifeq ($(PLATFORM),windows)
@powershell -NoProfile -Command "Remove-Item -Force -ErrorAction SilentlyContinue bin\workato*"
@powershell -NoProfile -Command "Remove-Item -Recurse -Force -ErrorAction SilentlyContinue tools\sf-cli"
@powershell -NoProfile -Command "Remove-Item -Force -ErrorAction SilentlyContinue bin\sf*"
else
@rm -f bin/workato
@rm -rf tools/sf-cli/
@rm -f bin/sf
endif
@echo "✓ Cleaned up all CLIs"
else ifeq ($(tool),workato)
@echo "Cleaning up Workato CLI..."
-@$(CLEANUP_WORKATO)
ifeq ($(PLATFORM),windows)
@powershell -NoProfile -Command "Remove-Item -Force -ErrorAction SilentlyContinue bin\workato*"
else
@rm -f bin/workato
endif
@echo "✓ Cleaned up Workato CLI"
else ifeq ($(tool),salesforce)
@echo "Cleaning up Salesforce CLI..."
ifeq ($(PLATFORM),windows)
@powershell -NoProfile -Command "Remove-Item -Recurse -Force -ErrorAction SilentlyContinue tools\sf-cli"
@powershell -NoProfile -Command "Remove-Item -Force -ErrorAction SilentlyContinue bin\sf*"
else
@rm -rf tools/sf-cli/
@rm -f bin/sf
endif
@echo "✓ Cleaned up Salesforce CLI"
else
@echo "❌ Unknown tool: $(tool)"
@echo "Valid options: workato, salesforce, all"
@exit 1
endif
# ============================================================
# Workato-Specific Commands
# ============================================================
# Load environment variables from .env if it exists
ifneq (,$(wildcard .env))
include .env
export
endif
validate:
ifeq ($(HAS_WORKATO),)
@echo "❌ Workato CLI not installed. Run 'make setup tool=workato' first."
@exit 1
endif
@echo "Validating recipes in workato/recipes/..."
ifeq ($(PLATFORM),windows)
@powershell -NoProfile -ExecutionPolicy Bypass -Command "$$files = Get-ChildItem -Path 'workato\recipes' -Filter '*.recipe.json' -Recurse | Select-Object -ExpandProperty FullName; if ($$files) { & $(WORKATO_CMD) recipe validate $$files } else { Write-Host 'No recipe files found.' }"
else
@$(WORKATO_CMD) recipe validate workato/recipes/**/*.recipe.json
endif
push:
ifeq ($(HAS_WORKATO),)
@echo "❌ Workato CLI not installed. Run 'make setup tool=workato' first."
@exit 1
endif
@echo "Pushing recipes to developer sandbox..."
ifeq ($(PLATFORM),windows)
@powershell -NoProfile -ExecutionPolicy Bypass -Command "\
$$workatoBin = '$(WORKATO_CMD)';\
if (-not (Get-Command $$workatoBin -ErrorAction SilentlyContinue)) {\
$$fallback = Join-Path '$(CURDIR)' 'bin\workato.cmd';\
if (Test-Path $$fallback) { $$workatoBin = $$fallback } else { Write-Error 'workato not found'; exit 1 }\
}\
Get-ChildItem -Directory 'projects\*' | ForEach-Object {\
$$folder = $$_.FullName;\
$$name = $$_.Name;\
Write-Host \"Pushing $$name...\";\
if ($$name -eq 'sf-api-collection') {\
Write-Host ' Phase 1: pushing api_group and recipes...';\
$$staging = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString());\
New-Item -ItemType Directory -Force -Path $$staging | Out-Null;\
Get-ChildItem -Path $$folder -Filter '*.api_endpoint.json' -ErrorAction SilentlyContinue | Move-Item -Destination $$staging;\
Push-Location $$folder; try { & $$workatoBin push } finally { Pop-Location };\
Write-Host ' Phase 2: pushing api_endpoints (with all dependencies)...';\
Get-ChildItem -Path $$staging -Filter '*.api_endpoint.json' -ErrorAction SilentlyContinue | Move-Item -Destination $$folder;\
Remove-Item -Path $$staging -Recurse -Force;\
Push-Location $$folder; try { & $$workatoBin push } finally { Pop-Location };\
} else {\
Push-Location $$folder; try { & $$workatoBin push } finally { Pop-Location };\
}\
}"
else
@WORKATO="$(WORKATO_CMD)"; \
for folder in projects/*/; do \
echo "Pushing $$folder..."; \
BASENAME=$$(basename "$$folder"); \
if [ "$$BASENAME" = "sf-api-collection" ]; then \
echo " Phase 1: pushing api_group and recipes..."; \
STAGING=$$(mktemp -d); \
mv "$$folder"/*.api_endpoint.json "$$STAGING"/ 2>/dev/null || true; \
(cd "$$folder" && "$$WORKATO" push); \
echo " Phase 2: pushing api_endpoints (with all dependencies)..."; \
mv "$$STAGING"/*.api_endpoint.json "$$folder"/ 2>/dev/null || true; \
rm -rf "$$STAGING"; \
(cd "$$folder" && "$$WORKATO" push); \
else \
(cd "$$folder" && "$$WORKATO" push); \
fi; \
done
endif
pull:
ifeq ($(HAS_WORKATO),)
@echo "❌ Workato CLI not installed. Run 'make setup tool=workato' first."
@exit 1
endif
@echo "Pulling recipes from developer sandbox to workato/sandbox/..."
@$(WORKATO_CMD) recipe pull --output workato/sandbox/
workato-init:
@echo "Initializing Workato projects..."
@$(RUN_WORKATO_INIT)
start-recipes:
@echo "Starting all Workato recipes (skipping failures)..."
@$(RUN_START_RECIPES)
start-recipes-stop-on-error:
@echo "Starting all Workato recipes (stop on first failure)..."
@$(RUN_START_STRICT)
stop-recipes:
@echo "Stopping all Workato recipes (skipping failures)..."
@$(RUN_STOP_RECIPES)
stop-recipes-stop-on-error:
@echo "Stopping all Workato recipes (stop on first failure)..."
@$(RUN_STOP_STRICT)
enable-api-endpoints:
@echo "Enabling all API endpoints..."
@$(RUN_ENABLE_EP)
create-api-client:
@echo "Creating API Platform client for sf-api-collection..."
ifeq ($(PLATFORM),windows)
@$(PS_EXEC) workato\scripts\cli\create_api_collection_client.ps1 -CollectionName "$(collection)" -ClientName "$(client)" -ClientDescription "$(description)"
else
@bash workato/scripts/cli/create_api_collection_client.sh \
--collection-name "$(collection)" \
--client-name "$(client)" \
--client-description "$(description)"
endif
# ============================================================
# Salesforce-Specific Commands
# ============================================================
sf-deploy:
ifndef org
@echo "❌ Error: org parameter required"
@echo "Usage: make sf-deploy org=myDevOrg"
@echo ""
@echo "Available orgs:"
-@$(SF_CMD) org list || echo "No orgs found. Run: $(SF_CMD) org login web"
@exit 1
endif
ifeq ($(HAS_SF),)
@echo "❌ Salesforce CLI not installed. Run 'make setup tool=salesforce' first."
@exit 1
endif
@echo "Deploying Salesforce metadata to $(org)..."
@$(RUN_SF_DEPLOY) $(org)
# ============================================================
# Diagnostics
# ============================================================
doctor:
@echo "Environment"
@echo "==========="
@echo " Platform: $(PLATFORM)"
@echo " CURDIR: $(CURDIR)"
@echo " WORKATO_CMD: $(WORKATO_CMD)"
@echo " SF_CMD: $(SF_CMD)"
@echo ""
@echo "Workato CLI"
@echo "==========="
ifeq ($(HAS_WORKATO),1)
@echo " Wrapper: $(WORKATO_CMD) ... found"
ifeq ($(PLATFORM),windows)
@powershell -NoProfile -Command "try { $$v = & $(WORKATO_CMD) --version 2>&1; Write-Host \" Binary: $$v ... OK\" } catch { Write-Host ' Binary: FAILED - wrapper exists but underlying binary is not functional'; Write-Host ' Run ''make setup tool=workato'' to reinstall' }"
else
@if $(WORKATO_CMD) --version >/dev/null 2>&1; then \
echo " Binary: $$($(WORKATO_CMD) --version 2>&1) ... OK"; \
else \
echo " Binary: FAILED — wrapper exists but underlying binary is not functional"; \
echo " Run 'make setup tool=workato' to reinstall"; \
fi
endif
else
@echo " Wrapper: $(WORKATO_CMD) ... NOT FOUND"
@echo " Run 'make setup tool=workato' to install"
endif
@echo ""
@echo "Salesforce CLI"
@echo "=============="
ifeq ($(HAS_SF),1)
@echo " Wrapper: $(SF_CMD) ... found"
ifeq ($(PLATFORM),windows)
@powershell -NoProfile -Command "try { $$v = (& $(SF_CMD) --version 2>&1) -split \"`n\" | Select-Object -First 1; Write-Host \" Binary: $$v ... OK\" } catch { Write-Host ' Binary: FAILED - wrapper exists but underlying binary is not functional'; Write-Host ' Run ''make setup tool=salesforce'' to reinstall' }"
else
@if $(SF_CMD) --version >/dev/null 2>&1; then \
echo " Binary: $$($(SF_CMD) --version 2>&1 | head -1) ... OK"; \
else \
echo " Binary: FAILED — wrapper exists but underlying binary is not functional"; \
echo " Run 'make setup tool=salesforce' to reinstall"; \
fi
endif
else
@echo " Wrapper: $(SF_CMD) ... NOT FOUND"
@echo " Run 'make setup tool=salesforce' to install"
endif
# ============================================================
# Backward-Compatible Aliases
# ============================================================
workato-setup:
@$(MAKE) setup tool=workato
workato-status:
@$(MAKE) status tool=workato
sf-setup:
@$(MAKE) setup tool=salesforce
sf-status:
@$(MAKE) status tool=salesforce