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

ci: add pre-commit-config #496

Merged
merged 5 commits into from
Aug 25, 2023
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
10 changes: 10 additions & 0 deletions .scripts/git_hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
LC_ALL=C
# Select files to format
FILES=$(git diff --cached --name-only --diff-filter=ACM "*.cs" | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Format all selected files
echo "$FILES" | cat | xargs | sed -e 's/ /,/g' | xargs dotnet-format --include
# Add back the modified files to staging
echo "$FILES" | xargs git add
exit 0
38 changes: 38 additions & 0 deletions .scripts/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
var hiddenHooksFolderPath = path.join(__dirname, '../.git/hooks');
var hooksFolderPath = path.join(__dirname, 'git_hooks');
var hooks = fs.readdirSync(hooksFolderPath);
function copyFile (source, target, cb) {
var cbCalled = false;
var rd = fs.createReadStream(source);
var wr = fs.createWriteStream(target);
function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
rd.on("error", done);
wr.on("error", done);
wr.on("close", done);
rd.pipe(wr);
}
hooks.forEach(function (hook) {
var hookSource = path.join(hooksFolderPath, hook);
var hookTarget = path.join(hiddenHooksFolderPath, hook);
copyFile(hookSource, hookTarget, function (err) {
if (!err) {
console.log(hook + ' added to your .git/hooks folder')
exec(
'chmod +x ' + hookTarget,
function (error) {
if (!error) {
console.log(hookTarget + ' made executable');
}
}
);
}
})
});
4 changes: 3 additions & 1 deletion Vonage.Common.Test/Vonage.Common.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
</Target>
</Project>
11 changes: 7 additions & 4 deletions Vonage.Common/Vonage.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>6.8.0</Version>
<PackageLicenseExpression />
<PackageLicenseExpression/>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<LangVersion>latest</LangVersion>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Enums.NET" Version="4.0.1" />
<PackageReference Include="Handy.DotNETCore-Compatibility.ColorTranslations" Version="0.2.1" />
<PackageReference Include="Enums.NET" Version="4.0.1"/>
<PackageReference Include="Handy.DotNETCore-Compatibility.ColorTranslations" Version="0.2.1"/>
<PackageReference Include="PolySharp" Version="1.13.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="7.0.3"/>
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="1.0.0" />
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="1.0.0"/>
<PackageReference Update="NETStandard.Library" Version="2.0.3"/>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
</Target>
</Project>
4 changes: 3 additions & 1 deletion Vonage.Server.Test/Vonage.Server.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
</Target>
</Project>
3 changes: 3 additions & 0 deletions Vonage.Server/Vonage.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@
<ItemGroup>
<InternalsVisibleTo Include="Vonage.Server.Test"/>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
</Target>
</Project>
36 changes: 19 additions & 17 deletions Vonage.Test.Unit/Vonage.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.0" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="19.2.29" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" />
<PackageReference Include="WireMock.Net" Version="1.5.31" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="AutoFixture" Version="4.18.0"/>
<PackageReference Include="FluentAssertions" Version="6.11.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3"/>
<PackageReference Include="Moq" Version="4.18.4"/>
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="19.2.29"/>
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0"/>
<PackageReference Include="WireMock.Net" Version="1.5.31"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -33,12 +33,12 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vonage.Common.Test\Vonage.Common.Test.csproj" />
<ProjectReference Include="..\Vonage\Vonage.csproj" />
<ProjectReference Include="..\Vonage.Common.Test\Vonage.Common.Test.csproj"/>
<ProjectReference Include="..\Vonage\Vonage.csproj"/>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.0' And '$(TargetFramework)' != 'netcoreapp3.1' ">
<Reference Include="System.Web" />
<Reference Include="System.Web"/>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -408,7 +408,7 @@
<None Include="Messages\Viber\Data\SendViberFileAsyncReturnsOk-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Remove="Messages\Viber\Data\SendViberFileAsyncReturnsOk-response.json" />
<None Remove="Messages\Viber\Data\SendViberFileAsyncReturnsOk-response.json"/>
<None Include="Messages\Viber\Data\SendViberFileAsyncReturnsOk-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -676,10 +676,10 @@
<None Update="ProactiveConnect\Events\Data\ShouldDeserialize200-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Folder Include="ConfigurationData\" />
<Folder Include="Messages\Messenger\Data" />
<Folder Include="Messages\Mms\Data" />
<Folder Include="Messages\Sms\Data" />
<Folder Include="ConfigurationData\"/>
<Folder Include="Messages\Messenger\Data"/>
<Folder Include="Messages\Mms\Data"/>
<Folder Include="Messages\Sms\Data"/>
<None Update="Data\NccoTests\TestConnectWithAdvancedMachineDetection-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -867,5 +867,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
</Target>
</Project>
2 changes: 2 additions & 0 deletions Vonage.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
CHANGELOG.md = CHANGELOG.md
VIDEO_BETA_CHANGELOG.md = VIDEO_BETA_CHANGELOG.md
.editorconfig = .editorconfig
.scripts\init.js = .scripts\init.js
.scripts\git_hooks\pre-commit = .scripts\git_hooks\pre-commit
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vonage", "Vonage\Vonage.csproj", "{41EF17C9-8D2E-4C7B-B2EE-3BD1A4CC1A1B}"
Expand Down
3 changes: 3 additions & 0 deletions Vonage/Vonage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@
<ItemGroup>
<InternalsVisibleTo Include="Vonage.Server.Test"/>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
</Target>
</Project>
Loading