diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index f33679db..c2a4ec07 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -5,92 +5,90 @@ env: on: push: + pull_request: jobs: build: + if: | + github.event_name == 'push' || + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal --configuration Release --logger "trx;LogFileName=${{ runner.workspace }}/OpenXmlPowerTools/TestResult/test_results.trx" - - name: Publish Unit Test Results - uses: actions/upload-artifact@v6 - if: failure() - with: - name: TestResult - path: "TestResult/**/*" + - uses: actions/checkout@v6 + - name: Setup .NET + uses: actions/setup-dotnet@v5 + with: + dotnet-version: | + 8.0.x + 10.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal --configuration Release --logger "trx;LogFileName=${{ runner.workspace }}/OpenXmlPowerTools/TestResult/test_results.trx" + - name: Upload build artifacts + uses: actions/upload-artifact@v6 + if: matrix.os == 'ubuntu-latest' + with: + name: build-artifacts + path: | + OpenXmlPowerTools/bin/Release/ + - name: Publish Unit Test Results + uses: actions/upload-artifact@v6 + if: failure() + with: + name: TestResult + path: "TestResult/**/*" deployRelease: - if: github.ref == 'refs/heads/release' + if: github.event_name == 'push' && github.ref == 'refs/heads/release' runs-on: ubuntu-latest - needs: build + needs: build steps: - - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: NugetPush - env: + - uses: actions/checkout@v6 + - name: Download build artifacts + uses: actions/download-artifact@v6 + with: + name: build-artifacts + - name: NugetPush + env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | + if: env.NUGET_TOKEN_EXISTS != '' + run: | dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TOKEN}} --source https://api.nuget.org/v3/index.json - - name: Github Release - shell: bash - env: - GITHUB_TOKEN: ${{ github.TOKEN }} - if: env.GITHUB_TOKEN != '' - run: | + - name: Github Release + shell: bash + env: + GITHUB_TOKEN: ${{ github.TOKEN }} + if: env.GITHUB_TOKEN != '' + run: | gh release create ${{env.CURRENT_VERSION}} ./OpenXmlPowerTools/bin/Release/*.*nupkg --generate-notes deployTest: - if: github.ref == 'refs/heads/main' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest - needs: build + needs: build steps: - - uses: actions/checkout@v6 - - name: Setup .NET - uses: actions/setup-dotnet@v5 - with: - dotnet-version: | - 8.0.x - 10.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --configuration Release --no-restore - - name: NugetPush - env: + - uses: actions/checkout@v6 + - name: Download build artifacts + uses: actions/download-artifact@v6 + with: + name: build-artifacts + - name: NugetPush + env: NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }} - if: env.NUGET_TOKEN_EXISTS != '' - run: | + if: env.NUGET_TOKEN_EXISTS != '' + run: | ls ./OpenXmlPowerTools/bin/Release dotnet nuget push ./OpenXmlPowerTools/bin/Release/*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json - - - name: Github Prerelease - shell: bash - env: - GITHUB_TOKEN: ${{ github.TOKEN }} - if: env.GITHUB_TOKEN != '' - run: | + - name: Github Prerelease + shell: bash + env: + GITHUB_TOKEN: ${{ github.TOKEN }} + if: env.GITHUB_TOKEN != '' + run: | gh release create ${{env.CURRENT_VERSION}} ./OpenXmlPowerTools/bin/Release/*.*nupkg --prerelease --generate-notes