Skip to content

Commit

Permalink
Merge pull request #7 from Fgruntjes/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
Fgruntjes authored Sep 27, 2022
2 parents ef5c4d7 + a7ddda5 commit 07925ab
Show file tree
Hide file tree
Showing 20 changed files with 309 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .github/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "serverless-personal-finance",
"description": "Personal finance application build on serverless cloud functions. Keeping running cost at a minimum while using high end hosting."
}
57 changes: 57 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Publish
on:
release:
types: [published]

jobs:
build_images:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ '6.0.x' ]
project: [ 'App.Function.Banktransaction.Import' ]
steps:
- uses: actions/checkout@v2
- uses: crazy-max/ghaction-docker-meta@v4
id: docker_meta
with:
images: ghcr.io/${{ github.repository }}/${{ matrix.project }}
- uses: docker/[email protected]
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max

deploy:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') && endsWith(github.ref, '${{ matrix.environment }}')
needs:
- build_images
permissions:
contents: 'read'
id-token: 'write'
strategy:
matrix:
project: [ 'App.Function.Banktransaction.Import' ]
environment: [ 'beta' ]
steps:
- uses: 'actions/checkout@v3'
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
- id: 'deploy'
uses: 'google-github-actions/deploy-cloudrun@v0'
with:
metadata: '${{ matrix.project }}'
env_vars: 'DEPLOY_ENV=${{ matrix.environment }}'
25 changes: 25 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release
on:
push:
branches:
- main
- master
- alpha
- beta

jobs:
release:
runs-on: ubuntu-20.04
steps:
- uses: actions/setup-node@v2
with:
node-version: '14'
- uses: actions/checkout@v2
with:
persist-credentials: false
- uses: cycjimmy/semantic-release-action@v3
with:
semantic_version: 19
working_directory: "./.github"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49 changes: 49 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test
on:
pull_request:

jobs:
#########################################################
# Code quality and unit tests
#########################################################
test_quality:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ '6.0.x' ]
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ matrix.dotnet-version }}
- uses: kkak10/[email protected]
id: PRNUMBER
- run: |
echo "file_name=FormatReport.${{ matrix.dotnet-version }}.${{steps.PRNUMBER.outputs.pr}}.${{github.run_number}}.json" >> $GITHUB_ENV
- run: dotnet format --verify-no-changes

test_integration:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ '6.0.x' ]
project: [ 'App.Function.Banktransaction.Import.Tests' ]
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ matrix.dotnet-version }}
- uses: kkak10/[email protected]
id: PRNUMBER
- run: |
echo "title=Test Run for PR #${{steps.PRNUMBER.outputs.pr}} (${{github.run_number}})" >> $GITHUB_ENV
echo "file_name=TestReport.${{ matrix.dotnet-version }}.${{ matrix.project }}.${{steps.PRNUMBER.outputs.pr}}.${{github.run_number}}.md" >> $GITHUB_ENV
- run: dotnet restore ${{ matrix.project }}
- run: dotnet build --no-restore ${{ matrix.project }}
- run: dotnet test --no-restore --no-build --logger "liquid.md;LogFileName=${{github.workspace}}/${{env.file_name}};Title=${{env.title}};" ${{ matrix.project }}
- uses: marocchino/sticky-pull-request-comment@v2
if: ${{always()}}
with:
path: ${{github.workspace}}/${{env.file_name}}
12 changes: 5 additions & 7 deletions .github/.releaserc.json → .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"release": {
"branches": [
"main",
{ "name": "beta", "prerelease": true }
]
},
"branches": [
"main",
{ "name": "beta", "prerelease": true }
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
Expand All @@ -21,4 +19,4 @@
}
]
]
}
}
1 change: 1 addition & 0 deletions App.Function.Banktransaction.Import.Tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TestResults/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="LiquidTestReports.Markdown" Version="1.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\App.Function.Banktransaction.Import\App.Function.Banktransaction.Import.csproj" />
<ProjectReference Include="..\App.TestsLib\App.TestsLib.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Net;
using System.Net.Http.Json;
using App.Lib.Dto;
using App.TestsLib;

namespace App.Function.Banktransaction.Import.Tests.Controller;

public class AppControllerTest : IntegrationTestFixture<Program>
{
public AppControllerTest(TestApplicationFactory<Program> factory) : base(factory)
{
}

[Fact]
public async void PostAndWaitForDatabase()
{
var values = new BankTransaction[]
{
new()
{
Account = "Some Account",
Category = "Clothing",
Date = new DateTime(2022, 10, 4),
Payee = "SomeStore",
Value = 220,
CurrencyCode = "EUR",
}
};
using var response = await _client.PostAsJsonAsync("/", values);
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
}
}
1 change: 1 addition & 0 deletions App.Function.Banktransaction.Import.Tests/src/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
6 changes: 3 additions & 3 deletions App.Function.Banktransaction.Import/service.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: personal-finance-banktransaction-import
name: ${DEPLOY_ENV}.import
spec:
template:
spec:
containerConcurrency: 10
containerConcurrency: 1
containers:
- image: europe-central2-docker.pkg.dev/serverless-personal-finance/banktransaction/import:dev-3
- image: ${IMAGE_TAG}
resources:
limits:
cpu: "1"
Expand Down
4 changes: 4 additions & 0 deletions App.Function.Banktransaction.Import/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
var app = builder.Build();
app.MapControllers();
app.Run();

public partial class Program
{
}
10 changes: 5 additions & 5 deletions App.Job.Import.Ynab/src/Command/ImportTransactionsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public sealed class Settings : CommandSettings
[CommandArgument(0, "<auth_token>")]
[Description("Personal access token or file containing token")]
public string AuthToken { get; init; }

[CommandOption("-d|--dry-run")]
[DefaultValue(false)]
public bool DryRun { get; init; }

[CommandOption("-e|--ynab-endpoint")]
[DefaultValue("https://api.youneedabudget.com")]
public string YnabEndpoint { get; init; }

[CommandOption("-a|--data-endpoint")]
[DefaultValue("https://asset-management.gruntjes.net")]
public string DataEndpoint { get; init; }
Expand All @@ -30,14 +30,14 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Settings
{
return 0;
}

private string? GetFileContentOrValue(string value)
{
if (!File.Exists(value))
{
return value;
}

try
{
return File.ReadAllText(value);
Expand Down
10 changes: 5 additions & 5 deletions App.Lib/src/Dto/BankTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ public class BankTransaction
{
[Description("If none provided id will be generated from all fields")]
public string? TransactionId { get; set; }

[BindRequired]
public DateTime Date { get; set; }

[BindRequired]
public string Category { get; set; }

[BindRequired]
public string Payee { get; set; }

[BindRequired]
public string Account { get; set; }

[BindRequired]
[Description("ISO 4217:2015 (ISO-3) currency code")]
public string CurrencyCode { get; set; }

[BindRequired]
public Decimal Value { get; set; }
}
2 changes: 1 addition & 1 deletion App.Lib/src/Message/BankTransactionImportMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace App.Lib.Message;
public class BankTransactionImportMessage
{
public IList<BankTransaction> Transactions { get; }

public BankTransactionImportMessage(IList<BankTransaction> transactions)
{
Transactions = transactions;
Expand Down
26 changes: 26 additions & 0 deletions App.TestsLib/App.TestsLib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Mvc.Testing">
<HintPath>..\..\..\..\..\.nuget\packages\microsoft.aspnetcore.mvc.testing\6.0.9\lib\net6.0\Microsoft.AspNetCore.Mvc.Testing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Hosting.Abstractions">
<HintPath>..\..\..\..\..\.nuget\packages\microsoft.extensions.hosting.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.core">
<HintPath>..\..\..\..\..\.nuget\packages\xunit.extensibility.core\2.4.2\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.9" />
<PackageReference Include="xunit" Version="2.4.2" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions App.TestsLib/src/IntegrationTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Xunit;

namespace App.TestsLib;

public class IntegrationTestFixture<TEntryPoint> : IClassFixture<TestApplicationFactory<TEntryPoint>> where TEntryPoint : class
{
protected readonly TestApplicationFactory<TEntryPoint> _factory;
protected readonly HttpClient _client;

public IntegrationTestFixture(TestApplicationFactory<TEntryPoint> factory)
{
_factory = factory;
_client = factory.CreateClient();
}
}
Loading

0 comments on commit 07925ab

Please sign in to comment.