Skip to content

Commit e3fc44a

Browse files
committed
revert: install pgbadger from source
1 parent e450b47 commit e3fc44a

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

.github/workflows/custom.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
4444
- name: Run local GitHub Action
4545
uses: ./
46+
env:
47+
GITHUB_TOKEN: ${{ github.token }}
4648
with:
4749
github_token: ${{ secrets.GITHUB_TOKEN }}
4850
postgres_url: http://query_doctor@localhost:5432/testing

action.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: "Query Doctor"
77
inputs:
88
github_token:
99
description: "GitHub token"
10-
required: false
10+
required: true
1111
begin_date:
1212
description: "Begin date to start analyzing logs"
1313
required: false
@@ -33,7 +33,20 @@ runs:
3333
shell: bash
3434
run: |
3535
sudo apt-get update
36-
sudo apt-get install -y pgbadger
36+
sudo apt-get install -y perl make wget
37+
38+
# Download, build, and install pgBadger
39+
- name: Download and Install pgBadger
40+
shell: bash
41+
run: |
42+
PGBADGER_VERSION=13.1
43+
cd /tmp
44+
wget https://github.com/darold/pgbadger/archive/v${PGBADGER_VERSION}.tar.gz -O pgbadger.tar.gz
45+
tar -xzf pgbadger.tar.gz
46+
cd pgbadger-${PGBADGER_VERSION}
47+
perl Makefile.PL
48+
sudo make install # Use sudo to install globally
49+
cd ${{ github.action_path }} # Return to action directory
3750
3851
# Compile the Deno application into a single executable
3952
- name: Compile Analyzer

bootstrap.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ from
383383
"assets"."inserted_at" desc
384384
limit
385385
100
386-
) "userAssets"
386+
) "userAssets";
387387

388388
--
389389
-- PostgreSQL database dump complete

main.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ function formatQuery(query: string) {
2323
}
2424

2525
async function main() {
26-
console.log(process.env.GITHUB_WORKSPACE);
27-
// console.log([...Deno.readDirSync(process.env.GITHUB_WORKSPACE!)]);
2826
const logPath = process.env.LOG_PATH || core.getInput("log_path");
2927
const postgresUrl = process.env.POSTGRES_URL || core.getInput("postgres_url");
3028
console.log(logPath);
@@ -184,9 +182,7 @@ async function main() {
184182
}
185183
}
186184
}
187-
const reporter = new GithubReporter(
188-
core.getInput("github_token", { required: true })
189-
);
185+
const reporter = new GithubReporter(process.env.GITHUB_TOKEN);
190186
await reporter.report({ recommendations });
191187
console.timeEnd("total");
192188
await output.status;

optimizer/genalgo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class IndexOptimizer {
4141
console.log(
4242
`index definition already exists, skipping: ${existingIndex.index_name}`
4343
);
44-
iter = permutations.next(SKIP);
44+
iter = permutations.next(PROCEED);
4545
console.log("--------------------------------");
4646
continue;
4747
}

reporters/github.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dedent from "dedent";
44
export class GithubReporter {
55
private static readonly REVIEW_COMMENT_SUFFIX = "<!-- qd-review-comment -->";
66
prNumber?: number;
7-
constructor(private readonly githubToken: string) {
7+
constructor(private readonly githubToken?: string) {
88
this.prNumber = github.context.payload.pull_request?.number;
99
}
1010

@@ -13,6 +13,10 @@ export class GithubReporter {
1313
console.warn(`Not a PR, skipping report...`);
1414
return;
1515
}
16+
if (!this.githubToken) {
17+
console.warn(`No GitHub token provided, skipping report...`);
18+
return;
19+
}
1620
const octokit = github.getOctokit(this.githubToken);
1721
// check if a review from us already exists
1822
const reviews = await octokit.rest.pulls.listReviews({
@@ -32,10 +36,13 @@ export class GithubReporter {
3236
<details>
3337
<summary>Optimized query cost (${r.baseCost} -> ${
3438
r.optimizedCost
35-
}) by <b>${(((r.baseCost - r.optimizedCost) / r.baseCost) * 100).toFixed(
36-
2
37-
)}%</b></summary>
39+
}) by <strong>${(
40+
((r.baseCost - r.optimizedCost) / r.baseCost) *
41+
100
42+
).toFixed(2)}%</strong></summary>
43+
\`\`\`sql
3844
${r.formattedQuery}
45+
\`\`\`
3946
4047
Base cost: ${r.baseCost}
4148
Optimized cost: ${r.optimizedCost}
@@ -65,8 +72,7 @@ export class GithubReporter {
6572
`;
6673
} else {
6774
review = dedent`
68-
# Your queries are already optimized!
69-
We didn't find any queries that could be optimized. Keep up the good work!
75+
# Your queries are optimized!
7076
${GithubReporter.REVIEW_COMMENT_SUFFIX}
7177
`;
7278
}

0 commit comments

Comments
 (0)