Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ENV=
CONFIGURED=false
SESSION_KEY=
HTTP_VALIDATION_KEY=
HTTP_ENCRYPTION_KEY=
HTTP_ENCRYPTION_KEY=
LOGGGING_SENTRY_DSN=https://sentry.io/...
60 changes: 31 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
name: build
name: Build and Release

on:
push:
paths-ignore: [".gitignore", "**/*.md"]
branches: [master]
tags: ["*"]
branches:
- master

jobs:
docker-publish-tags:
if: contains(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: elgohr/Publish-Docker-Github-Action@master
with:
name: fmcore/coreapi
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tag_semver: true
docker-publish-latest:
if: github.ref == 'refs/heads/master'
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: elgohr/Publish-Docker-Github-Action@master
- name: Checkout code
uses: actions/checkout@v3

- name: Build Docker image
run: |
docker build -t myapp .

- name: Create container and extract
run: |
mkdir -p ./app
docker create --name extract myapp
docker cp extract:/app/coreapi ./app/coreapi
docker cp extract:/app/cc ./app/cc
docker rm extract
- name: Archive release
run: tar -czvf output.tar.gz ./app

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
name: fmcore/coreapi
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
post-to-webhook:
needs: [docker-publish-latest]
runs-on: ubuntu-latest
steps:
- run: |
set +x
curl -XPOST -H 'X-Webhook-Auth: ${{ secrets.WEBHOOK_SECRET }}' -H "Content-type: application/json" -d '{"app": "flagbrew", "service": "coreapi"}' '${{ secrets.WEBHOOK_URL }}'
tag_name: run-${{ github.run_number }}-${{ github.sha }}
name: Build ${{ github.sha }}
draft: false
prerelease: false
files: output.tar.gz
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tmp/
**/dist
**/.env
bin
coreapi
coreapi
cc/
8 changes: 8 additions & 0 deletions .idea/.gitignore

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@ COPY . /build
RUN make go-build
RUN upx --best --lzma coreapi

# build-cs-release image
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-cs-release
WORKDIR /build

COPY . /build
RUN apt-get update && apt-get install --assume-yes make
RUN make cs-build-release


# Run image
FROM python:3
RUN apt update && \
apt install mono-complete -y

RUN mkdir /app
RUN mkdir /data
RUN mkdir /app/python
RUN mkdir /app/css
COPY --from=build-go /build/coreapi /app
COPY --from=build-go /build/python /app/python
COPY --from=build-go /build/start.sh /app
COPY --from=build-go /build/.env.example /data/.env
COPY --from=build-cs-release /build/cc /app/cc

# runtime params
WORKDIR /app
Expand Down
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ export PACKAGE := "github.com/FlagBrew/CoreAPI"
VERSION=$(shell git describe --tags --always --abbrev=0 --match=v* 2> /dev/null | sed -r "s:^v::g" || echo 0)
VERSION_FULL=$(shell git describe --tags --always --dirty --match=v* 2> /dev/null | sed -r "s:^v::g" || echo 0)

build-all: cs-build-release go-build

# General
clean:
clean: cs-clean
/bin/rm -rfv ${PROJECT}



# Docker
docker:
docker compose \
Expand All @@ -36,9 +39,21 @@ docker-build:
--force-rm .


# Python
python-fetch:
python3 -m pip install -r python/requirements.txt
# CSharp

cs-build-release:
cd coreconsole && \
dotnet build coreconsole.csproj -c Release -o ../cc && \
cp data ../cc/data -r


cs-build-debug:
cd coreconsole && \
dotnet build coreconsole.csproj -c Debug -o ../cc && \
cp data ../cc/data -r

cs-clean:
/bin/rm -rfv cc

# Go
go-fetch:
Expand Down
34 changes: 34 additions & 0 deletions coreconsole/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Common IntelliJ Platform excludes

# User specific
**/.idea/**/workspace.xml
**/.idea/**/tasks.xml
**/.idea/shelf/*
**/.idea/dictionaries
**/.idea/httpRequests/

# Sensitive or high-churn files
**/.idea/**/dataSources/
**/.idea/**/dataSources.ids
**/.idea/**/dataSources.xml
**/.idea/**/dataSources.local.xml
**/.idea/**/sqlDataSources.xml
**/.idea/**/dynamic.xml

# Rider
# Rider auto-generates .iml files, and contentModel.xml
**/.idea/**/*.iml
**/.idea/**/contentModel.xml
**/.idea/**/modules.xml

*.suo
*.user
.vs/
[Bb]in/
[Oo]bj/
_UpgradeReport_Files/
[Pp]ackages/

Thumbs.db
Desktop.ini
.DS_Store
13 changes: 13 additions & 0 deletions coreconsole/.idea/.idea.coreconsole/.idea/.gitignore

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

4 changes: 4 additions & 0 deletions coreconsole/.idea/.idea.coreconsole/.idea/encodings.xml

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

8 changes: 8 additions & 0 deletions coreconsole/.idea/.idea.coreconsole/.idea/indexLayout.xml

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

6 changes: 6 additions & 0 deletions coreconsole/.idea/.idea.coreconsole/.idea/vcs.xml

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

77 changes: 77 additions & 0 deletions coreconsole/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// See https://aka.ms/new-console-template for more information

using System.CommandLine;
using System.Text.Json;
using coreconsole.handlers;
using coreconsole.utils;
using PKHeX.Core;
using Sentry;
using Version = coreconsole.Models.Version;

namespace coreconsole;

public static class MainClass
{
public static void Main(string[] args)
{
if (!Helpers.LoadEnv()) Environment.Exit((int)enums.ExitCode.EnvNotConfigured);

using (SentrySdk.Init(o => { o.Dsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); }))
{
var pokemonArg = new Argument<string>(
"pokemon",
"The pokemon file (in base64 format)."
);

var generationOption = new Option<EntityContext?>(
"--generation",
"Used to determine desired generation when generation could be 6/7 or 8/8b"
);

var cmd1 = new Command("summary", "Returns the summary for a given pokemon.")
{
pokemonArg,
generationOption
};
cmd1.SetHandler(Summary.SummaryHandler, pokemonArg, generationOption);

var cmd2 = new Command("legality", "Returns the legality status for a Pokemon, including what checks fail.")
{
pokemonArg,
generationOption
};

cmd2.SetHandler(Legality.LegalityCheckHandler, pokemonArg, generationOption);

var legalizationGenerationOverride = new Option<int?>("--legalization-generation",
"Forces the legalized Pokemon to use the provided generation (may cause legalization to fail).");

var legalizationGameVersionOverride = new Option<GameVersion?>("--version",
"Game Version to use in trying to legalize the Pokemon (may cause legalization to fail).");

var cmd3 = new Command("legalize", "Attempts to auto legalize a pokemon and returns it if successful.")
{
pokemonArg,
generationOption,
legalizationGenerationOverride,
legalizationGameVersionOverride
};
cmd3.SetHandler(Legality.LegalizeHandler, pokemonArg, generationOption,
legalizationGenerationOverride, legalizationGameVersionOverride);

var cmd4 = new Command("version", "Returns the version for ALM/PKHeX");
cmd4.SetHandler(() => { Console.WriteLine(JsonSerializer.Serialize(new Version())); });

var cli = new RootCommand("CoreConsole - a tool for interacting with PKHeX and Auto Legality via CLI.")
{
cmd1,
cmd2,
cmd3,
cmd4
};
cli.Invoke(args);
}

Environment.Exit((int)enums.ExitCode.Success);
}
}
33 changes: 33 additions & 0 deletions coreconsole/Tests/AutoLegalityTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using coreconsole.handlers;
using coreconsole.utils;
using PKHeX.Core;

namespace Tests;

[TestFixture]
public class AutoLegalityTest
{
[SetUp]
public void Setup()
{
Helpers.Init();
}

[Test]
public void CanAutoLegalizePokemon()
{
const string pkmnHex =
"1a9b12b00000701626020000537e0c70d8000000467800020000000000000000000000000000000021003700fd00000023190a0000000000b9227415000000000a13000000000000420061007300630075006c0069006e00ffff0000ffff001400000000000000004400650073006d0075006e006400ffff00000017021000000e00000406000000";

var pkmnBytes = Helpers.StringToByteArray(pkmnHex);
var pkmn = EntityFormat.GetFromBytes(pkmnBytes);
Assert.That(pkmn, Is.Not.Null);
// Check the legality first
var legalityReport = Legality.CheckLegality(pkmn!);
Assert.That(legalityReport.Valid, Is.False);

// Now try to auto legalize
var pokemon = Legality.AutoLegalize(pkmn!);
Assert.That(pokemon, Is.Not.Null);
}
}
Loading