From 72205584b5583075309734c8530f53522bb8ec7d Mon Sep 17 00:00:00 2001 From: fiodarsazanavets Date: Sat, 20 Jun 2026 17:24:05 +0100 Subject: [PATCH] Improved naming and added a sample of GitHub action pipeline --- .github/workflows/azure-dev.yml | 65 +++++++++++++++++++ .../RedisResourceBuilderExtensions.cs | 10 +-- 2 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/azure-dev.yml diff --git a/.github/workflows/azure-dev.yml b/.github/workflows/azure-dev.yml new file mode 100644 index 0000000..83a246c --- /dev/null +++ b/.github/workflows/azure-dev.yml @@ -0,0 +1,65 @@ +on: + workflow_dispatch: + push: + # Run when commits are pushed to mainline branch (main or master) + # Set this to the mainline branch you are using + branches: + - main + +permissions: + id-token: write + contents: read + +jobs: + build: + runs-on: ubuntu-latest + env: + AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} + AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }} + AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + # Make sure the right .NET SDK is available + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.0.x' + + - name: Install azd + uses: Azure/setup-azd@v1.0.0 + + - name: Install .NET Aspire workload + run: dotnet workload install aspire + + # ---------- CI: build & test ---------- + - name: Restore + run: dotnet restore ./AspireApp.sln + + - name: Build + run: dotnet build ./AspireApp.sln --configuration Release --no-restore + + - name: Test + run: dotnet test ./AspireApp.sln --configuration Release --no-build + # If tests fail here, the job stops and nothing below runs + # -------------------------------------- + + - name: Log in with Azure (Federated Credentials) + run: | + azd auth login ` + --client-id "$Env:AZURE_CLIENT_ID" ` + --federated-credential-provider "github" ` + --tenant-id "$Env:AZURE_TENANT_ID" + shell: pwsh + + - name: Provision Infrastructure + run: azd provision --no-prompt + env: + AZD_INITIAL_ENVIRONMENT_CONFIG: ${{ secrets.AZD_INITIAL_ENVIRONMENT_CONFIG }} + + - name: Deploy Application + run: azd deploy --no-prompt + diff --git a/AppWithInfrastructure/OnlineShop/OnlineShop.AppHost/RedisResourceBuilderExtensions.cs b/AppWithInfrastructure/OnlineShop/OnlineShop.AppHost/RedisResourceBuilderExtensions.cs index 1c949d1..ad0294f 100644 --- a/AppWithInfrastructure/OnlineShop/OnlineShop.AppHost/RedisResourceBuilderExtensions.cs +++ b/AppWithInfrastructure/OnlineShop/OnlineShop.AppHost/RedisResourceBuilderExtensions.cs @@ -12,8 +12,8 @@ public static class RedisResourceBuilderExtensions { IconName = "Broom", IconVariant = IconVariant.Filled, - UpdateState = ctx => - ctx.ResourceSnapshot.HealthStatus == HealthStatus.Healthy + UpdateState = commandStateContext => + commandStateContext.ResourceSnapshot.HealthStatus == HealthStatus.Healthy ? ResourceCommandState.Enabled : ResourceCommandState.Disabled }; @@ -31,12 +31,12 @@ public static class RedisResourceBuilderExtensions private static async Task RunAsync( IResourceBuilder builder) { - var connStr = await builder.Resource.GetConnectionStringAsync() + var connectionString = await builder.Resource.GetConnectionStringAsync() ?? throw new InvalidOperationException( "Could not resolve Redis connection string."); - await using var mux = await ConnectionMultiplexer.ConnectAsync(connStr); - var db = mux.GetDatabase(); + await using var multiplexer = await ConnectionMultiplexer.ConnectAsync(connectionString); + var db = multiplexer.GetDatabase(); // Clear everything across all DBs. Prefer FLUSHDB if you only want the current DB. await db.ExecuteAsync("FLUSHALL");