-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
Replace Python with C#
- Loading branch information
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ tmp/ | |
**/dist | ||
**/.env | ||
bin | ||
coreapi | ||
coreapi | ||
cc/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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); | ||
} | ||
} |