This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split logic out, so one can run it with Github Actions (which doesn't…
… accept CLI arguments) or as a CLI program (which accepts arguments) with node dist/cli.js <filename>
- Loading branch information
1 parent
5aad79a
commit 9ae1282
Showing
5 changed files
with
117 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { validateValidatedTokensCsv } from "./logic"; | ||
import minimist from "minimist"; | ||
// CLI entrypoint which accepts an argument | ||
(async () => { | ||
try { | ||
const argv = minimist(process.argv.slice(2)); | ||
await validateValidatedTokensCsv(argv._[0]); | ||
} | ||
catch (error: any) { | ||
console.log(error.message) | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import * as core from "@actions/core"; | ||
import { exec } from "@actions/exec"; | ||
import { canOnlyAddOneToken, detectDuplicateSymbol, detectDuplicateMints as detectDuplicateMints, validMintAddress, noEditsToPreviousLinesAllowed } from "./utils/validate"; | ||
import { ValidatedTokensData } from "./types/types"; | ||
import { indexToLineNumber } from "./utils/validate"; | ||
import { parse } from "csv-parse/sync"; | ||
import fs from "fs"; | ||
|
||
export async function validateValidatedTokensCsv(filename: string) { | ||
const [records, recordsRaw] = parseCsv(filename); | ||
|
||
const recordsPreviousRaw = await gitPreviousVersion("validated-tokens.csv"); | ||
fs.writeFileSync(".validated-tokens-0.csv", recordsPreviousRaw); | ||
const [recordsPrevious, _] = parseCsv(".validated-tokens-0.csv") | ||
|
||
let duplicateSymbols; | ||
let duplicateMints; | ||
let attemptsToAddMultipleTokens; | ||
let invalidMintAddresses; | ||
let notCommunityValidated; | ||
let noEditsAllowed; | ||
|
||
duplicateSymbols = detectDuplicateSymbol(recordsPrevious, records); | ||
duplicateMints = detectDuplicateMints(records); | ||
attemptsToAddMultipleTokens = canOnlyAddOneToken(recordsPrevious, records) | ||
invalidMintAddresses = validMintAddress(records); | ||
noEditsAllowed = noEditsToPreviousLinesAllowed(recordsPrevious, records); | ||
// notCommunityValidated = validCommunityValidated(records); | ||
|
||
console.log("No More Duplicate Symbols:", duplicateSymbols); | ||
console.log("Duplicate Mints:", duplicateMints); | ||
console.log("Attempts to Add Multiple Tokens:", attemptsToAddMultipleTokens); | ||
console.log("Invalid Mint Addresses:", invalidMintAddresses); | ||
console.log("Not Community Validated:", notCommunityValidated); | ||
console.log("Edits to Existing Tokens:", noEditsAllowed); | ||
} | ||
|
||
// Get previous version of validated-tokens.csv from last commit | ||
async function gitPreviousVersion(path: string): Promise<any> { | ||
let prevVersion = ""; | ||
let gitCmdError = ""; | ||
|
||
try { | ||
await exec("git", ["show", `origin/main:${path}`], { | ||
listeners: { | ||
stdout: (data: Buffer) => { | ||
prevVersion += data.toString(); | ||
}, | ||
stderr: (data: Buffer) => { | ||
gitCmdError += data.toString(); | ||
}, | ||
}, | ||
silent: true | ||
}); | ||
} catch (error: any) { | ||
core.setFailed(error.message); | ||
} | ||
|
||
if (gitCmdError) { | ||
core.setFailed(gitCmdError); | ||
} | ||
return prevVersion; | ||
} | ||
|
||
function parseCsv(filename: string): [ValidatedTokensData[], string] { | ||
const recordsRaw = fs.readFileSync(filename, "utf8") | ||
const r = parse(recordsRaw, { | ||
columns: true, | ||
skip_empty_lines: true, | ||
}); | ||
const records = csvToRecords(r); | ||
return [records, recordsRaw]; | ||
} | ||
|
||
function csvToRecords(r: any): ValidatedTokensData[] { | ||
const records: ValidatedTokensData[] = []; | ||
r.forEach((record: any, i: number) => { | ||
const rec: ValidatedTokensData = { | ||
Name: record.Name, | ||
Symbol: record.Symbol, | ||
Mint: record.Mint, | ||
Decimals: record.Decimals, | ||
LogoURI: record.LogoURI, | ||
"Community Validated": JSON.parse(record["Community Validated"]), | ||
Line: indexToLineNumber(i) | ||
}; | ||
records.push(rec); | ||
}); | ||
return records; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,12 @@ | ||
import * as core from "@actions/core"; | ||
import { exec } from "@actions/exec"; | ||
import { canOnlyAddOneToken, detectDuplicateSymbol, detectDuplicateMints as detectDuplicateMints, validMintAddress, noEditsToPreviousLinesAllowed } from "./utils/validate"; | ||
import { ValidatedTokensData } from "./types/types"; | ||
import { indexToLineNumber } from "./utils/validate"; | ||
import { parse } from "csv-parse/sync"; | ||
import fs from "fs"; | ||
|
||
import { validateValidatedTokensCsv } from "./logic"; | ||
// Github Actions entrypoint | ||
(async () => { | ||
try { | ||
await validateValidatedTokensCsv(); | ||
await validateValidatedTokensCsv("validated-tokens.csv"); | ||
} | ||
catch (error: any) { | ||
core.setFailed(error.message); | ||
console.log(error.message) | ||
} | ||
})(); | ||
|
||
async function validateValidatedTokensCsv() { | ||
const [records, recordsRaw] = parseCsv("validated-tokens.csv"); | ||
|
||
const recordsPreviousRaw = await gitPreviousVersion("validated-tokens.csv"); | ||
fs.writeFileSync(".validated-tokens-0.csv", recordsPreviousRaw); | ||
const [recordsPrevious, _] = parseCsv(".validated-tokens-0.csv") | ||
|
||
let duplicateSymbols; | ||
let duplicateMints; | ||
let attemptsToAddMultipleTokens; | ||
let invalidMintAddresses; | ||
let notCommunityValidated; | ||
let noEditsAllowed; | ||
|
||
duplicateSymbols = detectDuplicateSymbol(recordsPrevious, records); | ||
duplicateMints = detectDuplicateMints(records); | ||
attemptsToAddMultipleTokens = canOnlyAddOneToken(recordsPrevious, records) | ||
invalidMintAddresses = validMintAddress(records); | ||
noEditsAllowed = noEditsToPreviousLinesAllowed(recordsPrevious, records); | ||
// notCommunityValidated = validCommunityValidated(records); | ||
|
||
console.log("No More Duplicate Symbols:", duplicateSymbols); | ||
console.log("Duplicate Mints:", duplicateMints); | ||
console.log("Attempts to Add Multiple Tokens:", attemptsToAddMultipleTokens); | ||
console.log("Invalid Mint Addresses:", invalidMintAddresses); | ||
console.log("Not Community Validated:", notCommunityValidated); | ||
console.log("Edits to Existing Tokens:", noEditsAllowed); | ||
} | ||
|
||
// Get previous version of validated-tokens.csv from last commit | ||
async function gitPreviousVersion(path: string): Promise<any> { | ||
let prevVersion = ""; | ||
let gitCmdError = ""; | ||
|
||
try { | ||
await exec("git", ["show", `origin/main:${path}`], { | ||
listeners: { | ||
stdout: (data: Buffer) => { | ||
prevVersion += data.toString(); | ||
}, | ||
stderr: (data: Buffer) => { | ||
gitCmdError += data.toString(); | ||
}, | ||
}, | ||
silent: true | ||
}); | ||
} catch (error: any) { | ||
core.setFailed(error.message); | ||
} | ||
|
||
if (gitCmdError) { | ||
core.setFailed(gitCmdError); | ||
} | ||
return prevVersion; | ||
} | ||
|
||
function parseCsv(filename: string): [ValidatedTokensData[], string] { | ||
const recordsRaw = fs.readFileSync(filename, "utf8") | ||
const r = parse(recordsRaw, { | ||
columns: true, | ||
skip_empty_lines: true, | ||
}); | ||
const records = csvToRecords(r); | ||
return [records, recordsRaw]; | ||
} | ||
|
||
function csvToRecords(r: any): ValidatedTokensData[] { | ||
const records: ValidatedTokensData[] = []; | ||
r.forEach((record: any, i: number) => { | ||
const rec: ValidatedTokensData = { | ||
Name: record.Name, | ||
Symbol: record.Symbol, | ||
Mint: record.Mint, | ||
Decimals: record.Decimals, | ||
LogoURI: record.LogoURI, | ||
"Community Validated": JSON.parse(record["Community Validated"]), | ||
Line: indexToLineNumber(i) | ||
}; | ||
records.push(rec); | ||
}); | ||
return records; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters