Skip to content

Commit 91cd5de

Browse files
Update deploy.yaml
1 parent 2c10746 commit 91cd5de

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

.github/workflows/deploy.yaml

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ on:
77
workflow_call:
88
inputs:
99
runner:
10-
required: false
10+
required: true
1111
type: string
12-
default: ubuntu-latest
1312
target:
1413
description: >
1514
The environment to deploy to (e.g., `dev`, `qa`, `prod`).
@@ -32,7 +31,14 @@ on:
3231
Example: `aks-prod-weu`
3332
required: false
3433
default: ""
35-
34+
ref:
35+
description: "The github ref to use for checking out files"
36+
required: false
37+
type: string
38+
delete_first:
39+
description: "Delete the namespaced app first before deploying it."
40+
required: false
41+
type: boolean
3642
cd_repo:
3743
required: true
3844
type: string
@@ -43,8 +49,8 @@ on:
4349
application:
4450
required: false
4551
type: string
46-
deployFilesPath:
47-
description: "The repo path to the deployment files (if not using an artifact)"
52+
deploy_path:
53+
description: "The repo path to the deployment files"
4854
required: false
4955
type: string
5056
image_tag:
@@ -65,7 +71,7 @@ on:
6571
applicationDetails:
6672
description: >-
6773
JSON array where each item maps:
68-
{ "name" => application, "images" => image_base_names[], "path" => deployFilesPath }
74+
{ "name" => application, "images" => image_base_names[], "path" => deploy_path }
6975
Example:
7076
[
7177
{"name":"app1","images":["repo/app1","repo/sidecar"],"path":"services/app1/overlays/prod"},
@@ -142,9 +148,10 @@ jobs:
142148
- name: Checkout repo
143149
uses: actions/checkout@v4
144150
with:
145-
repository: ${{ inputs.repo }}
151+
repository: ${{ github.repository }}
146152
path: source
147-
ref: ${{ inputs.repo_commit_id != '' && inputs.repo_commit_id || inputs.branch_name }}
153+
ref: ${{ inputs.ref }}
154+
sparce-checkout: ${{ inputs.deploy_path }}
148155

149156
- name: Ensure envsubst installed
150157
shell: bash
@@ -351,7 +358,7 @@ jobs:
351358
env:
352359
APP_DETAILS: ${{ inputs.applicationDetails }}
353360
APPLICATION: ${{ inputs.application }}
354-
DEPLOY_PATH: ${{ inputs.deployFilesPath }}
361+
DEPLOY_PATH: ${{ inputs.deploy_path }}
355362
IMG_ONE: ${{ inputs.image_base_name }}
356363
IMG_LIST: ${{ inputs.image_base_names }}
357364
with:
@@ -382,7 +389,7 @@ jobs:
382389
for (const s of process.env.IMG_LIST.split(',').map(x => x.trim()).filter(Boolean)) images.push(s);
383390
}
384391
if (!name) { core.setFailed('❌ application is required when applicationDetails is not provided'); return; }
385-
if (!path) { core.setFailed('❌ deployFilesPath is required when applicationDetails is not provided'); return; }
392+
if (!path) { core.setFailed('❌ deploy_path is required when applicationDetails is not provided'); return; }
386393
apps.push({ name, path, images });
387394
}
388395
core.setOutput('apps', JSON.stringify(apps));
@@ -587,6 +594,47 @@ jobs:
587594
core.setOutput('curl_ssl_flags', curlSslFlags);
588595
core.setOutput('token', finalToken);
589596
597+
598+
- name: Delete ArgoCD apps first (per app)
599+
if: ${{ inputs.delete_first }}
600+
uses: actions/github-script@v7
601+
env:
602+
APPS: ${{ steps.apps.outputs.apps }}
603+
ARGOCD_URL: ${{ steps.argocd_conn.outputs.argocd_url }}
604+
ARGOCD_TOKEN: ${{ steps.argocd_conn.outputs.token }}
605+
CURL_SSL_FLAGS: ${{ steps.argocd_conn.outputs.curl_ssl_flags }}
606+
NAMESPACE: ${{ inputs.namespace }}
607+
with:
608+
script: |
609+
const { execSync } = require('child_process');
610+
const apps = JSON.parse(process.env.APPS || '[]');
611+
612+
for (const app of apps) {
613+
const appName = `${process.env.NAMESPACE}-${app.name}`;
614+
const deleteUrl = `${process.env.ARGOCD_URL}/api/v1/applications/${appName}`;
615+
616+
try {
617+
const http = execSync(
618+
`bash -lc 'curl ${process.env.CURL_SSL_FLAGS} -s -o /dev/null -w "%{http_code}" -X DELETE "${deleteUrl}" -H "Authorization: Bearer ${process.env.ARGOCD_TOKEN}"'`,
619+
{ encoding: 'utf8' }
620+
).trim();
621+
622+
if (http === '200') {
623+
core.info(`🗑️ Deleted Argo app ${appName}`);
624+
} else if (http === '404') {
625+
core.info(`ℹ️ Argo app ${appName} not found, skipping delete.`);
626+
} else {
627+
core.warning(`⚠️ Unexpected response deleting ${appName}: HTTP ${http}`);
628+
}
629+
} catch (err) {
630+
core.setFailed(`❌ Failed to run delete for ${appName}: ${err.message}`);
631+
return;
632+
}
633+
}
634+
635+
636+
637+
590638
- name: Check or create ArgoCD applications (per app)
591639
uses: actions/github-script@v7
592640
env:

0 commit comments

Comments
 (0)