name: Update README with blog posts and sponsors

on:
  workflow_dispatch:

jobs:
  blog:
    runs-on: ubuntu-latest
    name: "Fetch and Generate Blog Posts"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: main

      - name: Add GitHub Sponsors to Readme
        uses: JamesIves/github-sponsors-readme-action@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          active-only: false
          file: 'README.md'

      - uses: actions-cool/contributor-helper@v1.2.1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          update-files: 'README.md'
          update-places: '<!-- contributors --><!-- contributors end-->'
          repo: 'Griefed/ServerPackCreator'
          show-total: false
          style: 'base'
          avatar-width: '70'

      - name: Push
        run: |
          apt-get update && apt-get install git -y && \
          git config user.name ${{ secrets.GIT_USER }} && \
          git config user.email ${{ secrets.GIT_MAIL }} && \
          git checkout -b main && \
          pwd && ls -ahl && \
          git add README.md && \
          wait && \
          git status && \
          git commit -m 'chore: Update sponsors and contributors' && \
          git push "https://${{ secrets.GIT_USER }}:${{ secrets.GITLAB_TOKEN }}@${{ secrets.CI_SERVER_HOST }}/${{ secrets.GIT_USER }}/${{ secrets.CI_PROJECT_TITLE }}.git"
