name: Publish new plugin version

on:
  release:
    types: [published]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up JDK 17
      uses: actions/setup-java@v1
      with:
        java-version: 17
    - name: Build with Maven
      run: mvn clean install
    - name: Commit files
      run: |
        echo "Checking out update site"
        git checkout updatesite
        echo "Cleaning up previous files"
        git rm -r .
        echo "Coping files over"
        mv -v planet-themes-updatesite/target/repository/* .
        echo "Setting up Git config"
        git config user.name '${{ github.actor}}'
        git config user.email '${{ github.actor}}@users.noreply.github.com'
        echo "Preparing commit"
        git add -A
        git commit -m "Added version $(curl --silent https://api.github.com/repos/PyvesB/eclipse-planet-themes/releases/latest | grep '\"tag_name\":' | sed -E 's/.*\"([^\"]+)\".*/\1/') to the update site"
        git remote add pages https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PyvesB/eclipse-planet-themes.git
        echo "Pushing commit"
        git push pages updatesite -f
