Skip to content

Commit c6fd401

Browse files
authored
feat: aot (#6)
1 parent 9d86fe4 commit c6fd401

12 files changed

Lines changed: 358 additions & 171 deletions

File tree

.github/workflows/release.yml

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,66 @@ on:
66
- '*'
77

88
jobs:
9-
release:
9+
10+
create-draft:
1011
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v5
14+
- run: gh release create ${{ github.ref_name }} --draft --title "${{ github.ref_name }}"
15+
env:
16+
GH_TOKEN: ${{ github.token }}
17+
publish-exes:
18+
strategy:
19+
matrix:
20+
include:
21+
- os: ubuntu-latest
22+
osid: linux
23+
- os: windows-latest
24+
osid: win
25+
- os: macos-latest
26+
osid: osx
27+
28+
runs-on: ${{ matrix.os }}
1129
env:
1230
VERSION: ${{ github.ref_name }}
31+
steps:
32+
- name: Checkout source repo
33+
uses: actions/checkout@v5
1334

35+
- uses: actions/setup-dotnet@v5
36+
with:
37+
dotnet-version: '10.0.x'
38+
39+
- name: Publish executables (Windows)
40+
if: matrix.os == 'windows-latest'
41+
run: ./publish.ps1 ${{env.VERSION}} ${{ secrets.STORAGE_APIKEY }} ${{ matrix.osid }}
42+
shell: pwsh
43+
env:
44+
VERSION: ${{ env.VERSION }}
45+
GH_TOKEN: ${{ github.token }}
46+
47+
- name: Publish executables (Linux/macOS)
48+
if: matrix.os != 'windows-latest'
49+
run: ./publish.sh ${{env.VERSION}} ${{ secrets.STORAGE_APIKEY }} ${{ matrix.osid }}
50+
shell: bash
51+
env:
52+
VERSION: ${{ env.VERSION }}
53+
GH_TOKEN: ${{ github.token }}
54+
55+
publish-nuget:
56+
runs-on: ubuntu-latest
57+
env:
58+
VERSION: ${{ github.ref_name }}
1459
steps:
1560
- name: Checkout source repo
1661
uses: actions/checkout@v5
1762

18-
- uses: actions/setup-dotnet@v4
63+
- uses: actions/setup-dotnet@v5
1964
with:
2065
dotnet-version: '10.0.x'
2166

22-
- name: Publish script
23-
run: ./publish.sh ${{env.VERSION}} ${{ secrets.STORAGE_APIKEY }} ${{ secrets.NUGET_APIKEY }}
67+
- name: Publish NuGet tool
68+
run: ./publish-nuget.sh ${{env.VERSION}} ${{ secrets.NUGET_APIKEY }}
2469
env:
2570
VERSION: ${{ env.VERSION }}
2671
GH_TOKEN: ${{ github.token }}

app/Commands/Root.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[RegisterCommands]
2+
internal class Root
3+
{
4+
[ConsoleAppFilter<AddStdinToContext>]
5+
[Command("")]
6+
public async Task ThisWeekOrLoginRequriredCommand(ConsoleAppContext ctx, CancellationToken token)
7+
{
8+
if(ctx.Arguments.Length > 0)
9+
{
10+
Console.MarkupLine($"""
11+
[red]Wah?[/] Forstod ikke '{string.Join(" ", ctx.Arguments)}`
12+
Prøv [green]`tim -h|--help[/]`.
13+
""");
14+
return;
15+
}
16+
17+
var session = await UserSecretsManager.GetFloqSession(token);
18+
19+
if(session is { IsExpired: true })
20+
{
21+
session = await UserSecretsManager.RefreshFloqSession(token);
22+
if(session is null)
23+
{
24+
Console.MarkupLine("[red] Sesjon utløpt.[/] Vennligst logg inn på nytt med [green]`tim login`.[/]");
25+
return;
26+
}
27+
}
28+
29+
if(session is { IsExpired: false })
30+
{
31+
var newCtx = ctx with { State = new GlobalState(session) };
32+
await Time.ListPeriod(newCtx, SelectedRange.CurrentWeek, ct: token);
33+
return;
34+
}
35+
36+
Console.Write(
37+
new FigletText("tim")
38+
.Color(Color.Purple));
39+
40+
Console.MarkupLine($"[dim] v{AppInfoHelper.App.MajorMinorPatch}[/]");
41+
Console.MarkupLine($"[dim] {AppInfoHelper.App.Informational}[/]");
42+
Console.MarkupLine("""
43+
[]
44+
Velkommen til tim. Kom igang med
45+
- [green] `tim login`[/].
46+
- [green] `tim -h|--help[/]`.
47+
[/]
48+
""");
49+
var wantToLogin = new ConfirmationPrompt("Logge inn?").ShowDefaultValue(true);
50+
var yesPlz = Console.Prompt(wantToLogin);
51+
if(yesPlz)
52+
{
53+
await Authentications.LoginImpl(token);
54+
}
55+
else
56+
{
57+
Console.MarkupLine("[dim]np, tar det senere[/]");
58+
}
59+
}
60+
}

app/Helpers/Auth/JwtHelper.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/Helpers/Auth/UserSecretsManager.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Reflection;
44
using System.Text.Json;
55
using System.Text.Json.Serialization;
6-
using Microsoft.Extensions.Configuration.UserSecrets;
6+
77

88
public class UserSecretsManager
99
{
@@ -85,7 +85,7 @@ public static async Task StoreDefaultProject(UserDefaultedProject? value, Cancel
8585
}
8686
else
8787
{
88-
secrets["DefaultProject"] = JsonSerializer.Serialize(value);
88+
secrets["DefaultProject"] = JsonSerializer.Serialize(value, UserSecretsJsonSerializerContext.Default.UserDefaultedProject);
8989
}
9090

9191
var secretsJson = ToJson(secrets);
@@ -103,7 +103,7 @@ public static async Task StoreDefaultProject(UserDefaultedProject? value, Cancel
103103

104104
try
105105
{
106-
if(JsonSerializer.Deserialize<UserDefaultedProject>(projectJson) is { } project)
106+
if(JsonSerializer.Deserialize<UserDefaultedProject>(projectJson, UserSecretsJsonSerializerContext.Default.UserDefaultedProject) is { } project)
107107
{
108108
return project;
109109
}
@@ -144,7 +144,7 @@ public static string GetAppDataPath()
144144
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
145145
"blank",
146146
"tim",
147-
Assembly.GetExecutingAssembly().GetCustomAttribute<UserSecretsIdAttribute>()!.UserSecretsId,
147+
"tim-deploy",
148148
"secrets.json");
149149

150150
return path;
@@ -198,15 +198,15 @@ private static string EscapeJsonString(string value)
198198
}
199199

200200
var response = await AuthClient.PostAsJsonAsync("/login/oauth/refresh",
201-
new { refresh_token = currentSession.RefreshToken }, token);
201+
new RefreshTokenRequest(currentSession.RefreshToken), UserSecretsJsonSerializerContext.Default.RefreshTokenRequest, token);
202202

203203
if(!response.IsSuccessStatusCode)
204204
{
205205
Console.WriteLine("Unable to refresh session");
206206
return null;
207207
}
208208

209-
var refreshResponse = await response.Content.ReadFromJsonAsync<RefreshTokenResponse>(token);
209+
var refreshResponse = await response.Content.ReadFromJsonAsync<RefreshTokenResponse>(UserSecretsJsonSerializerContext.Default.RefreshTokenResponse,token);
210210
if(refreshResponse == null)
211211
{
212212
return null;
@@ -226,12 +226,6 @@ private static string EscapeJsonString(string value)
226226
return await GetFloqSession(token);
227227
}
228228

229-
private record RefreshTokenResponse(
230-
[property: JsonPropertyName("access_token")]
231-
string AccessToken,
232-
[property: JsonPropertyName("expiry_date")]
233-
string ExpiryDate);
234-
235229
public static async Task RemoveFloqSession(CancellationToken token)
236230
{
237231
var secretsPath = GetAppDataPath();
@@ -283,7 +277,28 @@ public string ExpireInFriendly
283277
}
284278
}
285279

280+
public record RefreshTokenRequest(
281+
[property: JsonPropertyName("refresh_token")]
282+
string RefreshToken);
283+
284+
public record RefreshTokenResponse(
285+
[property: JsonPropertyName("access_token")]
286+
string AccessToken,
287+
[property: JsonPropertyName("expiry_date")]
288+
string ExpiryDate);
289+
286290
// Stored as JSON in file, nb, be backwards compatitble
287291
public record UserDefaultedProject(string Id, string Project, string Customer, string CustomerId);
288292

289293
public record ImplicitCallbackData(string AccessToken, string ExpireDate, string RefreshToken, string UserEmail);
294+
295+
[JsonSourceGenerationOptions(
296+
PropertyNameCaseInsensitive = true,
297+
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase
298+
)]
299+
[JsonSerializable(typeof(UserDefaultedProject))]
300+
[JsonSerializable(typeof(RefreshTokenRequest))]
301+
[JsonSerializable(typeof(RefreshTokenResponse))]
302+
internal partial class UserSecretsJsonSerializerContext : JsonSerializerContext
303+
{
304+
}

0 commit comments

Comments
 (0)