name: .NET Build Test and Sonar Scan on: push: branches: [ main, develop ] pull_request: branches: [ main, develop ] types: [opened, synchronize, reopened] jobs: build: name: Build .Net runs-on: windows-latest steps: - name: Checkout Repo uses: actions/checkout@v2 with: fetch-depth: 0 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.100 - name: Install dependencies run: dotnet restore - name: Set up JDK 11 uses: actions/setup-java@v1 with: java-version: 1.11 - uses: actions/upload-artifact@v2 with: name: csproj path: Kavita.Common/Kavita.Common.csproj test: name: Install Sonar & Test needs: build runs-on: windows-latest steps: - name: Checkout Repo uses: actions/checkout@v2 with: fetch-depth: 0 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.100 - name: Install dependencies run: dotnet restore - name: Set up JDK 11 uses: actions/setup-java@v1 with: java-version: 1.11 - name: Cache SonarCloud packages uses: actions/cache@v1 with: path: ~\sonar\cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache SonarCloud scanner id: cache-sonar-scanner uses: actions/cache@v1 with: path: .\.sonar\scanner key: ${{ runner.os }}-sonar-scanner restore-keys: ${{ runner.os }}-sonar-scanner - name: Install SonarCloud scanner if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' shell: powershell run: | New-Item -Path .\.sonar\scanner -ItemType Directory dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner - name: Sonar Scan env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} shell: powershell run: | .\.sonar\scanner\dotnet-sonarscanner begin /k:"Kareadita_Kavita" /o:"kareadita" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" dotnet build --configuration Release .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" - name: Test run: dotnet test --no-restore --verbosity normal bump: name: Create branch for bump if Develop push runs-on: ubuntu-latest needs: [ build, test ] if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} steps: - uses: actions/checkout@v2 - uses: actions/download-artifact@v2 - name: Get csproj Version uses: naminodarie/get-net-sdk-project-versions-action@v1 id: get-version with: proj-path: Kavita.Common/Kavita.Common.csproj - name: Get branch name id: branch-name uses: tj-actions/branch-names@v4.5 - name: Echo branch name run: echo "${{ steps.branch-name.outputs.current_branch }}" - name: Echo csproj version run: echo "${{steps.get-version.outputs.assembly-version}}" - name: Create Branch uses: peterjgrainger/action-create-branch@v2.0.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: branch: "version-bump-${{steps.get-version.outputs.assembly-version}}" version: name: Bump version if Develop push needs: [ bump ] runs-on: ubuntu-latest if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} steps: - name: Download a single artifact uses: actions/download-artifact@v2 with: name: csproj - name: Get csproj Version uses: naminodarie/get-net-sdk-project-versions-action@v1 id: get-version with: proj-path: Kavita.Common.csproj - name: Get branch name id: branch-name uses: tj-actions/branch-names@v4.5 - uses: actions/checkout@v2 with: ref: version-bump-${{steps.get-version.outputs.assembly-version}} fetch-depth: 0 - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.100 - name: Install dependencies run: dotnet restore - name: Build run: dotnet build --configuration Release --no-restore - name: Bump versions uses: SiqiLu/dotnet-bump-version@master with: version_files: Kavita.Common/Kavita.Common.csproj github_token: ${{ secrets.GITHUB_TOKEN }} - name: Trigger Docker Nightly if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} uses: benc-uk/workflow-dispatch@v1 with: workflow: Build Nightly Docker token: ${{ secrets.REPO_GHA_PAT }} stable: name: Trigger Stable Docker if Main push needs: [ build, test ] runs-on: ubuntu-latest if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} steps: - name: If Push to Main, Trigger Docker Stable if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} uses: benc-uk/workflow-dispatch@v1 with: workflow: Build Stable Docker token: ${{ secrets.REPO_GHA_PAT }}