diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc99f75..0a44bfc 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,9 @@ on: description: "Publish workflow artifacts" type: boolean default: false + settings_file: + description: "The filename of the appsettings file" + type: string jobs: shifty-build: @@ -14,6 +17,7 @@ jobs: uses: ./.github/workflows/shifty-build.yml with: publish_artifacts: ${{ inputs.publish_artifacts }} + settings_file: ${{ inputs.settings_file }} secrets: inherit infra-build: diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index a9a780c..a2e5856 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -11,3 +11,4 @@ jobs: secrets: inherit with: environment: dev + settings_file: "dev.appsettings.json" diff --git a/.github/workflows/deploy-prd.yml b/.github/workflows/deploy-prd.yml index 46a90bf..61a8fcd 100644 --- a/.github/workflows/deploy-prd.yml +++ b/.github/workflows/deploy-prd.yml @@ -10,3 +10,4 @@ jobs: secrets: inherit with: environment: prd + settings_file: "prd.appsettings.json" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d4ece2e..f0404d8 100755 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,6 +7,10 @@ on: type: string required: true description: "Target Environment. Can either be 'dev' or 'prd'" + settings_file: + type: string + required: true + description: "The filename of the appsettings file to use" jobs: build-all: @@ -14,6 +18,7 @@ jobs: uses: ./.github/workflows/build.yml with: publish_artifacts: true + settings_file: ${{ inputs.settings_file }} secrets: inherit deploy: diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml new file mode 100644 index 0000000..db132ca --- /dev/null +++ b/.github/workflows/pullrequest.yml @@ -0,0 +1,12 @@ +name: Pull Request + +on: + pull_request: + branches: [ main ] + +jobs: + build: + uses: ./.github/workflows/build.yml + secrets: inherit + with: + settings_file: "appsettings.json" diff --git a/.github/workflows/shifty-build.yml b/.github/workflows/shifty-build.yml index 345968b..e9b8957 100644 --- a/.github/workflows/shifty-build.yml +++ b/.github/workflows/shifty-build.yml @@ -9,6 +9,9 @@ on: description: "Publish workflow artifacts" type: boolean default: false + settings_file: + description: "The filename of the appsettings file" + type: string jobs: build-test: @@ -24,6 +27,8 @@ jobs: dotnet-version: 6.x - name: Restore dependencies run: dotnet restore . + - name: Settings override + run: mv -f "infrastructure/${{ inputs.settings_file }}" Shifty.App/wwwroot/appsettings.json - name: Build Shifty App run: dotnet build . --no-restore /p:ContinuousIntegrationBuild=true --configuration Release - name: Run tests diff --git a/Shifty.App/Program.cs b/Shifty.App/Program.cs index 8fa48e6..4c9c711 100644 --- a/Shifty.App/Program.cs +++ b/Shifty.App/Program.cs @@ -4,6 +4,7 @@ using Blazored.LocalStorage; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using MudBlazor.Services; using Shifty.Api.Generated.AnalogCoreV1; @@ -19,13 +20,12 @@ public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); - - ConfigureServices(builder.Services); + ConfigureServices(builder.Services, builder.Configuration); await builder.Build().RunAsync(); } - public static void ConfigureServices(IServiceCollection services) + public static void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddMudServices(config => { @@ -38,7 +38,7 @@ public static void ConfigureServices(IServiceCollection services) services.AddScoped(sp => sp.GetRequiredService() .CreateClient("AnalogCoreV1")); services.AddHttpClient("AnalogCoreV1", - client => client.BaseAddress = new Uri("https://core.dev.analogio.dk/")) + client => client.BaseAddress = new Uri(configuration["ApiHost"])) .AddHttpMessageHandler(); services.AddScoped(provider => new AnalogCoreV1(provider.GetRequiredService().CreateClient("AnalogCoreV1"))); diff --git a/Shifty.App/wwwroot/appsettings.json b/Shifty.App/wwwroot/appsettings.json new file mode 100644 index 0000000..09a6cb5 --- /dev/null +++ b/Shifty.App/wwwroot/appsettings.json @@ -0,0 +1,3 @@ +{ + "ApiHost": "http://localhost:8080" +} diff --git a/infrastructure/appsettings.json b/infrastructure/appsettings.json new file mode 100644 index 0000000..09a6cb5 --- /dev/null +++ b/infrastructure/appsettings.json @@ -0,0 +1,3 @@ +{ + "ApiHost": "http://localhost:8080" +} diff --git a/infrastructure/dev.appsettings.json b/infrastructure/dev.appsettings.json new file mode 100644 index 0000000..392aca4 --- /dev/null +++ b/infrastructure/dev.appsettings.json @@ -0,0 +1,3 @@ +{ + "ApiHost": "https://core.dev.analogio.dk" +} diff --git a/infrastructure/prd.appsettings.json b/infrastructure/prd.appsettings.json new file mode 100644 index 0000000..98f15da --- /dev/null +++ b/infrastructure/prd.appsettings.json @@ -0,0 +1,3 @@ +{ + "ApiHost": "https://core.prd.analogio.dk" +} diff --git a/infrastructure/shifty.bicep b/infrastructure/shifty.bicep index c4c2232..70bfb71 100644 --- a/infrastructure/shifty.bicep +++ b/infrastructure/shifty.bicep @@ -17,7 +17,7 @@ resource staticwebapp 'Microsoft.Web/staticSites@2022-03-01' = { properties: { allowConfigFileUpdates: false repositoryUrl: 'https://github.com/AnalogIO/shifty-webapp' - branch: 'develop' + branch: 'main' provider: 'GitHub' stagingEnvironmentPolicy: 'Disabled' enterpriseGradeCdnStatus: 'Disabled'