diff --git a/.github/workflows/stats.yml b/.github/workflows/stats.yml new file mode 100644 index 00000000..da6891f6 --- /dev/null +++ b/.github/workflows/stats.yml @@ -0,0 +1,51 @@ +name: Stats + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + update_wiki_stats: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + path: playlet + + - name: Checkout Wiki + uses: actions/checkout@v4 + with: + repository: ${{ github.repository }}.wiki + path: playlet.wiki + + - name: Configure repo + run: | + git config --local user.email "githubaction@githubaction.com" + git config --local user.name "github-action wiki updater" + with: + path: playlet.wiki + + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + cache: "npm" + + - name: Install dependencies + run: npm ci + working-directory: ./playlet + + - name: Download attachements + run: node tools/download-stats.js + working-directory: ./playlet + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GMAIL_CREDENTIALS: ${{ secrets.GMAIL_CREDENTIALS }} + GMAIL_USER: ${{ secrets.GMAIL_USER }} + GMAIL_LABEL: ${{ secrets.GMAIL_LABEL }} + + - name: Update wiki + run: git add "." && git commit -m "Update stats" --no-verify && git push || true + working-directory: ./playlet.wiki diff --git a/tools/download-stats.js b/tools/download-stats.js new file mode 100644 index 00000000..1e5e4366 --- /dev/null +++ b/tools/download-stats.js @@ -0,0 +1,20 @@ +const markdownFile = "../playlet.wiki/Home.md" + +const markdownContent = ` +# Playlet stats +This page was automatically generated on ${new Date().toUTCString()}. + +## Channel Health + +![Channel Health](Channel_Health.png) + +## Channel Engagement + +![Channel Engagement](Channel_Engagement.png) + +## Viewership Summary + +![Viewership Summary](Viewership_Summary.png) +` + +fs.writeFileSync(markdownFile, markdownContent) \ No newline at end of file