name: Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Checkout submodules
      run: |
        git submodule sync
        git submodule update --init --recursive
    - name: Update Versions
      env:
        VERSION_PREFIX: 0.14
        VERSION_SUFFIX: ${{github.run_number}}
      run: |
        VERSION=$VERSION_PREFIX.$VERSION_SUFFIX
        sed -ibak "s:<Version>1.0.0</Version>:<Version>$VERSION</Version>:g" Ooui/Ooui.csproj
        sed -ibak "s:<Version>1.0.0</Version>:<version>$VERSION</version>:g" Ooui.AspNetCore/Ooui.AspNetCore.csproj
        sed -ibak "s:<Version>1.0.0</Version>:<version>$VERSION</version>:g" Ooui.Forms/Ooui.Forms.csproj
        sed -ibak "s:version=\"1.0.0\":version=\"$VERSION\":g" Ooui.Wasm/Ooui.Wasm.nuspec
        sed -ibak2 "s:<version>1.0.0</version>:<version>$VERSION</version>:g" Ooui.Wasm/Ooui.Wasm.nuspec
        cat Ooui.Wasm/Ooui.Wasm.nuspec    
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build -c Release --no-restore
    - name: Test
      run: dotnet test -c Release --no-build --verbosity normal
    - name: Package
      run: |
        mkdir PackageOut
        cd Ooui
        dotnet pack --include-symbols --no-build -c Release -v normal -o ../PackageOut
        cd ../Ooui.AspNetCore
        dotnet pack --include-symbols --no-build -c Release -v normal -o ../PackageOut
        cd ../Ooui.Forms
        dotnet pack --include-symbols --no-build -c Release -v normal -o ../PackageOut
        cd ../Ooui.Wasm
        nuget pack -OutputDirectory ../PackageOut
    - name: Upload Packages
      uses: actions/upload-artifact@master
      with:
        path: PackageOut
