|
7 | 7 | workflow_call:
|
8 | 8 | inputs:
|
9 | 9 | runner:
|
10 |
| - required: false |
| 10 | + required: true |
11 | 11 | type: string
|
12 |
| - default: ubuntu-latest |
13 | 12 | target:
|
14 | 13 | description: >
|
15 | 14 | The environment to deploy to (e.g., `dev`, `qa`, `prod`).
|
|
32 | 31 | Example: `aks-prod-weu`
|
33 | 32 | required: false
|
34 | 33 | 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 |
36 | 42 | cd_repo:
|
37 | 43 | required: true
|
38 | 44 | type: string
|
|
43 | 49 | application:
|
44 | 50 | required: false
|
45 | 51 | 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" |
48 | 54 | required: false
|
49 | 55 | type: string
|
50 | 56 | image_tag:
|
|
65 | 71 | applicationDetails:
|
66 | 72 | description: >-
|
67 | 73 | 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 } |
69 | 75 | Example:
|
70 | 76 | [
|
71 | 77 | {"name":"app1","images":["repo/app1","repo/sidecar"],"path":"services/app1/overlays/prod"},
|
@@ -142,9 +148,10 @@ jobs:
|
142 | 148 | - name: Checkout repo
|
143 | 149 | uses: actions/checkout@v4
|
144 | 150 | with:
|
145 |
| - repository: ${{ inputs.repo }} |
| 151 | + repository: ${{ github.repository }} |
146 | 152 | 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 }} |
148 | 155 |
|
149 | 156 | - name: Ensure envsubst installed
|
150 | 157 | shell: bash
|
@@ -351,7 +358,7 @@ jobs:
|
351 | 358 | env:
|
352 | 359 | APP_DETAILS: ${{ inputs.applicationDetails }}
|
353 | 360 | APPLICATION: ${{ inputs.application }}
|
354 |
| - DEPLOY_PATH: ${{ inputs.deployFilesPath }} |
| 361 | + DEPLOY_PATH: ${{ inputs.deploy_path }} |
355 | 362 | IMG_ONE: ${{ inputs.image_base_name }}
|
356 | 363 | IMG_LIST: ${{ inputs.image_base_names }}
|
357 | 364 | with:
|
@@ -382,7 +389,7 @@ jobs:
|
382 | 389 | for (const s of process.env.IMG_LIST.split(',').map(x => x.trim()).filter(Boolean)) images.push(s);
|
383 | 390 | }
|
384 | 391 | 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; } |
386 | 393 | apps.push({ name, path, images });
|
387 | 394 | }
|
388 | 395 | core.setOutput('apps', JSON.stringify(apps));
|
@@ -587,6 +594,47 @@ jobs:
|
587 | 594 | core.setOutput('curl_ssl_flags', curlSslFlags);
|
588 | 595 | core.setOutput('token', finalToken);
|
589 | 596 |
|
| 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 | +
|
590 | 638 | - name: Check or create ArgoCD applications (per app)
|
591 | 639 | uses: actions/github-script@v7
|
592 | 640 | env:
|
|
0 commit comments