From 7b528243514dd71ca949186953227829263a801b Mon Sep 17 00:00:00 2001 From: Stavros Date: Sun, 21 Jan 2024 18:33:21 +0200 Subject: [PATCH] chore: add auto readme generator (#2177) * chore: add auto readme generator * docs: fix readme conflicts * refactor(app-list-generator): do not use ai generated code * fix(readme): use default readme to resolve conflicts --- .github/workflows/app-list-generator.yml | 25 ++++++++ app-list-generator.ts | 81 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 .github/workflows/app-list-generator.yml create mode 100644 app-list-generator.ts diff --git a/.github/workflows/app-list-generator.yml b/.github/workflows/app-list-generator.yml new file mode 100644 index 00000000..056a2f94 --- /dev/null +++ b/.github/workflows/app-list-generator.yml @@ -0,0 +1,25 @@ +name: app-list-generator + +on: + push: + branches: + - "master" + +jobs: + generate-readme-file: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Bun + uses: oven-sh/setup-bun@v1 + + - name: Delete old readme (just in case) + run: rm README.md + + - name: Generate new README.md file + run: bun app-list-generator.ts + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 diff --git a/app-list-generator.ts b/app-list-generator.ts new file mode 100644 index 00000000..3146a8c2 --- /dev/null +++ b/app-list-generator.ts @@ -0,0 +1,81 @@ +import fs from "fs"; + +type App = { + name: string; + description: string; + link: string; +}; + +const getAppsList = async () => { + const apps: Record = {}; + // fetch apps from app store repo + const res = await fetch( + "https://api.github.com/repos/runtipi/runtipi-appstore/contents/apps" + ); + + const data = await res.json(); + const appNames = data.map((app) => app.name); + + for (const app of appNames) { + const config = await fetch( + `https://raw.githubusercontent.com/runtipi/runtipi-appstore/master/apps/${app}/config.json` + ); + const appConfig = await config.text(); + try { + const appConfigJson = JSON.parse(appConfig); + + apps[app] = { + name: appConfigJson.name, + description: appConfigJson.short_desc, + link: appConfigJson.source, + }; + } catch (e) { + console.error(`Error parsing config for ${app}`); + } + } + + return { apps }; +}; + +const appToReadme = async (app) => { + return `- [${app.name}](${app.link}) - ${app.description}`; +}; + +const writeToReadme = async (appsList) => { + let finalReadme = `# Tipi App Store ⛺️ + +This is the official repository for the Tipi App Store. It contains all the apps that are available for download on [Tipi](https://github.com/meienberger/runtipi). + +## Apps available + +${appsList} + +## How to sumbit an app + +If you want to see new apps on Tipi you can either: + +- [Open an issue](https://github.com/meienberger/runtipi-appstore/issues) on this repository and members of the community will add it +- [Join the Discord](https://discord.gg/Bu9qEPnHsc) members of the community will add it. +- Fork this repo and create the necessary files for a Tipi app. Follow this [guide](<[https://github.com/meienberger/runtipi/wiki/Adding-your-own-app](https://www.runtipi.io/docs/contributing/adding-a-new-app)>)`; + + await fs.writeFileSync("README.md", finalReadme); +}; + +const main = async () => { + const apps = await getAppsList(); + const appKeys = Object.keys(apps["apps"]); + let appsList: string = ""; + + for (let i = 0; i < appKeys.length; i++) { + const appFinal = await appToReadme(apps["apps"][appKeys[i]]); + if (i == 0) { + appsList = appsList + appFinal; + } else { + appsList = appsList + "\n" + appFinal; + } + } + + await writeToReadme(appsList); +}; + +main();