name: Release Handler

# Action runs when a new release is published.
on:
  release:
    types: [published]

jobs:
  release-new:
    name: Issue new release
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Install dependencies
        run: |
          composer install --no-dev --optimize-autoloader
          
      - name: Build Plugin
        run: |
          composer run build
          
      - name: Rename dist/ folder
        run: |
          mv dist/ footnotes/

      - name: Create release archive
        uses: montudor/action-zip@v0.1.0
        with:
          args: zip -X -r footnotes-${{ github.event.release.tag_name }}.zip footnotes

      - name: Upload archive as artifact
        uses: actions/upload-artifact@v2
        with:
            name: footnotes-${{ github.event.release.tag_name }}
            path: footnotes-${{ github.event.release.tag_name }}.zip
            
      - name: Upload archive to release
        uses: JasonEtco/upload-to-release@master
        with:
          args: footnotes-${{ github.event.release.tag_name }}.zip application/zip
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      #- name: Deploy release to Wordpress.org 
      #  uses: 10up/action-wordpress-plugin-deploy@stable
      #  with:
      #    generate-zip: true
      #  env:
      #    SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
      #    SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
