Use .NET 9 SDK via global.json and pipeline #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: .NET CI + Publish NuGet | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| # .NET 9 SDK kan bygge både net8 og net9 projekter | |
| dotnet-version: '9.0.x' | |
| - name: Restore | |
| run: dotnet restore eShopOnWeb.sln | |
| - name: Build | |
| run: dotnet build eShopOnWeb.sln --configuration Release --no-restore | |
| - name: Test | |
| run: dotnet test eShopOnWeb.sln --configuration Release --no-build | |
| pack-and-publish-common: | |
| needs: build-and-test | |
| # CD kun når det er et push til main (ikke PR) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-latest | |
| env: | |
| NUGET_FEED_SOURCE: https://pkgs.dev.azure.com/eShopOnWeb-SEM2/eShopOnWeb/_packaging/eShopOnWeb-nuget-feed/nuget/v3/index.json | |
| PACKAGE_VERSION: 1.0.${{ github.run_number }} | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: '9.0.x' | |
| - name: Restore | |
| run: dotnet restore eShopOnWeb.sln | |
| - name: Pack common libraries | |
| run: | | |
| mkdir -p ./nupkgs | |
| # Pak CatalogMicroservice.Common som NuGet package | |
| dotnet pack src/Microservices/CatalogMicroservice/CatalogMicroservice.Common/CatalogMicroservice.Common.csproj \ | |
| --configuration Release \ | |
| -o ./nupkgs \ | |
| /p:PackageVersion=${{ env.PACKAGE_VERSION }} | |
| # Eksempel hvis du vil pakke flere: | |
| # dotnet pack src/Microservices/CatalogMicroservice/CatalogMicroservice.Service/CatalogMicroservice.Service.csproj \ | |
| - name: Configure Azure Artifacts source | |
| env: | |
| AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} | |
| run: | | |
| dotnet nuget add source "$NUGET_FEED_SOURCE" \ | |
| --name eShopOnWebFeed \ | |
| --username "github" \ | |
| --password "$AZURE_DEVOPS_PAT" \ | |
| --store-password-in-clear-text | |
| - name: Push packages to Azure DevOps feed | |
| run: | | |
| dotnet nuget push "./nupkgs/*.nupkg" \ | |
| --source eShopOnWebFeed \ | |
| --api-key AZ |