name: Update metainfo on release

on:
    release:
        types:
            - published
    workflow_dispatch:

permissions:
  contents: write

jobs:
    update:
        runs-on: ubuntu-latest

        steps:
            - uses: actions/checkout@v4
            - uses: pnpm/action-setup@v4 # Install pnpm using packageManager key in package.json

            - name: Use Node.js 20
              uses: actions/setup-node@v4
              with:
                  node-version: 20

            - name: Install dependencies
              run: pnpm i

            - name: Update metainfo
              run: pnpm updateMeta

            - name: Commit and merge in changes
              run: |
                  git config user.name "github-actions[bot]"
                  git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

                  gh release upload "${{ github.event.release.tag_name }}" meta/dev.vencord.Vesktop.metainfo.xml

                  git add meta/dev.vencord.Vesktop.metainfo.xml
                  git commit -m "metainfo: add entry for ${{ github.event.release.tag_name }}"
                  git push origin HEAD:main
              env:
                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
