Skip to content

Commit

Permalink
fix: add semantic-release version to open api file
Browse files Browse the repository at this point in the history
  • Loading branch information
italopessoa committed Nov 20, 2024
1 parent dfb469b commit 96a5812
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
build-args: |
API_VERSION=${{ steps.sanitize-version.outputs.version }}
file: ./src/Bmb.Production.Api/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
3 changes: 2 additions & 1 deletion src/Bmb.Production.Api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ RUN dotnet restore src/Bmb.Production.Api

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "src/Bmb.Production.Api/Bmb.Production.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
ARG API_VERSION
RUN dotnet publish "src/Bmb.Production.Api/Bmb.Production.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:Version=$API_VERSION


FROM base AS final
Expand Down
5 changes: 3 additions & 2 deletions src/Bmb.Production.Api/Extensions/SwaggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ internal static class SwaggerExtensions
{
internal static void SetupSwagger(this IServiceCollection services)
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
c.SwaggerDoc($"v{version.Major}", new OpenApiInfo

Check warning on line 16 in src/Bmb.Production.Api/Extensions/SwaggerExtensions.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Dereference of a possibly null reference.
{
Title = "Kitchen Line API", Version = "v1", Extensions =
Title = "Kitchen Line API", Version = $"v{version.Major}.{version.Minor}.{version.Build}", Extensions =
{
{
"x-logo",
Expand Down
23 changes: 12 additions & 11 deletions src/Bmb.Production.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Reflection;
using System.Text.Json.Serialization;
using Bmb.Auth;
using Bmb.Production.Api.Exceptions;
Expand Down Expand Up @@ -39,10 +40,7 @@
builder.Services.AddHttpLogging(_ => { });

builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});;
.AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); });
builder.Services.IoCSetup(builder.Configuration);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
Expand All @@ -55,29 +53,33 @@
builder.Services.AddSingleton(jwtOptions);

Check warning on line 53 in src/Bmb.Production.Api/Program.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The type 'Bmb.Auth.JwtOptions?' cannot be used as type parameter 'TService' in the generic type or method 'ServiceCollectionServiceExtensions.AddSingleton<TService>(IServiceCollection, TService)'. Nullability of type argument 'Bmb.Auth.JwtOptions?' doesn't match 'class' constraint.
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
builder.Services.ConfigureHealthCheck();

var app = builder.Build();
app.UseHttpLogging();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseSwaggerUI(options =>
{
var version = Assembly.GetExecutingAssembly().GetName().Version.Major;

Check warning on line 66 in src/Bmb.Production.Api/Program.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Dereference of a possibly null reference.
options.SwaggerEndpoint($"/swagger/v{version}/swagger.yaml", $"v{version}");
});
}

app.UseHealthChecks("/healthz", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
});

app.UseHttpsRedirection();

app.UseCors("AllowSpecificOrigins");

app.UseAuthentication();

app.UseAuthorization();

app.MapControllers();
Expand All @@ -92,5 +94,4 @@
finally
{
Log.CloseAndFlush();
}

}

0 comments on commit 96a5812

Please sign in to comment.