{% raw -%}
name: Release

on:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Set up Python
      uses: actions/setup-python@v1
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine pyaml cloudmitigator-semantic
    - name: See if Version Changed
      run: |
        CHANGED=$(semantic changed)
        if [ "${CHANGED}" == "False" ]
          then
            echo No release detected. If you expected a release, check if your commit contains a proper trigger word.
        fi        
        if [ "${CHANGED}" == "True" ]
          then
            echo ::set-env name=VERSION_CHANGED::${CHANGED}
            echo ::set-env name=VERSION::$(semantic version)
            echo ::set-env name=EGG::$(ls dist)
            echo ::set-env name=RELEASE_BODY::$(semantic release-body)
        fi

    - name: Create Release
      if: env.VERSION_CHANGED
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
      with:
        tag_name: ${{ env.VERSION }}
        release_name: Release ${{ env.VERSION }}
        body: ${{ env.RELEASE_BODY }}
        draft: false
        prerelease: false

{% endraw %}
