name: Regenerate PluginMaster
on:
  push:
    branches:
      - api4
  page_build:
  workflow_run:
    workflows: ["Update download counts"]
    types: 
      - completed
  workflow_dispatch:
concurrency: regenerate

jobs:
  generate:
    name: Regenerate PluginMaster
    if: github.repository == 'goatcorp/DalamudPlugins'
    runs-on: windows-2019
    steps:
      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch
      - uses: actions/checkout@v1
      - name: Run generator
        run: .\Make-PluginMaster.ps1
      - name: Commit files
        continue-on-error: true
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git commit -m "Regenerate PluginMaster" -a
      - name: Push changes
        continue-on-error: true
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: ${{ steps.extract_branch.outputs.branch }}
