Skip to content

Commit

Permalink
changed in dotnet
Browse files Browse the repository at this point in the history
  • Loading branch information
apetrovskiy committed Nov 17, 2023
1 parent 1d778fd commit 22a7e9a
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 120 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-format": {
"version": "7.4.452404",
"commands": [
"dotnet-format"
]
}
}
}
70 changes: 33 additions & 37 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,52 +261,48 @@ jobs:
# name: allure-reports
# path: allure-reports

dotnet-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
# dotnet-format:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repo
# uses: actions/checkout@v2

- name: Add dotnet-format problem matcher
uses: xt0rted/dotnet-format-problem-matcher@v1
# - name: Add dotnet-format problem matcher
# uses: xt0rted/dotnet-format-problem-matcher@v1

- name: Restore dotnet tools
uses: xt0rted/dotnet-tool-restore@v1
# - name: Restore dotnet tools
# uses: xt0rted/dotnet-tool-restore@v1

- name: Run dotnet format
uses: xt0rted/dotnet-format@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# - name: Run dotnet format
# uses: xt0rted/dotnet-format@v1
# with:
# repo-token: ${{ secrets.GITHUB_TOKEN }}
dotnet:
runs-on: ubuntu-latest
needs:
- build
# - dotnet-format
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/allure-prep
- name: Setup .NET
uses: actions/setup-dotnet@v1
if: always()
with:
dotnet-version: 7.0.x
- name: Print donten version
if: always()
run: dotnet --version
- name: Restore dependencies
if: always()
run: dotnet restore
# - name: dotnet - format check
# if: always()
# run: |
# run: dotnet tool update -g dotnet-format
# dotnet-format --check
- name: Build
if: always()
run: dotnet build --no-restore
- name: Test
if: always()
run: dotnet test --no-build --verbosity normal
- uses: actions/checkout@v3
- uses: ./.github/actions/allure-prep
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Install dotnet-format
run: |
dotnet tool uninstall dotnet-format
dotnet tool install dotnet-format --version "7.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json
# - name: Restore dotnet tools
# run: dotnet tool restore
- name: Check formatting
run: dotnet format --verify-no-changes -v d
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal

- name: Look at Allure
if: always()
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ dmypy.json
### Ruby ###
*.gem
*.rbc
/.config
# /.config
/coverage/
/InstalledFiles
/pkg/
Expand Down Expand Up @@ -1198,8 +1198,8 @@ build
.metals/metals.h2.db
.metals/metals.lock.db
.bloop/
.bloop/CodeSignTest.json
.bloop/CodeSignTest-test.json
.bloop/testLeCo.json
.bloop/testLeCo-test.json

allure-reports/*
allure-results/*
Expand Down
110 changes: 110 additions & 0 deletions init_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/sh

FULL_RESTORE=0
# 0 - runs code operations without the Internet
# 1 - reloads packages

rm allure-results/* -y

SOLUTION_NAME=testLeCo
ROOT_FOLDER=src
MAIN_PRJ_NAME=main
MAIN_PRJ_FOLDER="${ROOT_FOLDER}/${MAIN_PRJ_NAME}"
MAIN_PRJ_FILE="${MAIN_PRJ_FOLDER}/${MAIN_PRJ_NAME}.csproj"
MAIN_PRJ_TMP_FILE="${MAIN_PRJ_FOLDER}/main.tmp"
TEST_PRJ_NAME=test
TEST_PRJ_FOLDER="${ROOT_FOLDER}/${TEST_PRJ_NAME}"
TEST_PRJ_FILE="${TEST_PRJ_FOLDER}/${TEST_PRJ_NAME}.csproj"
TEST_PRJ_TMP_FILE="${TEST_PRJ_FOLDER}/test.tmp"
# the allure config item
ALLURE_CONFIG_FILE_NAME=allureConfig.json
ALLURE_CONFIG_FILE_PATH=${TEST_PRJ_FOLDER}/${ALLURE_CONFIG_FILE_NAME}
ALLURE_CONFIG_CONTENT="{\n \"allure\": {\n \"directory\": \"../../../../../allure-results\"\n }\n}\n"
ALLURE_ITEM_GROUP="\n <ItemGroup>\n <Content Include=\"allureConfig.json\">\n <CopyToOutputDirectory>Always</CopyToOutputDirectory>\n </Content>\n </ItemGroup>\n"
# stylecop
STYLECOP_ITEM_GROUP=" <ItemGroup>\n <AdditionalFiles Include=\"../stylecop.json\" />\n </ItemGroup>\n"
PROJECT_TAG="</Project>"

rm -f "${TEST_PRJ_FILE}"
rm -f "${TEST_PRJ_FOLDER}/Class1.cs"
rm -f "${MAIN_PRJ_FILE}"
rm -f "${MAIN_PRJ_FOLDER}/Class1.cs"
rm -f "${SOLUTION_NAME}.sln"

dotnet new sln --name "${SOLUTION_NAME}"
dotnet new classlib --name "${MAIN_PRJ_NAME}" --framework net7.0 --output "${MAIN_PRJ_FOLDER}"
dotnet new classlib --name "${TEST_PRJ_NAME}" --framework net7.0 --output "${TEST_PRJ_FOLDER}"
dotnet sln add "${MAIN_PRJ_FILE}"
dotnet sln add "${TEST_PRJ_FILE}"
dotnet add "${TEST_PRJ_FILE}" reference "${MAIN_PRJ_FILE}"

rm -f "${TEST_PRJ_FOLDER}/Class1.cs"
rm -f "${MAIN_PRJ_FOLDER}/Class1.cs"

# formatting
dotnet add "${MAIN_PRJ_FOLDER}" package Stylecop.Analyzers
dotnet add "${TEST_PRJ_FOLDER}" package Stylecop.Analyzers

# testing
dotnet add "${TEST_PRJ_FOLDER}" package Microsoft.NET.Test.Sdk
dotnet add "${TEST_PRJ_FOLDER}" package coverlet.collector
dotnet add "${TEST_PRJ_FOLDER}" package NUnit
dotnet add "${TEST_PRJ_FOLDER}" package NUnit3TestAdapter
dotnet add "${TEST_PRJ_FOLDER}" package NUnit.Allure
dotnet add "${TEST_PRJ_FOLDER}" package NUnit.Allure.Steps
#
dotnet add "${TEST_PRJ_FOLDER}" package xunit
dotnet add "${TEST_PRJ_FOLDER}" package xunit.runner.visualstudio
dotnet add "${TEST_PRJ_FOLDER}" package Allure.XUnit
#
dotnet add "${TEST_PRJ_FOLDER}" package MSTest.TestAdapter
dotnet add "${TEST_PRJ_FOLDER}" package MSTest.TestFramework
#
dotnet add "${TEST_PRJ_FOLDER}" package Allure.Commons
dotnet add "${TEST_PRJ_FOLDER}" package NUnit.Analyzers
#
dotnet add "${TEST_PRJ_FOLDER}" package FluentAssertions
dotnet add "${TEST_PRJ_FOLDER}" package Shouldly
#
##########

echo "${ALLURE_CONFIG_CONTENT}" >"${ALLURE_CONFIG_FILE_PATH}"

echo "============================="
cat "${ALLURE_CONFIG_FILE_PATH}"
echo "============================="
echo "${ALLURE_ITEM_GROUP}"
echo "============================="
echo "${STYLECOP_ITEM_GROUP}"
echo "============================="
echo "${PROJECT_TAG}"

# main prj
sed '$d' "${MAIN_PRJ_FILE}"
tail -r "${MAIN_PRJ_FILE}" | tail -n +3 | tail -r >"${MAIN_PRJ_TMP_FILE}"
{
echo "${STYLECOP_ITEM_GROUP}"
echo "${PROJECT_TAG}"
} >>"${MAIN_PRJ_TMP_FILE}"
mv "${MAIN_PRJ_TMP_FILE}" "${MAIN_PRJ_FILE}"

# test prj
sed '$d' "${TEST_PRJ_FILE}"
tail -r "${TEST_PRJ_FILE}" | tail -n +3 | tail -r >"${TEST_PRJ_TMP_FILE}"
{
echo "${ALLURE_ITEM_GROUP}"
echo "${STYLECOP_ITEM_GROUP}"
echo "${PROJECT_TAG}"
} >>"${TEST_PRJ_TMP_FILE}"
mv "${TEST_PRJ_TMP_FILE}" "${TEST_PRJ_FILE}"

if [ "${FULL_RESTORE}" = 1 ]; then
echo "cleanin... ==========="
dotnet clean
dotnet restore
fi
# install from here: dotnet tool install dotnet-format --version "7.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json
dotnet tool restore
dotnet format -v d
dotnet build --no-restore
dotnet test --no-build --verbosity normal
8 changes: 8 additions & 0 deletions run_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

dotnet clean
dotnet restore
dotnet format --verify-no-changes -v d
dotnet build --no-restore

dotnet test
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
namespace challenges.c20201001_20201007.CombinationSum
// <copyright file="solution.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

namespace Challenges.C20201001_20201007.CombinationSum
{
using System.Collections.Generic;

public class Solution
{
public IList<IList<int>> CombinationSum(int[] candidates, int target)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace challenges.c20201001_20201007.NumberOfRecentCalls
// <copyright file="20201001-20201007.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

namespace Challenges.C20201001_20201007.NumberOfRecentCalls
{
using System;
using System.Collections.Generic;
Expand All @@ -8,30 +12,31 @@ public class RecentCounter
private const int MaximumTime = 3000;
private int counter;
private List<int> requests;

public RecentCounter()
{
counter = 0;
requests = new List<int>();
this.counter = 0;
this.requests = new List<int>();
}

public int Ping(int t)
{
requests.Add(t);
this.requests.Add(t);
var sum = 0;
counter = 0;
for (var i = requests.Count - 1; i >= 0; i--)
this.counter = 0;
for (var i = this.requests.Count - 1; i >= 0; i--)
{
sum += requests[i];
Console.WriteLine($"req -> {requests[i]}");
counter++;
Console.WriteLine($"counter -> {counter}");
if (MaximumTime <= sum)
sum += this.requests[i];
Console.WriteLine($"req -> {this.requests[i]}");
this.counter++;
Console.WriteLine($"counter -> {this.counter}");
if (sum >= MaximumTime)
{
break;
}
}
return counter;

return this.counter;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// <copyright file="code.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

/*
public class RecentCounter {
public RecentCounter() {
}
public int Ping(int t) {
}
}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace challenges.c20210101_20210107.CheckArrayFormationThroughConcatenation
// <copyright file="solution.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

namespace Challenges.C20210101_20210107.CheckArrayFormationThroughConcatenation
{

public class Solution
{
public bool CanFormArray(int[] arr, int[][] pieces)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
namespace challenges.c20210101_20210107.FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree
// <copyright file="solution.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

namespace Challenges.C20210101_20210107.FindACorrespondingNodeOfABinaryTreeInACloneOfThatTree
{
// Definition for a binary tree node.
public class TreeNode
{
public int val;
public TreeNode left;
public TreeNode right;
public TreeNode(int x) { val = x; }
}

public int Val;
public TreeNode Left;
public TreeNode Right;

public TreeNode(int x)
{
this.Val = x;
}
}

public class Solution
{
public TreeNode GetTargetCopy(TreeNode original, TreeNode cloned, TreeNode target)
Expand Down
Loading

0 comments on commit 22a7e9a

Please sign in to comment.