From 61325cf2b18142db187dfd75875c34bf130670ca Mon Sep 17 00:00:00 2001 From: Aaron Weisberg Date: Fri, 19 Jul 2024 12:12:46 -0700 Subject: [PATCH 1/6] adds --server-side-generate --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 37b9cb0..d30dc4a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1864,7 +1864,7 @@ function run() { core.info(`Found apps: ${apps.map(a => a.metadata.name).join(', ')}`); const diffs = []; yield asyncForEach(apps, (app) => __awaiter(this, void 0, void 0, function* () { - const command = `app diff ${app.metadata.name} --local=${app.spec.source.path}`; + const command = `app diff ${app.metadata.name} --local=./ --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, diff --git a/src/main.ts b/src/main.ts index 3d5f7a1..7e3637d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -232,7 +232,7 @@ async function run(): Promise { const diffs: Diff[] = []; await asyncForEach(apps, async app => { - const command = `app diff ${app.metadata.name} --local=${app.spec.source.path}`; + const command = `app diff ${app.metadata.name} --local=./ --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, From e361dd12c505b6b7904cdc6b51fdb54d71fe36ca Mon Sep 17 00:00:00 2001 From: Aaron Weisberg Date: Fri, 19 Jul 2024 12:17:08 -0700 Subject: [PATCH 2/6] use absolute path --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index d30dc4a..4528717 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1864,7 +1864,7 @@ function run() { core.info(`Found apps: ${apps.map(a => a.metadata.name).join(', ')}`); const diffs = []; yield asyncForEach(apps, (app) => __awaiter(this, void 0, void 0, function* () { - const command = `app diff ${app.metadata.name} --local=./ --server-side-generate`; + const command = `app diff ${app.metadata.name} --local=/ --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, diff --git a/src/main.ts b/src/main.ts index 7e3637d..88e6820 100644 --- a/src/main.ts +++ b/src/main.ts @@ -232,7 +232,7 @@ async function run(): Promise { const diffs: Diff[] = []; await asyncForEach(apps, async app => { - const command = `app diff ${app.metadata.name} --local=./ --server-side-generate`; + const command = `app diff ${app.metadata.name} --local=/ --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, From b8924b1d29dec5e6e7b3e6e733c6be20c6cac20c Mon Sep 17 00:00:00 2001 From: Aaron Weisberg Date: Fri, 19 Jul 2024 12:23:21 -0700 Subject: [PATCH 3/6] use cwd --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 88e6820..f9a40f0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -232,7 +232,7 @@ async function run(): Promise { const diffs: Diff[] = []; await asyncForEach(apps, async app => { - const command = `app diff ${app.metadata.name} --local=/ --server-side-generate`; + const command = `app diff ${app.metadata.name} --local=${process.cwd()} --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, From 1b9a98b1ac3576ad92a43e0d339421ebab7c0fef Mon Sep 17 00:00:00 2001 From: Aaron Weisberg Date: Fri, 19 Jul 2024 12:23:38 -0700 Subject: [PATCH 4/6] use cwd --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 4528717..d6f65cc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1864,7 +1864,7 @@ function run() { core.info(`Found apps: ${apps.map(a => a.metadata.name).join(', ')}`); const diffs = []; yield asyncForEach(apps, (app) => __awaiter(this, void 0, void 0, function* () { - const command = `app diff ${app.metadata.name} --local=/ --server-side-generate`; + const command = `app diff ${app.metadata.name} --local=${process.cwd()} --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, From 3a7d973423e88e501c7375b16f5028c2a92fc800 Mon Sep 17 00:00:00 2001 From: Aaron Weisberg Date: Fri, 19 Jul 2024 12:28:41 -0700 Subject: [PATCH 5/6] remove --local --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index d6f65cc..15d5b57 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1864,7 +1864,7 @@ function run() { core.info(`Found apps: ${apps.map(a => a.metadata.name).join(', ')}`); const diffs = []; yield asyncForEach(apps, (app) => __awaiter(this, void 0, void 0, function* () { - const command = `app diff ${app.metadata.name} --local=${process.cwd()} --server-side-generate`; + const command = `app diff ${app.metadata.name} --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, diff --git a/src/main.ts b/src/main.ts index f9a40f0..4452ae0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -232,7 +232,7 @@ async function run(): Promise { const diffs: Diff[] = []; await asyncForEach(apps, async app => { - const command = `app diff ${app.metadata.name} --local=${process.cwd()} --server-side-generate`; + const command = `app diff ${app.metadata.name} --server-side-generate`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, From 85fddba088847407b27e8b84ad4b5c0103ee0eea Mon Sep 17 00:00:00 2001 From: Aaron Weisberg Date: Fri, 19 Jul 2024 12:57:22 -0700 Subject: [PATCH 6/6] use --revision --- dist/index.js | 6 +++--- src/main.ts | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index 15d5b57..762136e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1698,7 +1698,7 @@ const ARGOCD_SERVER_URL = core.getInput('argocd-server-url'); const ARGOCD_TOKEN = core.getInput('argocd-token'); const VERSION = core.getInput('argocd-version'); const ENV = core.getInput('environment'); -const PLAINTEXT = core.getInput('plaintext').toLowerCase() === "true"; +const PLAINTEXT = core.getInput('plaintext').toLowerCase() === 'true'; let EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args'); if (PLAINTEXT) { EXTRA_CLI_ARGS += ' --plaintext'; @@ -1835,7 +1835,7 @@ _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angele octokit.rest.issues.deleteComment({ owner, repo, - comment_id: comment.id, + comment_id: comment.id }); } } @@ -1864,7 +1864,7 @@ function run() { core.info(`Found apps: ${apps.map(a => a.metadata.name).join(', ')}`); const diffs = []; yield asyncForEach(apps, (app) => __awaiter(this, void 0, void 0, function* () { - const command = `app diff ${app.metadata.name} --server-side-generate`; + const command = `app diff ${app.metadata.name} --server-side-generate --revision ${github.context.sha}`; try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch, diff --git a/src/main.ts b/src/main.ts index 4452ae0..0c55b61 100644 --- a/src/main.ts +++ b/src/main.ts @@ -37,7 +37,7 @@ const ARGOCD_SERVER_URL = core.getInput('argocd-server-url'); const ARGOCD_TOKEN = core.getInput('argocd-token'); const VERSION = core.getInput('argocd-version'); const ENV = core.getInput('environment'); -const PLAINTEXT = core.getInput('plaintext').toLowerCase() === "true"; +const PLAINTEXT = core.getInput('plaintext').toLowerCase() === 'true'; let EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args'); if (PLAINTEXT) { EXTRA_CLI_ARGS += ' --plaintext'; @@ -108,8 +108,9 @@ async function getApps(): Promise { } return (responseJson.items as App[]).filter(app => { - const targetRevision = app.spec.source.targetRevision - const targetPrimary = targetRevision === 'master' || targetRevision === 'main' || !targetRevision + const targetRevision = app.spec.source.targetRevision; + const targetPrimary = + targetRevision === 'master' || targetRevision === 'main' || !targetRevision; return ( app.spec.source.repoURL.includes( `${github.context.repo.owner}/${github.context.repo.repo}` @@ -135,10 +136,12 @@ async function postDiffComment(diffs: Diff[]): Promise { const commitLink = `https://github.com/${owner}/${repo}/pull/${github.context.issue.number}/commits/${sha}`; const shortCommitSha = String(sha).substr(0, 7); - const prefixHeader = `## ArgoCD Diff on ${ENV}` + const prefixHeader = `## ArgoCD Diff on ${ENV}`; const diffOutput = diffs.map( ({ app, diff, error }) => ` -App: [\`${app.metadata.name}\`](${protocol}://${ARGOCD_SERVER_URL}/applications/${app.metadata.name}) +App: [\`${app.metadata.name}\`](${protocol}://${ARGOCD_SERVER_URL}/applications/${ + app.metadata.name + }) YAML generation: ${error ? ' Error 🛑' : 'Success 🟢'} App sync status: ${app.status.sync.status === 'Synced' ? 'Synced ✅' : 'Out of Sync ⚠️ '} ${ @@ -195,11 +198,11 @@ _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angele // Delete stale comments for (const comment of commentsResponse.data) { if (comment.body?.includes(prefixHeader)) { - core.info(`deleting comment ${comment.id}`) + core.info(`deleting comment ${comment.id}`); octokit.rest.issues.deleteComment({ owner, repo, - comment_id: comment.id, + comment_id: comment.id }); } } @@ -232,7 +235,7 @@ async function run(): Promise { const diffs: Diff[] = []; await asyncForEach(apps, async app => { - const command = `app diff ${app.metadata.name} --server-side-generate`; + const command = `app diff ${app.metadata.name} --server-side-generate --revision ${github.context.sha}` try { core.info(`Running: argocd ${command}`); // ArgoCD app diff will exit 1 if there is a diff, so always catch,