Skip to content

Commit c687f8e

Browse files
authored
Merge pull request #12 from FlagBrew/back-to-sharp
Replace Python with C#
2 parents d693dfa + cc19632 commit c687f8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3606
-5789
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ ENV=
33
CONFIGURED=false
44
SESSION_KEY=
55
HTTP_VALIDATION_KEY=
6-
HTTP_ENCRYPTION_KEY=
6+
HTTP_ENCRYPTION_KEY=
7+
LOGGGING_SENTRY_DSN=https://sentry.io/...

.github/workflows/build.yml

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
name: build
1+
name: Build and Release
2+
23
on:
34
push:
4-
paths-ignore: [".gitignore", "**/*.md"]
5-
branches: [master]
6-
tags: ["*"]
5+
branches:
6+
- master
77

88
jobs:
9-
docker-publish-tags:
10-
if: contains(github.ref, 'refs/tags/v')
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/checkout@v2
14-
- uses: elgohr/Publish-Docker-Github-Action@master
15-
with:
16-
name: fmcore/coreapi
17-
username: ${{ secrets.DOCKER_USERNAME }}
18-
password: ${{ secrets.DOCKER_PASSWORD }}
19-
tag_semver: true
20-
docker-publish-latest:
21-
if: github.ref == 'refs/heads/master'
9+
build:
2210
runs-on: ubuntu-latest
11+
2312
steps:
24-
- uses: actions/checkout@v2
25-
- uses: elgohr/Publish-Docker-Github-Action@master
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Build Docker image
17+
run: |
18+
docker build -t myapp .
19+
20+
- name: Create container and extract
21+
run: |
22+
mkdir -p ./app
23+
docker create --name extract myapp
24+
docker cp extract:/app/coreapi ./app/coreapi
25+
docker cp extract:/app/cc ./app/cc
26+
docker rm extract
27+
- name: Archive release
28+
run: tar -czvf output.tar.gz ./app
29+
30+
- name: Create Release
31+
id: create_release
32+
uses: softprops/action-gh-release@v1
2633
with:
27-
name: fmcore/coreapi
28-
username: ${{ secrets.DOCKER_USERNAME }}
29-
password: ${{ secrets.DOCKER_PASSWORD }}
30-
post-to-webhook:
31-
needs: [docker-publish-latest]
32-
runs-on: ubuntu-latest
33-
steps:
34-
- run: |
35-
set +x
36-
curl -XPOST -H 'X-Webhook-Auth: ${{ secrets.WEBHOOK_SECRET }}' -H "Content-type: application/json" -d '{"app": "flagbrew", "service": "coreapi"}' '${{ secrets.WEBHOOK_URL }}'
34+
tag_name: run-${{ github.run_number }}-${{ github.sha }}
35+
name: Build ${{ github.sha }}
36+
draft: false
37+
prerelease: false
38+
files: output.tar.gz

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ tmp/
1313
**/dist
1414
**/.env
1515
bin
16-
coreapi
16+
coreapi
17+
cc/

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,27 @@ COPY . /build
77
RUN make go-build
88
RUN upx --best --lzma coreapi
99

10+
# build-cs-release image
11+
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-cs-release
12+
WORKDIR /build
13+
14+
COPY . /build
15+
RUN apt-get update && apt-get install --assume-yes make
16+
RUN make cs-build-release
17+
18+
1019
# Run image
1120
FROM python:3
1221
RUN apt update && \
1322
apt install mono-complete -y
1423

1524
RUN mkdir /app
1625
RUN mkdir /data
17-
RUN mkdir /app/python
26+
RUN mkdir /app/css
1827
COPY --from=build-go /build/coreapi /app
19-
COPY --from=build-go /build/python /app/python
2028
COPY --from=build-go /build/start.sh /app
2129
COPY --from=build-go /build/.env.example /data/.env
30+
COPY --from=build-cs-release /build/cc /app/cc
2231

2332
# runtime params
2433
WORKDIR /app

Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ export PACKAGE := "github.com/FlagBrew/CoreAPI"
66
VERSION=$(shell git describe --tags --always --abbrev=0 --match=v* 2> /dev/null | sed -r "s:^v::g" || echo 0)
77
VERSION_FULL=$(shell git describe --tags --always --dirty --match=v* 2> /dev/null | sed -r "s:^v::g" || echo 0)
88

9+
build-all: cs-build-release go-build
10+
911
# General
10-
clean:
12+
clean: cs-clean
1113
/bin/rm -rfv ${PROJECT}
1214

1315

16+
1417
# Docker
1518
docker:
1619
docker compose \
@@ -36,9 +39,21 @@ docker-build:
3639
--force-rm .
3740

3841

39-
# Python
40-
python-fetch:
41-
python3 -m pip install -r python/requirements.txt
42+
# CSharp
43+
44+
cs-build-release:
45+
cd coreconsole && \
46+
dotnet build coreconsole.csproj -c Release -o ../cc && \
47+
cp data ../cc/data -r
48+
49+
50+
cs-build-debug:
51+
cd coreconsole && \
52+
dotnet build coreconsole.csproj -c Debug -o ../cc && \
53+
cp data ../cc/data -r
54+
55+
cs-clean:
56+
/bin/rm -rfv cc
4257

4358
# Go
4459
go-fetch:

coreconsole/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Common IntelliJ Platform excludes
2+
3+
# User specific
4+
**/.idea/**/workspace.xml
5+
**/.idea/**/tasks.xml
6+
**/.idea/shelf/*
7+
**/.idea/dictionaries
8+
**/.idea/httpRequests/
9+
10+
# Sensitive or high-churn files
11+
**/.idea/**/dataSources/
12+
**/.idea/**/dataSources.ids
13+
**/.idea/**/dataSources.xml
14+
**/.idea/**/dataSources.local.xml
15+
**/.idea/**/sqlDataSources.xml
16+
**/.idea/**/dynamic.xml
17+
18+
# Rider
19+
# Rider auto-generates .iml files, and contentModel.xml
20+
**/.idea/**/*.iml
21+
**/.idea/**/contentModel.xml
22+
**/.idea/**/modules.xml
23+
24+
*.suo
25+
*.user
26+
.vs/
27+
[Bb]in/
28+
[Oo]bj/
29+
_UpgradeReport_Files/
30+
[Pp]ackages/
31+
32+
Thumbs.db
33+
Desktop.ini
34+
.DS_Store

coreconsole/.idea/.idea.coreconsole/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coreconsole/.idea/.idea.coreconsole/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coreconsole/.idea/.idea.coreconsole/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coreconsole/.idea/.idea.coreconsole/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coreconsole/Program.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using System.CommandLine;
4+
using System.Text.Json;
5+
using coreconsole.handlers;
6+
using coreconsole.utils;
7+
using PKHeX.Core;
8+
using Sentry;
9+
using Version = coreconsole.Models.Version;
10+
11+
namespace coreconsole;
12+
13+
public static class MainClass
14+
{
15+
public static void Main(string[] args)
16+
{
17+
if (!Helpers.LoadEnv()) Environment.Exit((int)enums.ExitCode.EnvNotConfigured);
18+
19+
using (SentrySdk.Init(o => { o.Dsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); }))
20+
{
21+
var pokemonArg = new Argument<string>(
22+
"pokemon",
23+
"The pokemon file (in base64 format)."
24+
);
25+
26+
var generationOption = new Option<EntityContext?>(
27+
"--generation",
28+
"Used to determine desired generation when generation could be 6/7 or 8/8b"
29+
);
30+
31+
var cmd1 = new Command("summary", "Returns the summary for a given pokemon.")
32+
{
33+
pokemonArg,
34+
generationOption
35+
};
36+
cmd1.SetHandler(Summary.SummaryHandler, pokemonArg, generationOption);
37+
38+
var cmd2 = new Command("legality", "Returns the legality status for a Pokemon, including what checks fail.")
39+
{
40+
pokemonArg,
41+
generationOption
42+
};
43+
44+
cmd2.SetHandler(Legality.LegalityCheckHandler, pokemonArg, generationOption);
45+
46+
var legalizationGenerationOverride = new Option<int?>("--legalization-generation",
47+
"Forces the legalized Pokemon to use the provided generation (may cause legalization to fail).");
48+
49+
var legalizationGameVersionOverride = new Option<GameVersion?>("--version",
50+
"Game Version to use in trying to legalize the Pokemon (may cause legalization to fail).");
51+
52+
var cmd3 = new Command("legalize", "Attempts to auto legalize a pokemon and returns it if successful.")
53+
{
54+
pokemonArg,
55+
generationOption,
56+
legalizationGenerationOverride,
57+
legalizationGameVersionOverride
58+
};
59+
cmd3.SetHandler(Legality.LegalizeHandler, pokemonArg, generationOption,
60+
legalizationGenerationOverride, legalizationGameVersionOverride);
61+
62+
var cmd4 = new Command("version", "Returns the version for ALM/PKHeX");
63+
cmd4.SetHandler(() => { Console.WriteLine(JsonSerializer.Serialize(new Version())); });
64+
65+
var cli = new RootCommand("CoreConsole - a tool for interacting with PKHeX and Auto Legality via CLI.")
66+
{
67+
cmd1,
68+
cmd2,
69+
cmd3,
70+
cmd4
71+
};
72+
cli.Invoke(args);
73+
}
74+
75+
Environment.Exit((int)enums.ExitCode.Success);
76+
}
77+
}

coreconsole/Tests/AutoLegalityTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using coreconsole.handlers;
2+
using coreconsole.utils;
3+
using PKHeX.Core;
4+
5+
namespace Tests;
6+
7+
[TestFixture]
8+
public class AutoLegalityTest
9+
{
10+
[SetUp]
11+
public void Setup()
12+
{
13+
Helpers.Init();
14+
}
15+
16+
[Test]
17+
public void CanAutoLegalizePokemon()
18+
{
19+
const string pkmnHex =
20+
"1a9b12b00000701626020000537e0c70d8000000467800020000000000000000000000000000000021003700fd00000023190a0000000000b9227415000000000a13000000000000420061007300630075006c0069006e00ffff0000ffff001400000000000000004400650073006d0075006e006400ffff00000017021000000e00000406000000";
21+
22+
var pkmnBytes = Helpers.StringToByteArray(pkmnHex);
23+
var pkmn = EntityFormat.GetFromBytes(pkmnBytes);
24+
Assert.That(pkmn, Is.Not.Null);
25+
// Check the legality first
26+
var legalityReport = Legality.CheckLegality(pkmn!);
27+
Assert.That(legalityReport.Valid, Is.False);
28+
29+
// Now try to auto legalize
30+
var pokemon = Legality.AutoLegalize(pkmn!);
31+
Assert.That(pokemon, Is.Not.Null);
32+
}
33+
}

0 commit comments

Comments
 (0)