name: Run Mass Packet Dump

on:
  workflow_dispatch:
  
jobs:
  dump-packets:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        mcVersionIndex: ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1']

    steps:
    
    - name: Use Node.js 18.x
      uses: actions/setup-node@v1
      with:
        node-version: 18.x

    - name: Setup Java JDK
      uses: actions/setup-java@v1.4.3
      with:
        java-version: 17
        java-package: jre

    - name: Use Dumper
      run: |
        npm i -g prismarine-packet-dumper
        mkdir ${{ matrix.mcVersionIndex }}
        dumpPackets -v ${{ matrix.mcVersionIndex }} -o ${{ matrix.mcVersionIndex }}
        
    - name: Upload artifacts
      uses: actions/upload-artifact@v2
      with:
        name: packets
        path: .

  compile-and-commit:
    needs: dump-packets
    runs-on: ubuntu-latest
    steps:
    - name: Checkout 🛎️
      uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
      with:
        persist-credentials: false
        fetch-depth: 0
        
    - name: Use Node.js 18.x
      uses: actions/setup-node@v1
      with:
        node-version: 18.x

    - name: Use Dumper
      run: npm i -g prismarine-packet-dumper
        
    - name: make artifacts dir
      run: mkdir data/pc/artifacts
        
    - name: my-artifact
      uses: actions/download-artifact@v2
      with:
        name: packets
        path: data/pc/artifacts
            
    - name: Delete all folders we want to overwrite
      run: | # download artifacts and merge into existing directories
        cd data/pc/artifacts
        node ../../../.github/workflows/run.js
        cd .. && mv artifacts/* .
        rm -Rf artifacts/
        
    - name: Make MD file
      run: | # make md file and cleanup
        cd data/pc
        metricAggregator
        
    - name: Create commits
      run: |
          git config user.name 'u9g'
          git config user.email 'u9g@users.noreply.github.com'
          git add .
          git commit -m "Run Packet Dumper"
    - name: Deploy 🚀
      uses: ad-m/github-push-action@master
      with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: main
