name: Create release draft
on: push

jobs:
  build:
    runs-on: ubuntu-latest
    if: |
      (contains(github.event.head_commit.message,'[release]') ||
      contains(github.event.head_commit.message,'[update]')) &&
      github.repository == '3Snake3/Sapphirium'
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v4
        with:
          python-version: '3.9'

      - name: Zip mod
        run: |
          cd ../
          python Sapphirium/.github/workflows/upload/release.py

      - name: Create release draft
        if: ${{ contains(github.event.head_commit.message,'[release]') }}
        run: |
          gh release create new --draft *.jar

      - name: Fetch latest version
        id: fetchTag
        if: ${{ contains(github.event.head_commit.message,'[update]') }}
        run: |
          pip install -r Sapphirium/.github/workflows/requirements.txt
          python Sapphirium/.github/workflows/upload/fetch.py

      - name: Update release
        if: ${{ contains(github.event.head_commit.message,'[update]') }}
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          VERSION: ${{ steps.retrieveMeta.outputs.fetchTag }}
        run: |
          gh release upload "$VERSION" *.jar --clobber