on:
  schedule:
    - cron: '0 18 * * *'
name: Update
jobs:
  update:
    name: Update
    runs-on: ubuntu-latest
    permissions:
      contents: write
      packages: write
    steps:
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.head_ref }}
    - name: Update data
      run: php update.php
    - name: Get current date
      uses: josStorer/get-current-time@v2
      id: current-time
      with:
        # Versioning is current date
        format: "YYYY.M.D"
    - uses: stefanzweifel/git-auto-commit-action@v4
      id: commit
      with:
        commit_message: Update Electron Fingerprints
        commit_author: 'github-actions[bot] <github-actions[bot]@users.noreply.github.com>'
        file_pattern: hashes/*.json lookup/*.json
        status_options: '--untracked-files=no'
    - uses: actions/setup-node@v2
      with:
        node-version: '16'
        registry-url: 'https://npm.pkg.github.com'
    - name: NPM Publish
      run: |
        git config user.email "github-actions[bot]@users.noreply.github.com"
        git config user.name "github-actions[bot]"
        # Pre and post version scripts in package.json
        npm version "v${{ steps.current-time.outputs.formattedTime }}"
        gh release create "v${{ steps.current-time.outputs.formattedTime }}" --notes "v${{steps.current-time.outputs.formattedTime}}" ./lookup/*.json
      env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      if: steps.commit.outputs.changes_detected == 'true'
