Skip to content

Commit bb09ef2

Browse files
Update deploy.yaml
1 parent 11be72c commit bb09ef2

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

.github/workflows/deploy.yaml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,16 @@ jobs:
258258
echo "CD_ROOT=$CD_ROOT" >> "$GITHUB_ENV"
259259
echo "cd_root=$CD_ROOT" >> "$GITHUB_OUTPUT"
260260
261-
# Export UAMI env vars (uami_name => client_id) for selected cluster
261+
# Export UAMI env vars (uami_name => client_id)
262262
- name: Export UAMI env vars (uami_name => client_id)
263263
uses: actions/github-script@v7
264264
env:
265265
UAMI_JSON: ${{ steps.env.outputs.uami_map }}
266+
CLUSTER: ${{ steps.env.outputs.cluster }}
266267
with:
267268
script: |
268269
const fs = require('fs');
270+
const clusterName = (process.env.CLUSTER || '').trim();
269271
270272
let arr = [];
271273
try { arr = JSON.parse(process.env.UAMI_JSON || '[]'); }
@@ -276,20 +278,11 @@ jobs:
276278
return;
277279
}
278280
279-
const seenByName = new Set();
280-
const seenByVar = new Set();
281-
const exported = [];
282-
283-
const toShellId = (s) => {
284-
const orig = String(s).trim();
285-
let k = orig.replace(/[^A-Za-z0-9_]/g, '_');
286-
if (!/^[A-Za-z_]/.test(k)) k = `_${k}`;
287-
if (k !== orig) core.warning(`UAMI name '${orig}' adjusted to '${k}' for shell compatibility.`);
288-
return k;
289-
};
281+
const seen = new Set();
282+
const exported = [];
290283
291284
for (const [i, u] of arr.entries()) {
292-
const name = String(u.uami_name || '').trim();
285+
let name = String(u.uami_name || '').trim();
293286
const rg = String(u.uami_resource_group || '').trim();
294287
const cid = String(u.client_id || '').trim();
295288
@@ -298,24 +291,39 @@ jobs:
298291
continue;
299292
}
300293
301-
if (seenByName.has(name)) {
302-
core.warning(`Duplicate UAMI name '${name}' (rg='${rg}'). Keeping the first occurrence.`);
303-
continue;
294+
// Remove "<clusterName>-" prefix if present
295+
const prefix = clusterName + "-";
296+
if (name.toLowerCase().startsWith(prefix.toLowerCase())) {
297+
name = name.substring(prefix.length);
304298
}
305299
306-
const varName = toShellId(name);
307-
if (seenByVar.has(varName)) {
308-
core.warning(`UAMI name '${name}' maps to '${varName}', which collides with another UAMI. Keeping the first occurrence.`);
300+
// Replace '-' with '_'
301+
let varName = name.replace(/-/g, "_");
302+
303+
// Ensure valid shell identifier
304+
if (!/^[A-Za-z_]/.test(varName)) varName = `_${varName}`;
305+
306+
if (seen.has(varName)) {
307+
core.warning(`Duplicate UAMI var '${varName}' (rg='${rg}'). Skipping duplicate.`);
309308
continue;
310309
}
311310
312311
fs.appendFileSync(process.env.GITHUB_ENV, `${varName}=${cid}\n`);
313-
seenByName.add(name);
314-
seenByVar.add(varName);
315-
exported.push(varName);
312+
seen.add(varName);
313+
exported.push({ varName, cid });
316314
}
317315
318-
core.info(`Exported ${exported.length} UAMI env var(s): ${exported.join(', ')}`);
316+
if (exported.length === 0) {
317+
core.info("No UAMI vars exported.");
318+
} else {
319+
core.info("Exported UAMI vars for templating:");
320+
for (const e of exported) {
321+
core.info(` ${e.varName}=${e.cid}`);
322+
}
323+
}
324+
325+
326+
319327
320328
# Unify to a single apps[] list for either mode
321329
- name: Resolve apps (single or multi)

0 commit comments

Comments
 (0)