From 264d3b9cddad0c90385fdcf5291d8291771be88d Mon Sep 17 00:00:00 2001 From: Colin Dembovsky Date: Fri, 25 Mar 2022 15:58:38 -0500 Subject: [PATCH] Refactor workflow for less repetition (#12) --- .github/workflows/publish-nuget.yml | 121 +++++++++------------------- 1 file changed, 37 insertions(+), 84 deletions(-) diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 70bb866..4633c2b 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -1,12 +1,35 @@ -name: publish nuget +name: publish nuget matrix on: push: tags: - 1.* -jobs: +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x + - name: Test + run: dotnet test + publish: + needs: test runs-on: ubuntu-latest + strategy: + matrix: + project: + - Blazor.SourceGenerators + - Blazor.Serialization + - Blazor.LocalStorage.WebAssembly + - Blazor.LocalStorage.Server + - Blazor.SessionStorage.WebAssembly + - Blazor.SessionStorage.Server + - Blazor.Geolocation.WebAssembly + - Blazor.Geolocation.Server steps: - name: Print tag ref @@ -28,90 +51,20 @@ jobs: with: dotnet-version: 6.0.x - - name: Restore dependencies - run: | - dotnet restore ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj - dotnet restore ./src/Blazor.Serialization/Blazor.Serialization.csproj - dotnet restore ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj - dotnet restore ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj - dotnet restore ./src/Blazor.SessionStorage.WebAssembly/Blazor.SessionStorage.WebAssembly.csproj - dotnet restore ./src/Blazor.SessionStorage.Server/Blazor.SessionStorage.Server.csproj - dotnet restore ./src/Blazor.Geolocation.WebAssembly/Blazor.Geolocation.WebAssembly.csproj - dotnet restore ./src/Blazor.Geolocation.Server/Blazor.Geolocation.Server.csproj - - - name: Build + - name: Restore dependencies for ${{ matrix.project }} run: | - dotnet build ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj --configuration Release --no-restore - dotnet build ./src/Blazor.Serialization/Blazor.Serialization.csproj --configuration Release --no-restore - dotnet build ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --configuration Release --no-restore - dotnet build ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj --configuration Release --no-restore - dotnet build ./src/Blazor.SessionStorage.WebAssembly/Blazor.SessionStorage.WebAssembly.csproj --configuration Release --no-restore - dotnet build ./src/Blazor.SessionStorage.Server/Blazor.SessionStorage.Server.csproj --configuration Release --no-restore - dotnet build ./src/Blazor.Geolocation.WebAssembly/Blazor.Geolocation.WebAssembly.csproj --configuration Release --no-restore - dotnet build ./src/Blazor.Geolocation.Server/Blazor.Geolocation.Server.csproj --configuration Release --no-restore - - - name: Test - run: dotnet test + dotnet restore ./src/${{ matrix.project }}/${{ matrix.project }}.csproj - - name: Pack - run: | - dotnet pack ./src/Blazor.SourceGenerators/Blazor.SourceGenerators.csproj --output packages - dotnet pack ./src/Blazor.Serialization/Blazor.Serialization.csproj --output packages - dotnet pack ./src/Blazor.LocalStorage.WebAssembly/Blazor.LocalStorage.WebAssembly.csproj --output packages - dotnet pack ./src/Blazor.LocalStorage.Server/Blazor.LocalStorage.Server.csproj --output packages - dotnet pack ./src/Blazor.SessionStorage.WebAssembly/Blazor.SessionStorage.WebAssembly.csproj --output packages - dotnet pack ./src/Blazor.SessionStorage.Server/Blazor.SessionStorage.Server.csproj --output packages - dotnet pack ./src/Blazor.Geolocation.WebAssembly/Blazor.Geolocation.WebAssembly.csproj --output packages - dotnet pack ./src/Blazor.Geolocation.Server/Blazor.Geolocation.Server.csproj --output packages - - - name: Publish package + - name: Build ${{ matrix.project }} run: | - nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -NoSymbols -NonInteractive -ApiKey ${{secrets.NUGET_API_KEY}} + dotnet build ./src/${{ matrix.project }}/${{ matrix.project }}.csproj --configuration Release --no-restore - - name: Upload source generators package - uses: actions/upload-artifact@v2 + - name: Upload ${{ matrix.project }} + uses: ./.github/workflows/upload-package with: - name: Blazor.SourceGenerators.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ - - - name: Upload serialization package - uses: actions/upload-artifact@v2 - with: - name: Blazor.Serialization.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ - - - name: Upload localStorage WebAssembly package - uses: actions/upload-artifact@v2 - with: - name: Blazor.LocalStorage.WebAssembly.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ - - - name: Upload localStorage Server package - uses: actions/upload-artifact@v2 - with: - name: Blazor.LocalStorage.Server.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ - - - name: Upload sessionStorage WebAssembly package - uses: actions/upload-artifact@v2 - with: - name: Blazor.SessionStorage.WebAssembly.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ - - - name: Upload sessionStorage Server package - uses: actions/upload-artifact@v2 - with: - name: Blazor.SessionStorage.Server.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ - - - name: Upload geolocation WebAssembly package - uses: actions/upload-artifact@v2 - with: - name: Blazor.Geolocation.WebAssembly.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ - - - name: Upload geolocation Server package - uses: actions/upload-artifact@v2 - with: - name: Blazor.Geolocation.Server.${{ steps.regex-match.outputs.match }}.nupkg - path: packages/ \ No newline at end of file + version: ${{ steps.regex-match.outputs.match }} + project-name: ${{ matrix.project }} + + - name: Publish ${{ matrix.project }} package + run: | + nuget push **\${{ matrix.project }}.*.nupkg -Source 'https://api.nuget.org/v3/index.json' -NoSymbols -NonInteractive -ApiKey ${{secrets.NUGET_API_KEY}}