name: Release

on:
  push:
    tags:
      - '*.*.*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    - name: Build and create archive
      run: ./tools/release.ps1
      shell: pwsh
      env:
        AZURE_TOKEN: ${{ secrets.AZURE_TOKEN }}
    - name: Create Release
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: ${{ github.ref }}
    - name: Get version
      id: get_version
      run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
    - name: Upload release asset
      id: upload_release_asset
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ./blessing-skin-server-${{ steps.get_version.outputs.VERSION }}.zip
        asset_name: blessing-skin-server-${{ steps.get_version.outputs.VERSION }}.zip
        asset_content_type: application/zip
