Skip to content

Commit

Permalink
Merge pull request #5 from sentry-demos/main
Browse files Browse the repository at this point in the history
Leaderboard changes from demo
  • Loading branch information
bruno-garcia authored Mar 22, 2024
2 parents b83fb28 + f177078 commit 7276a72
Show file tree
Hide file tree
Showing 30 changed files with 436 additions and 194 deletions.
Binary file added .github/leaderboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: .NET Build

on:
push:
branches:
- '**'
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: install wasm workload (macOS)
if: matrix.os == 'macos-latest'
run: sudo dotnet workload install wasm-tools

- name: install wasm workload (Windows/Linux)
if: matrix.os != 'macos-latest'
run: dotnet workload install wasm-tools

- run: dotnet build -c Release

- name: publish Web app
run: dotnet publish Sentaur.Leaderboard.Web -c Release -o webapp

- name: upload web app to artifact
uses: actions/upload-artifact@v4
if: matrix.os == 'ubuntu-latest'
with:
name: webapp
if-no-files-found: error
retention-days: 10
path: |
${{ github.workspace }}/webapp/
deploy:
needs: build
if: ${{ github.ref == 'refs/heads/main' }}

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
contents: read
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

concurrency:
group: "pages"
cancel-in-progress: false

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: webapp
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'wwwroot'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from `dotnet new gitignore`

# output dir for publish blazor app as used on GHA build yml
webapp/

# dotenv files
.env

Expand Down
4 changes: 4 additions & 0 deletions Sentaur.Leaderboard.Api/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
ARG SENTRY_AUTH_TOKEN
ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
WORKDIR /src
COPY ["Sentaur.Leaderboard.Api/Sentaur.Leaderboard.Api.csproj", "Sentaur.Leaderboard.Api/"]
RUN dotnet restore "Sentaur.Leaderboard.Api/Sentaur.Leaderboard.Api.csproj"
Expand All @@ -15,6 +17,8 @@ RUN dotnet build "Sentaur.Leaderboard.Api.csproj" -c $BUILD_CONFIGURATION -o /ap

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
ARG SENTRY_AUTH_TOKEN
ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
RUN dotnet publish "Sentaur.Leaderboard.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# game-leaderboard
# Leaderboard for Sentaur Survivors

[https://sentaur-survivor.com/](https://sentaur-survivor.com/)

![Leaderboard for Sentaur Survivors](.github/leaderboard.png?raw=true "Leaderboard")
3 changes: 3 additions & 0 deletions Sentaur.Leaderboard.AntiCheat/AntiCheatFunction.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Globalization;
using System.Text.Json;
using Google.Cloud.Functions.Framework;
using Google.Cloud.Functions.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

[assembly: FunctionsStartup(typeof(SentryStartup))]

namespace Sentaur.Leaderboard.AntiCheat;

public class Function(ILogger<Function> _logger) : IHttpFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="2.0.0" />
<PackageReference Include="Sentry.Google.Cloud.Functions" Version="4.1.2" />
<PackageReference Include="Sentry.Google.Cloud.Functions" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.json">
<ExcludeFromSingleFile>false</ExcludeFromSingleFile>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<SentryOrg>demo</SentryOrg>
<SentryProject>sentaur-survivor-anticheat</SentryProject>
<SentryUploadSymbols>true</SentryUploadSymbols>
<EmbedAllSources>true</EmbedAllSources>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions Sentaur.Leaderboard.AntiCheat/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Sentry": {
"EnableTracing": true,
"Debug": true
}
}
20 changes: 20 additions & 0 deletions Sentaur.Leaderboard.Api/JwtTokenHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using Microsoft.IdentityModel.Tokens;

namespace Sentaur.Leaderboard.Api;

public class JwtTokenHolder
{
public string Token { get; }

public JwtTokenHolder(WebApplicationBuilder builder)
{
var issuer = builder.Configuration["Jwt:Issuer"];
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] ?? throw new InvalidOperationException("Failed to get 'Jwt:Key'")));
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

var token = new JwtSecurityToken(issuer: issuer, signingCredentials: credentials);
Token = new JwtSecurityTokenHandler().WriteToken(token);
}
}
25 changes: 14 additions & 11 deletions Sentaur.Leaderboard.Api/LeaderboardContext.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Sentaur.Leaderboard.Api;

public class LeaderboardContext : DbContext
public class LeaderboardContext(DbContextOptions<LeaderboardContext> options) : DbContext(options)
{
public DbSet<ScoreEntry> ScoreEntries { get; set; } = null!;

private string _dbPath;

public LeaderboardContext()
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
_dbPath = Path.Join(path, "scores.db");
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
Expand All @@ -24,5 +16,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}

protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={_dbPath}");
=> options.UseNpgsql();

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder
.Properties<DateTimeOffset>()
.HaveConversion<DateTimeOffsetConverter>();
}
}

public class DateTimeOffsetConverter()
: ValueConverter<DateTimeOffset, DateTimeOffset>(d => d.ToUniversalTime(),
d => d.ToUniversalTime());

This file was deleted.

39 changes: 0 additions & 39 deletions Sentaur.Leaderboard.Api/Migrations/20240301164227_NewKeyProp.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Sentaur.Leaderboard.Api.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand All @@ -15,14 +15,16 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "ScoreEntries",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
Duration = table.Column<TimeSpan>(type: "TEXT", nullable: false),
Score = table.Column<int>(type: "INTEGER", nullable: false),
Timestamp = table.Column<DateTimeOffset>(type: "TEXT", nullable: false)
Key = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Duration = table.Column<TimeSpan>(type: "interval", nullable: false),
Score = table.Column<int>(type: "integer", nullable: false),
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ScoreEntries", x => x.Key);
});
}

Expand Down
Loading

0 comments on commit 7276a72

Please sign in to comment.