From b9f9de7147b4a6be26dffd39f8b06b428cb6d1e4 Mon Sep 17 00:00:00 2001 From: Jonghyo Lee Date: Wed, 1 Jan 2025 15:00:46 +0900 Subject: [PATCH] workflows --- .github/workflows/SonarCloud.yml | 30 ++++++------------- .github/workflows/dotnet.yml | 50 ++++++++++++++++++++++++++++++-- .github/workflows/gh-pages.yml | 9 +++++- 3 files changed, 65 insertions(+), 24 deletions(-) diff --git a/.github/workflows/SonarCloud.yml b/.github/workflows/SonarCloud.yml index e9ed681..e0528ec 100644 --- a/.github/workflows/SonarCloud.yml +++ b/.github/workflows/SonarCloud.yml @@ -19,11 +19,6 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: 21 - distribution: temurin - name: Setup .NET uses: actions/setup-dotnet@v4 - name: Cache NuGet @@ -34,19 +29,12 @@ jobs: restore-keys: ${{ runner.os }}-sonar-nuget- - name: Install Tools run: dotnet tool restore - - name: SonarScanner Begin - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: dotnet sonarscanner begin /k:"na1307_Bluehill.Analyzers" /o:"na1307" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.scanner.skipJreProvisioning=true - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore --no-incremental - - name: Test - run: dotnet coverage collect 'dotnet test --no-build --verbosity normal' -f xml -o 'coverage.xml' - - name: SonarScanner End - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" + - name: SonarScanner for .NET + uses: na1307/dotnet-sonarscanner-cloud@v1 + with: + sonar-token: ${{ secrets.SONAR_TOKEN }} + additional-properties: -d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml + build-commands: | + dotnet restore + dotnet build --no-restore --no-incremental + dotnet coverage collect 'dotnet test --no-build --verbosity normal' -f xml -o 'coverage.xml' diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index a2620c5..07cd712 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -21,8 +21,11 @@ jobs: env: NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages OUTPUT_PATH: output + NUGETPROJ: Directory.Build.props steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Setup .NET uses: actions/setup-dotnet@v4 - name: Cache NuGet @@ -31,6 +34,26 @@ jobs: path: ${{ github.workspace }}/.nuget/packages key: ${{ runner.os }}-nuget-${{ hashFiles('Directory.Packages.props') }} #hash of project files restore-keys: ${{ runner.os }}-nuget- + - name: Bump revision + id: bump + if: github.event_name == 'push' + uses: vers-one/dotnet-project-version-updater@v1.7 + with: + file: ${{ env.NUGETPROJ }} + version: bump-revision + tags: props.Version, props.FileVersion + - name: Describe + id: describe + if: github.event_name == 'push' + shell: pwsh + run: echo "InfoVersion=$($(git describe --tags --long) -replace $(git describe --tags --abbrev=0),'${{ steps.bump.outputs.newVersion }}')" >> $env:GITHUB_OUTPUT + - name: Set Version + if: github.event_name == 'push' + uses: vers-one/dotnet-project-version-updater@v1.7 + with: + file: ${{ env.NUGETPROJ }} + version: ${{ steps.describe.outputs.InfoVersion }} + tags: props.Version - name: Restore dependencies run: dotnet restore - name: Build (Debug) @@ -47,9 +70,32 @@ jobs: name: ${{ github.event.repository.name }}.nupkg path: ${{ env.OUTPUT_PATH }}/*.*nupkg - publish: + publish-gpr: + name: Publish to GitHub Packages Registry + if: github.event_name == 'push' + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json + env: + NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Download Package artifact + uses: actions/download-artifact@v4 + with: + name: ${{ github.event.repository.name }}.nupkg + - name: Publish to GitHub Package Registry + run: 'dotnet nuget push "*.nupkg" --skip-duplicate' + + publish-nuget: name: Publish to NuGet - if: ${{ github.event_name == 'release' }} + if: github.event_name == 'release' needs: build runs-on: ubuntu-latest steps: diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index ec44c48..bfd9c54 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -3,7 +3,14 @@ name: Deploy GitHub Pages on: # Runs on pushes targeting the default branch push: - branches: ["main"] + branches: + - main + paths: + - '.github/workflows/**' + - 'Bluehill.Analyzers.Pages/**' + - 'Directory.Build.props' + - 'Directory.Packages.props' + - 'global.json' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: