Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make https optional #40

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ author: 'Quizlet'
inputs:
argocd-server-url:
description: ArgoCD server url (without the protocol)
required: true
default: argo-cd-argocd-server.argo-cd
required: false
argocd-token:
description: ArgoCD token for a local or project-scoped user https://argoproj.github.io/argo-cd/operator-manual/user-management/#local-usersaccounts-v15
required: true
Expand All @@ -19,6 +20,14 @@ inputs:
description: Extra arguments to pass to the argocd CLI
default: --grpc-web
required: false
plaintext:
description: Whether to use HTTPS
default: 'false'
required: false
environment:
description: Name of env to use in the diff title posted to the PR
default: legacy
required: false
runs:
using: 'node12'
main: 'dist/index.js'
Binary file added bin/argo
Binary file not shown.
37 changes: 16 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,12 @@ core.info(githubToken);
const ARGOCD_SERVER_URL = core.getInput('argocd-server-url');
const ARGOCD_TOKEN = core.getInput('argocd-token');
const VERSION = core.getInput('argocd-version');
const EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args');
const ENV = core.getInput('environment');
const PLAINTEXT = core.getInput('plaintext').toLowerCase() === "true";
let EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args');
if (PLAINTEXT) {
EXTRA_CLI_ARGS += ' --plaintext';
}
const octokit = github.getOctokit(githubToken);
function execCommand(command, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -1739,7 +1744,11 @@ function setupArgoCDCommand() {
}
function getApps() {
return __awaiter(this, void 0, void 0, function* () {
const url = `https://${ARGOCD_SERVER_URL}/api/v1/applications?fields=items.metadata.name,items.spec.source.path,items.spec.source.repoURL,items.spec.source.targetRevision,items.spec.source.helm,items.spec.source.kustomize,items.status.sync.status`;
let protocol = 'https';
if (PLAINTEXT) {
protocol = 'http';
}
const url = `${protocol}://${ARGOCD_SERVER_URL}/api/v1/applications`;
core.info(`Fetching apps from: ${url}`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let responseJson;
Expand All @@ -1754,7 +1763,8 @@ function getApps() {
core.error(e);
}
return responseJson.items.filter(app => {
return (app.spec.source.repoURL.includes(`${github.context.repo.owner}/${github.context.repo.repo}`) && (app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main'));
const targetPrimary = app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main';
return (app.spec.source.repoURL.includes(`${github.context.repo.owner}/${github.context.repo.repo}`) && targetPrimary);
});
});
}
Expand Down Expand Up @@ -1797,7 +1807,7 @@ ${diff}
---
`);
const output = scrubSecrets(`
## ArgoCD Diff for commit [\`${shortCommitSha}\`](${commitLink})
## ArgoCD Diff on ${ENV} for commit [\`${shortCommitSha}\`](${commitLink})
_Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angeles' })} PT_
${diffOutput.join('\n')}

Expand All @@ -1807,23 +1817,8 @@ _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angele
| ⚠️ | The app is out-of-sync in ArgoCD, and the diffs you see include those changes plus any from this PR. |
| 🛑 | There was an error generating the ArgoCD diffs due to changes in this PR. |
`);
const commentsResponse = yield octokit.rest.issues.listComments({
issue_number: github.context.issue.number,
owner,
repo
});
const existingComment = commentsResponse.data.find(d => d.body.includes('ArgoCD Diff for'));
// Existing comments should be updated even if there are no changes this round in order to indicate that
if (existingComment) {
octokit.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: output
});
// Only post a new comment when there are changes
}
else if (diffs.length) {
// Only post a new comment when there are changes
if (diffs.length) {
octokit.rest.issues.createComment({
issue_number: github.context.issue.number,
owner,
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 24 additions & 30 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ core.info(githubToken);
const ARGOCD_SERVER_URL = core.getInput('argocd-server-url');
const ARGOCD_TOKEN = core.getInput('argocd-token');
const VERSION = core.getInput('argocd-version');
const EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args');
const ENV = core.getInput('environment');
const PLAINTEXT = core.getInput('plaintext').toLowerCase() === "true";
let EXTRA_CLI_ARGS = core.getInput('argocd-extra-cli-args');
if (PLAINTEXT) {
EXTRA_CLI_ARGS += ' --plaintext';
}

const octokit = github.getOctokit(githubToken);

Expand Down Expand Up @@ -84,7 +89,11 @@ async function setupArgoCDCommand(): Promise<(params: string) => Promise<ExecRes
}

async function getApps(): Promise<App[]> {
const url = `https://${ARGOCD_SERVER_URL}/api/v1/applications?fields=items.metadata.name,items.spec.source.path,items.spec.source.repoURL,items.spec.source.targetRevision,items.spec.source.helm,items.spec.source.kustomize,items.status.sync.status`;
let protocol = 'https';
if (PLAINTEXT) {
protocol = 'http';
}
const url = `${protocol}://${ARGOCD_SERVER_URL}/api/v1/applications`;
core.info(`Fetching apps from: ${url}`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let responseJson: any;
Expand All @@ -99,10 +108,11 @@ async function getApps(): Promise<App[]> {
}

return (responseJson.items as App[]).filter(app => {
const targetPrimary = app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main'
return (
app.spec.source.repoURL.includes(
`${github.context.repo.owner}/${github.context.repo.repo}`
) && (app.spec.source.targetRevision === 'master' || app.spec.source.targetRevision === 'main')
) && targetPrimary
);
});
}
Expand All @@ -125,8 +135,8 @@ App: [\`${app.metadata.name}\`](https://${ARGOCD_SERVER_URL}/applications/${app.
YAML generation: ${error ? ' Error 🛑' : 'Success 🟢'}
App sync status: ${app.status.sync.status === 'Synced' ? 'Synced ✅' : 'Out of Sync ⚠️ '}
${
error
? `
error
? `
**\`stderr:\`**
\`\`\`
${error.stderr}
Expand All @@ -137,12 +147,12 @@ ${error.stderr}
${JSON.stringify(error.err)}
\`\`\`
`
: ''
}
: ''
}

${
diff
? `
diff
? `
<details>

\`\`\`diff
Expand All @@ -151,14 +161,14 @@ ${diff}

</details>
`
: ''
}
: ''
}
---
`
);

const output = scrubSecrets(`
## ArgoCD Diff for commit [\`${shortCommitSha}\`](${commitLink})
## ArgoCD Diff on ${ENV} for commit [\`${shortCommitSha}\`](${commitLink})
_Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angeles' })} PT_
${diffOutput.join('\n')}

Expand All @@ -169,24 +179,8 @@ _Updated at ${new Date().toLocaleString('en-US', { timeZone: 'America/Los_Angele
| 🛑 | There was an error generating the ArgoCD diffs due to changes in this PR. |
`);

const commentsResponse = await octokit.rest.issues.listComments({
issue_number: github.context.issue.number,
owner,
repo
});

const existingComment = commentsResponse.data.find(d => d.body!.includes('ArgoCD Diff for'));

// Existing comments should be updated even if there are no changes this round in order to indicate that
if (existingComment) {
octokit.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: output
});
// Only post a new comment when there are changes
} else if (diffs.length) {
// Only post a new comment when there are changes
if (diffs.length) {
octokit.rest.issues.createComment({
issue_number: github.context.issue.number,
owner,
Expand Down
Loading