-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* appky patch * change url for testing * update url * setup action * setup actions for testing * Testing (#28) * appky patch * change url for testing * update url * setup action * setup actions for testing * update action * simulate new plugin * Testing (#29) * appky patch * change url for testing * update url * setup action * setup actions for testing * simulate new plugin * update details test * Testing (#30) * appky patch * change url for testing * update url * setup action * setup actions for testing * simulate new plugin * update details test * add to existing package test * Testing (#31) * appky patch * change url for testing * update url * setup action * setup actions for testing * simulate new plugin * update details test * add to existing package test * non-config changes test * Testing (#32) * appky patch * change url for testing * update url * setup action * setup actions for testing * simulate new plugin * update details test * add to existing package test * non-config changes test * fail test * image too big * invalid image url * invalid appling * add plugin without config * add valid details * log * re-add details * valid details * Fail Testing (#33) * appky patch * change url for testing * update url * setup action * setup actions for testing * simulate new plugin * update details test * add to existing package test * non-config changes test * fail test * image too big * invalid image url * invalid appling * add plugin without config * add valid details * log * re-add details * valid details * invalid to new * last test * fix details * Testing (#34) * appky patch * change url for testing * update url * setup action * setup actions for testing * simulate new plugin * update details test * add to existing package test * non-config changes test * fail test * image too big * invalid image url * invalid appling * add plugin without config * add valid details * log * re-add details * valid details * invalid to new * last test * fix details * update icon * Mmackz/plugin details config (#36) * feat: add plugin details to db on pr * refactor(builder): use required params for mint/burn * refactor: use different logic for fetching updated config files * refactor: change name of action * fix: fetch origin * docs: add comments * feat: allow for multiple tasks * tasks
- Loading branch information
Showing
33 changed files
with
897 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@rabbitholegg/create-plugin": minor | ||
--- | ||
|
||
create plugin details config file |
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 @@ | ||
const _axios = require("axios"); | ||
const _fs = require("fs/promises"); | ||
const _yaml = require("js-yaml"); | ||
const _utils = require("./utils"); | ||
|
||
async function sendPluginDetailsToAPI(detailsPath: string): Promise<void> { | ||
const fileContents = await _fs.readFile(detailsPath, "utf8"); | ||
const details = _yaml.load(fileContents); | ||
const { project, tasks } = details; | ||
|
||
// send project details to staging API | ||
const { data: stagingData } = await _axios.post( | ||
`${process.env.STAGING_API_URL}/plugins/add-project`, | ||
{ | ||
...project, | ||
approvedForTerminal: true, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${process.env.BOOST_API_TOKEN}`, | ||
}, | ||
}, | ||
); | ||
|
||
// send project details to production API | ||
const { data } = await _axios.post( | ||
`${process.env.PRODUCTION_API_URL}/plugins/add-project`, | ||
project, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${process.env.BOOST_API_TOKEN}`, | ||
}, | ||
}, | ||
); | ||
|
||
for (const task of tasks) { | ||
// send task details to staging API | ||
await _axios.post( | ||
`${process.env.STAGING_API_URL}/plugins/add-task`, | ||
{ | ||
...task, | ||
projectId: stagingData.projectId, | ||
approvedForTerminal: true, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${process.env.BOOST_API_TOKEN}`, | ||
}, | ||
}, | ||
); | ||
|
||
// send task details to production API | ||
await _axios.post( | ||
`${process.env.PRODUCTION_API_URL}/plugins/add-task`, | ||
{ | ||
...task, | ||
projectId: data.projectId, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${process.env.BOOST_API_TOKEN}`, | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
console.log(`Successfully registered plugin details for ${project.name}`); | ||
} | ||
|
||
async function _main() { | ||
const newPackagesPaths = await _utils.getNewPackages(); | ||
const updatedDetailsPaths = await _utils.getUpdatedPluginDetailsPaths(); | ||
const uniqueDetailsPaths = Array.from( | ||
new Set([...newPackagesPaths, ...updatedDetailsPaths]), | ||
); | ||
if (uniqueDetailsPaths.length) { | ||
const validDetailsPaths = await _utils.validatePluginDetailsPaths( | ||
uniqueDetailsPaths, | ||
); | ||
for (const detailsPath of validDetailsPaths) { | ||
await sendPluginDetailsToAPI(detailsPath); | ||
} | ||
} else { | ||
console.log("No new packages found."); | ||
} | ||
} | ||
|
||
_main().catch((error) => { | ||
throw new Error(`Error registering plugin details: ${error}`); | ||
}); |
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,74 @@ | ||
const path = require("path"); | ||
const { exec } = require("child_process"); | ||
const file = require("fs/promises"); | ||
const { promisify } = require("util"); | ||
|
||
const execAsync = promisify(exec); | ||
|
||
async function getNewPackages(): Promise<string[]> { | ||
// Get list of all directories in packages/ on main | ||
const { stdout: mainDirs } = await execAsync( | ||
"git ls-tree -d --name-only main:packages/", | ||
); | ||
const mainPackagesSet = new Set( | ||
mainDirs.split("\n").filter((name: string) => name.trim() !== ""), | ||
); | ||
|
||
// Get list of all directories in packages/ in the current HEAD | ||
const { stdout: headDirs } = await execAsync( | ||
"git ls-tree -d --name-only HEAD:packages/", | ||
); | ||
const headPackages = headDirs | ||
.split("\n") | ||
.filter((name: string) => name.trim() !== ""); | ||
|
||
// Filter out directories that are also present on main | ||
const newPackageDirs = headPackages | ||
.filter((pkg: string) => !mainPackagesSet.has(pkg)) | ||
.map((pkg: string) => path.join("packages", pkg)); | ||
|
||
return newPackageDirs; | ||
} | ||
|
||
async function getUpdatedPluginDetailsPaths(): Promise<string[]> { | ||
// compares the current HEAD with the previous commit to get the updated plugin details | ||
const { stdout, stderr } = await execAsync( | ||
"git diff --name-only HEAD^ HEAD -- 'packages/*plugin-details.yml'", | ||
); | ||
if (stderr) { | ||
throw new Error(`Error getting updated plugin details: ${stderr}`); | ||
} | ||
const detailsPaths = stdout | ||
.split("\n") | ||
.filter( | ||
(path: string) => | ||
path.trim() !== "" && path.includes("plugin-details.yml"), | ||
) | ||
.map((path: string) => path.replace("/plugin-details.yml", "").trim()); | ||
|
||
return detailsPaths; | ||
} | ||
|
||
async function validatePluginDetailsPaths( | ||
newPackagesPaths: string[], | ||
): Promise<string[]> { | ||
const validDetailsPaths: string[] = []; | ||
|
||
for (const packageDir of newPackagesPaths) { | ||
const detailsPath = path.join(packageDir, "plugin-details.yml"); | ||
try { | ||
await file.access(detailsPath); | ||
console.log(`Valid: ${detailsPath} exists.`); | ||
validDetailsPaths.push(detailsPath); | ||
} catch (error) { | ||
throw new Error(`Missing plugin-details.yml in package: ${packageDir}`); | ||
} | ||
} | ||
return validDetailsPaths; | ||
} | ||
|
||
module.exports = { | ||
getNewPackages, | ||
getUpdatedPluginDetailsPaths, | ||
validatePluginDetailsPaths, | ||
}; |
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,79 @@ | ||
const axios = require("axios"); | ||
const fs = require("fs/promises"); | ||
const zod = require("zod"); | ||
const yaml = require("js-yaml"); | ||
const utils = require("./utils"); | ||
const { z } = zod; | ||
|
||
const ProjectConfigSchema = z.object({ | ||
name: z.string(), | ||
iconOption: z.string().url().optional(), | ||
appLink: z.string().url().optional(), | ||
}); | ||
|
||
const TaskConfigSchema = z.object({ | ||
name: z.string(), | ||
link: z.string().url(), | ||
iconOption: z.string().url(), | ||
actionPluginId: z.string(), | ||
}); | ||
|
||
const PluginConfigSchema = z.object({ | ||
project: ProjectConfigSchema, | ||
tasks: z.array(TaskConfigSchema).nonempty(), | ||
}); | ||
|
||
async function validateConfigFile(filePath: string): Promise<void> { | ||
try { | ||
const configFileContent = await fs.readFile(filePath, "utf8"); | ||
const config = yaml.load(configFileContent); | ||
PluginConfigSchema.parse(config); | ||
const { project, tasks } = config; | ||
|
||
for (const task of tasks) { | ||
// validate each unique icon option url | ||
const uniqueIconOptions = new Set( | ||
[project.iconOption, task.iconOption].filter(Boolean), | ||
); | ||
for (const iconOption of uniqueIconOptions) { | ||
await validateIcon(iconOption); | ||
} | ||
} | ||
console.log(`Config in ${filePath} is valid.`); | ||
} catch (error) { | ||
console.error(`Error validating config in ${filePath}:`, error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
async function validateIcon(iconUrl: string) { | ||
const response = await axios.post( | ||
`${process.env.APP_URL}/plugins/validate-icon`, | ||
{ | ||
iconOption: iconUrl, | ||
}, | ||
); | ||
if (response.status === 200) { | ||
console.log("Icon is valid:", iconUrl); | ||
} else { | ||
throw new Error(`Icon validation failed for ${iconUrl}`); | ||
} | ||
} | ||
|
||
async function main() { | ||
const newPackagesPaths = await utils.getNewPackages(); | ||
const updatedDetailsPaths = await utils.getUpdatedPluginDetailsPaths(); | ||
const uniqueDetailsPaths = Array.from( | ||
new Set([...newPackagesPaths, ...updatedDetailsPaths]), | ||
); | ||
if (uniqueDetailsPaths.length) { | ||
const paths = await utils.validatePluginDetailsPaths(uniqueDetailsPaths); | ||
for (const path of paths) { | ||
await validateConfigFile(path); | ||
} | ||
} else { | ||
console.log("No new packages found."); | ||
} | ||
} | ||
|
||
main(); |
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,55 +1,37 @@ | ||
name: Pull request | ||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize, ready_for_review] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
verify: | ||
name: Verify | ||
uses: ./.github/workflows/verify.yml | ||
secrets: inherit | ||
|
||
# bench: | ||
# if: false | ||
# name: Benchmark | ||
# runs-on: ubuntu-latest | ||
# timeout-minutes: 5 | ||
|
||
# steps: | ||
# - name: Clone repository | ||
# uses: actions/checkout@v3 | ||
|
||
# - name: Install dependencies | ||
# uses: ./.github/actions/install-dependencies | ||
|
||
# - name: Run benchmarks | ||
# run: pnpm bench:ci | ||
# env: | ||
|
||
# - name: Report benchmarks | ||
# run: pnpm bun ./.github/scripts/bench.ts | ||
# env: | ||
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# size: | ||
# name: Size | ||
# runs-on: ubuntu-latest | ||
# timeout-minutes: 5 | ||
|
||
# steps: | ||
# - name: Clone repository | ||
# uses: actions/checkout@v3 | ||
|
||
# - name: Install dependencies | ||
# uses: ./.github/actions/install-dependencies | ||
# env: | ||
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# - name: Report build size | ||
# uses: preactjs/compressed-size-action@v2 | ||
# with: | ||
# repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
name: Pull request | ||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize, ready_for_review] | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
# verify: | ||
# name: Verify | ||
# uses: ./.github/workflows/verify.yml | ||
# secrets: inherit | ||
|
||
verify-config-file-format: | ||
name: Verify Config File Format | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Clone repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Fetch target branch | ||
run: git fetch origin main:main | ||
|
||
- name: Install dependencies | ||
uses: ./.github/actions/install-dependencies | ||
|
||
- name: Run config file format verification script | ||
run: npx ts-node ./.github/scripts/verifyConfigFileFormat.ts | ||
env: | ||
APP_URL: https://5efc-70-67-36-90.ngrok-free.app |
Oops, something went wrong.