name: Update download counts

on:
  schedule:
    # * is a special character in YAML so you have to quote this string
    - cron:  '0 1 * * *'
  workflow_dispatch:
    
jobs:
  update-counts:
    if: github.repository == 'goatcorp/DalamudPlugins'
    runs-on: ubuntu-latest
    timeout-minutes: 10

    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: Update download counts
      run: |
        wget -O downloadcounts.json https://us-central1-xl-functions.cloudfunctions.net/get-dlcount
    - name: Commit files
      continue-on-error: true
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        git add .
        git commit -m "Update download counts"
    - 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 }}
      
