Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dashboard providing obsolete action information #2042

Merged
merged 35 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b934726
Add obsoleteOnly and jsonPath options for action list command
XxshiftxX Jul 21, 2023
e990da1
Add exported obsolete-action file
XxshiftxX Jul 21, 2023
9bf51e3
Add dashboard project
XxshiftxX Jul 24, 2023
1661e67
Install tailwind
XxshiftxX Jul 24, 2023
5d970d2
Set default font to Pretendard
XxshiftxX Jul 24, 2023
746242a
Add env variables
XxshiftxX Jul 24, 2023
020583d
Add react-query
XxshiftxX Jul 24, 2023
984acc9
Add code for loading currentBlock and actions data
XxshiftxX Jul 24, 2023
a791cbd
Remove default styles
XxshiftxX Jul 24, 2023
f8fd42c
Implement dashboard
XxshiftxX Jul 24, 2023
3c85d7d
Add gh-action script for deploy gh-pages
XxshiftxX Jul 28, 2023
1de5bf8
Merge branch 'development' into add-obsolete-action-command
XxshiftxX Jul 31, 2023
e959c53
Merge branch 'development' into add-obsolete-action-command
moreal Aug 2, 2023
4fba8b4
Change dashboard title
XxshiftxX Aug 2, 2023
e22ba42
Move gh-pages into devDependencies
XxshiftxX Aug 2, 2023
84176eb
Fix obsoleteOnly option's description
XxshiftxX Aug 2, 2023
f1bc72b
Replace default README.md with right contents
XxshiftxX Aug 2, 2023
c544d94
Add example .env file
XxshiftxX Aug 3, 2023
03584cf
Add gh-action for deploing gh pages
XxshiftxX Aug 3, 2023
2b6f233
Fix lint
XxshiftxX Aug 3, 2023
17a9786
Fix indent
XxshiftxX Aug 3, 2023
fb18783
Add working-directory on gh-actions
XxshiftxX Aug 3, 2023
c9df134
Set homepage of github action
XxshiftxX Aug 3, 2023
7d4f149
Change gh-pages destination dir
XxshiftxX Aug 3, 2023
90c8d9c
Change package.json homepage
XxshiftxX Aug 3, 2023
94692a2
Fix base url on vite config
XxshiftxX Aug 3, 2023
b539e1c
Fix .env file name
XxshiftxX Aug 3, 2023
07f7695
Set working-directory for .env building
XxshiftxX Aug 3, 2023
2c9b0b4
Fix secret syntax
XxshiftxX Aug 3, 2023
fa820e8
Fix typo
XxshiftxX Aug 3, 2023
446600c
Restore deleted gh-pages publish code
XxshiftxX Aug 3, 2023
6ed0b0f
Make latest destination for gh-pages
XxshiftxX Aug 3, 2023
be96425
Delete unused file
XxshiftxX Aug 3, 2023
ff18207
Fix gh actions target branch
XxshiftxX Aug 3, 2023
95e74ba
Merge branch 'development' into add-obsolete-action-command
XxshiftxX Aug 4, 2023
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
56 changes: 44 additions & 12 deletions .Lib9c.Tools/SubCommand/Action.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.Json.Nodes;
using Bencodex.Types;
using Cocona;
using Cocona.Help;
Expand All @@ -14,6 +16,12 @@ public class Action
[Obsolete("This function is deprecated. Please use `NineChronicles.Headless.Executable action list` command instead.")]
[Command(Description = "Lists all actions' type ids.")]
public void List(
[Option(
Description = "If true, show obsoleted actions only"
)] bool obsoleteOnly = false,
[Option(
Description = "If true, make json file with results"
)] string jsonPath = null,
[Option(
Description = "If true, filter obsoleted actions since the --block-index option."
)] bool excludeObsolete = false,
Expand All @@ -22,29 +30,53 @@ public void List(
)] long blockIndex = 0
)
{
Type baseType = typeof(Nekoyume.Action.ActionBase);
var baseType = typeof(ActionBase);

bool IsTarget(Type type)
{
return baseType.IsAssignableFrom(type) &&
type.GetCustomAttribute<ActionTypeAttribute>() is { } &&
(
!excludeObsolete ||
!(type.GetCustomAttribute<ActionObsoleteAttribute>() is { } aoAttr) ||
aoAttr.ObsoleteIndex > blockIndex
);
if (!baseType.IsAssignableFrom(type) ||
type.GetCustomAttribute<ActionTypeAttribute>() is null)
{
return false;
}

var isObsoleteTarget = type.GetCustomAttribute<ActionObsoleteAttribute>() is not null;
var isObsolete = type.GetCustomAttribute<ActionObsoleteAttribute>() is { } attr &&
attr.ObsoleteIndex <= blockIndex;

if (obsoleteOnly) return isObsoleteTarget;
XxshiftxX marked this conversation as resolved.
Show resolved Hide resolved
if (excludeObsolete) return !isObsolete;

return true;
}

var assembly = baseType.Assembly;
var typeIds = assembly.GetTypes()
.Where(IsTarget)
.Select(type => type.GetCustomAttribute<ActionTypeAttribute>()?.TypeIdentifier)
.OfType<Text>()
.OrderBy(type => type);
.Select(type => ((IValue typeId, long? obsoleteAt))(
type.GetCustomAttribute<ActionTypeAttribute>()?.TypeIdentifier,
type.GetCustomAttribute<ActionObsoleteAttribute>()?.ObsoleteIndex
))
.Where(type => type.typeId is Text)
.OrderBy(type => ((Text)type.typeId).Value);

var jsonResult = new JsonArray();

foreach (var (typeIdValue, obsoleteAt) in typeIds)
{
var typeId = (Text)typeIdValue;
var json = new JsonObject { ["id"] = typeId.Value };
if (obsoleteAt != null) json.Add("obsoleteAt", obsoleteAt);
jsonResult.Add(json);

foreach (Text typeId in typeIds) {
Console.WriteLine(typeId.Value);
}

if (jsonPath != null)
{
using var stream = File.CreateText(jsonPath);
stream.WriteLine(jsonResult.ToString());
}
}

[PrimaryCommand]
Expand Down
Loading
Loading