Skip to content

Commit

Permalink
Merge pull request #6 from steem-monsters/githubactions
Browse files Browse the repository at this point in the history
add actions
  • Loading branch information
farpetrad-sl authored Mar 2, 2024
2 parents 25acc4d + d9e39cc commit 9491951
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 47 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/CodeQL.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'csharp' ]

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
52 changes: 52 additions & 0 deletions .github/workflows/OpenPR.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: pull-request
on:
pull_request

jobs:
update-version:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore

- name: Bump version and push tag
id: bump-and-tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true

- name: version it
id: get-id
uses: actions/[email protected]
env:
DATA: ${{ steps.bump-and-tag.outputs.new_tag }}
with:
script: |
const id = process.env.DATA.split('v')[1]
core.setOutput('version', id)
- name: output
id: tag-and-version
run: echo "Output tag = ${{ steps.bump-and-tag.outputs.new_tag }} parsed = ${{ steps.get-id.outputs.version }}"

- name: Build
run: dotnet build --no-restore -c Debug -p:Version=${{ steps.get-id.outputs.version }}

- name: Test
env:
HIVEUSERNAME: ${{ secrets.USERNAME }}
KEY: ${{ secrets.KEY }}
run: dotnet test --no-build --verbosity normal


68 changes: 68 additions & 0 deletions .github/workflows/Publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Publish release to nuget

on:
push:
branches:
- master

jobs:
Nuget:
runs-on: ubuntu-latest
environment: test
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: '0'

- name: Setup .NET Core 6
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}

- name: Bump version and push tag
id: bump-and-tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true

- name: version it
id: get-id
uses: actions/[email protected]
env:
DATA: ${{ steps.bump-and-tag.outputs.new_tag }}
with:
script: |
const id = process.env.DATA.split('v')[1]
core.setOutput('version', id)
- name: Create releasse
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.bump-and-tag.outputs.new_tag }}
release_name: Release ${{ steps.bump-and-tag.outputs.new_tag }}
body: |
Changes in this release
draft: false
prerelease: false

- name: Restore dependencies
run: dotnet restore

- name: Pack it
run: dotnet pack -c Release --no-restore -p:Version=${{ steps.get-id.outputs.version }} -o out


- name: Publish SplinterLands.DTOs
run: nuget push ./**/SplinterLands.DTOs.*.nupkg -SkipDuplicate -NoSymbols -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}

- name: Publish SplinterLandsAPI
run: nuget push ./**/SplinterLandsAPI.*.nupkg -SkipDuplicate -NoSymbols -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}


10 changes: 10 additions & 0 deletions sl-Hive.Test/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This project makes use of the .net secrets manager in order to protect the login and key of the user used to validate tests that require a login.
To setup the secrets manager first run `dotnet user-secrets init` from the project directory.

Next add two secrets, one for the user `HIVEUSERNAME` and one for your private posting key `KEY`.

`dotnet user-secrets set "HIVEUSERNAME" "YOUR_USER_NAME_HERE"`

`dotnet user-secrets set "KEY" "YOUR_PRIVATE_POSTING_KEY_HERE"`

See more info at https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-8.0&tabs=windows
71 changes: 24 additions & 47 deletions sl-Hive.Test/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Configuration;
using sl_Hive.Models;
using sl_Hive.Requests;
using sl_Hive.Splinterlands_Ops;
using System.Reflection;

namespace sl_Hive.Test
{
Expand All @@ -10,7 +12,27 @@ public class UnitTest1
private HiveEngine hive = new HiveEngine(new HttpClient(), RPCNodeCollection.DefaultNodes);
const string PrivKey = "5JdeC9P7Pbd1uGdFVEsJ41EkEnADbbHGq6p1BwFxm6txNBsQnsw";
const string PublicKey = "STM8m5UgaFAAYQRuaNejYdS8FVLVp9Ss3K1qAVk5de6F8s3HnVbvA";
private readonly string User;
private readonly string PrivatePostingKey;

public UnitTest1()
{
var builder = new ConfigurationBuilder().AddUserSecrets(Assembly.GetExecutingAssembly(), true).AddEnvironmentVariables();

var Configuration = builder.Build();

PrivatePostingKey = Configuration["KEY"] ?? string.Empty;
User = Configuration["HIVEUSERNAME"] ?? string.Empty;

if (PrivatePostingKey == string.Empty)
{
PrivatePostingKey = Environment.GetEnvironmentVariable("KEY") ?? string.Empty;
}
if (User == string.Empty)
{
User = Environment.GetEnvironmentVariable("HIVEUSERNAME") ?? string.Empty;
}
}

[TestMethod]
public async Task ReadGlobalBlockchainProperties() {
Expand Down Expand Up @@ -47,54 +69,9 @@ public async Task GetAccounts() {
[TestMethod]
public async Task PostTransaction()
{
//var hash = Sha256Manager.GetHash(
// Encoding.ASCII.GetBytes(
// "farpetrad" + new DateTimeOffset(new DateTime()).ToUnixTimeMilliseconds().ToString())
// );
//var bytes = CBase58.DecodePrivateWif("");
//var sig = Secp256K1Manager.SignCompressedCompact(hash, bytes);
//var signature = Hex.ToString(sig);


/*var response = await hive.QueryBlockchain<HiveDynamicGlobalProperties>(HiveDynamicGlobalPropertiesRequest.Instance);
var request = new CustomJsonTx();
var trx = new custom_json()
{
id = "sm_stake_tokens", // whatever operation the game should perform
required_posting_auths = ["ahsoka"], // posting key ops
required_auths = [], // active key ops
json = JsonSerializer.Serialize(new StakeTokens() { qty = 1 }, HiveEngine._options),
};
var trans = new Transaction()
{
ref_block_num = (ushort)((ushort)response.Result?.Head_Block_Number & (ushort)0xFFFF),
ref_block_prefix = response.Result?.Ref_Block_Prefix ?? 0,
operations = new object[] { trx },
expiration = response?.Result?.Time.AddSeconds(30) ?? DateTime.UtcNow.AddSeconds(30),
signatures = new string[0],
extensions = new string[0],
};
var serializer = new SignatureSerializer();
var msg = serializer.Serialize(trans);
using(var memStream = new MemoryStream())
{
var chainIdBytes = Hex.HexToBytes(CHAINID);
memStream.Write(chainIdBytes, 0, chainIdBytes.Length);
memStream.Write(msg, 0, msg.Length);
var digest = Sha256Manager.GetHash(memStream.ToArray());
var signatureBytes = CBase58.DecodePrivateWif("");
trans.signatures = new[] { Hex.ToString(Secp256K1Manager.SignCompressedCompact(digest, signatureBytes)) };
var trxId = Hex.ToString(Sha256Manager.GetHash(msg)).Substring(0, 40);
};
request.Params = new JsonArray(JsonSerializer.SerializeToNode(trans.ToParams(), HiveEngine._options));
var post = await hive.QueryBlockchain<JObject>(request);*/
var post = await hive.BroadcastCustomJson(new StakeTokens() { qty = 1 },
"ahsoka",
"");
User,
PrivatePostingKey);
Assert.IsNotNull(post);
}

Expand Down
4 changes: 4 additions & 0 deletions sl-Hive.Test/sl-Hive.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

<UserSecretsId>fe95abbd-4c03-414f-9cc0-d43750a3e68f</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
Expand Down

0 comments on commit 9491951

Please sign in to comment.