You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/06/09 11:56:29 UTC
[incubator-shenyu-client-dotnet] branch main updated: [ISSUE #14] Add CI for building, testing, license checking and codeQL check (#15)
This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu-client-dotnet.git
The following commit(s) were added to refs/heads/main by this push:
new 2c361e1 [ISSUE #14] Add CI for building, testing, license checking and codeQL check (#15)
2c361e1 is described below
commit 2c361e1be5020ee07b784c974ad4aed7d7f71300
Author: Han Gao <dh...@hotmail.com>
AuthorDate: Thu Jun 9 19:56:25 2022 +0800
[ISSUE #14] Add CI for building, testing, license checking and codeQL check (#15)
* test ci
* add .licenserc.yaml
* add ignore paths for license check
* add codeql analysis workflow
* fix small bug
* add one unit test and ci for UT
* add UT and code coverage workflow
* change trigger to main branch
* remove deprecated test project
---
.editorconfig | 17 +++++
.github/actions/skip-ci/action.yml | 84 ++++++++++++++++++++++
.github/workflows/ci.yml | 62 ++++++++++++++++
.github/workflows/code-coverage.yml | 41 +++++++++++
.github/workflows/codeql-analysis.yml | 60 ++++++++++++++++
.licenserc.yaml | 39 ++++++++++
.../Apache.ShenYu.Client.Tests.csproj | 38 +++++-----
.../Utils/IpUtilsTest.cs} | 32 ++++-----
client/Apache.ShenYu.Client/Utils/IpUtils.cs | 24 ++++---
9 files changed, 348 insertions(+), 49 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 2520e68..b63d73b 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,3 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
###############################
# Core EditorConfig Options #
diff --git a/.github/actions/skip-ci/action.yml b/.github/actions/skip-ci/action.yml
new file mode 100644
index 0000000..3f1f5e3
--- /dev/null
+++ b/.github/actions/skip-ci/action.yml
@@ -0,0 +1,84 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+name: "Set Skip Env Var"
+description: "Action to set the SKIP_CI environment variable indicating that we should skip CI jobs"
+inputs:
+ ignore-patterns:
+ description: >-
+ Set the SKIP_CI environment variable when and only when all the changed files located in one of the path,
+ the paths is shell-style pattern.
+ required: false
+ default: >-
+ "*.md"
+ "shenyu-dashboard"
+
+runs:
+ using: "composite"
+ steps:
+ - name: Check Changed Files And Set Env Var
+ shell: bash
+ run: |
+ if [ $GITHUB_BASE_REF ]; then
+ # Pull Request
+ BASE_SHA=$GITHUB_BASE_REF
+ else
+ # Push
+ BASE_SHA=${{ github.event.before }}
+ fi
+
+ echo "Base sha is $BASE_SHA, head sha is $GITHUB_SHA"
+
+ if [[ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]]; then
+ BASE_SHA="master"
+ fi
+
+ git fetch --no-tags --progress --recurse-submodules --depth=1 origin ${BASE_SHA}:origin/${BASE_SHA}
+ BASE_SHA=origin/${BASE_SHA}
+ echo "Base sha is $BASE_SHA, head sha is $GITHUB_SHA"
+
+ if ! files=$(git --no-pager diff --name-only ${GITHUB_SHA} ${BASE_SHA}); then
+ exit 1
+ fi
+
+ echo "Ignore pattern:"
+ for pattern in $(echo '${{ inputs.ignore-patterns }}'); do
+ echo $pattern
+ done
+
+ echo "Changed files:"
+ for file in ${files}; do
+ echo $file
+ done
+
+ echo "SKIP_CI=true" >> $GITHUB_ENV
+ for file in ${files}; do
+ matched=0
+ for pattern in $(echo '${{ inputs.ignore-patterns }}'); do
+ pattern=$(echo "$pattern" | sed 's/"//g')
+ if eval "[[ '$file' == $pattern ]]"; then
+ matched=1
+ break
+ fi
+ done
+ if [[ "$matched" == "0" ]]; then
+ echo "$file doesn't match pattern $(echo '${{ inputs.ignore-patterns }}'), stop checking"
+ echo "SKIP_CI=false" >> $GITHUB_ENV
+ break
+ fi
+ done
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..e2a2f07
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,62 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: ci
+
+on:
+ pull_request:
+ push:
+ branches:
+ - main
+
+jobs:
+ build:
+ strategy:
+ matrix:
+ dotnet: [6.0.201]
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ include:
+ - dotnet: 5.0.406
+ os: ubuntu-latest
+ runs-on: ${{ matrix.os }}
+ steps:
+ - name: Support longpaths
+ if: ${{ matrix.os == 'windows-latest'}}
+ run: git config --system core.longpaths true
+ - uses: actions/checkout@v2
+ with:
+ submodules: true
+ - name: Set Skip Env Var
+ uses: ./.github/actions/skip-ci
+ - name: Setup .NET Core SDK
+ uses: actions/setup-dotnet@v2.1.0
+ with:
+ dotnet-version: ${{ matrix.dotnet }}
+ - name: Build with dotnet
+ if: env.SKIP_CI != 'true'
+ run: dotnet build --configuration Release
+
+ check-license-header:
+ name: Check License Header
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ submodules: true
+ - name: Check License Header
+ uses: apache/skywalking-eyes@9bd5feb86b5817aa6072b008f9866a2c3bbc8587
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml
new file mode 100644
index 0000000..6314d5e
--- /dev/null
+++ b/.github/workflows/code-coverage.yml
@@ -0,0 +1,41 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: code-coverage
+
+on:
+ pull_request:
+ push:
+ branches:
+ - main
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ submodules: true
+ - name: Set Skip Env Var
+ uses: ./.github/actions/skip-ci
+ - name: Setup .NET Core SDK
+ uses: actions/setup-dotnet@v2.1.0
+ with:
+ dotnet-version: 5.0.406
+ - name: Unit Test with dotnet
+ if: env.SKIP_CI != 'true'
+ run: dotnet test --configuration Release
+ # - uses: codecov/codecov-action@v1
+ # if: env.SKIP_CI != 'true'
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 0000000..a6a8d57
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,60 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: CodeQL
+
+on:
+ pull_request:
+ push:
+ branches:
+ - main
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ language: ["csharp"]
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ with:
+ submodules: true
+
+ - name: Set Skip Env Var
+ uses: ./.github/actions/skip-ci
+
+ - name: Setup .NET Core SDK
+ uses: actions/setup-dotnet@v2.1.0
+ with:
+ dotnet-version: 6.0.201
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v2
+ if: env.SKIP_CI != 'true'
+ with:
+ languages: ${{ matrix.language }}
+
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v2
+ if: env.SKIP_CI != 'true'
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v2
+ if: env.SKIP_CI != 'true'
diff --git a/.licenserc.yaml b/.licenserc.yaml
new file mode 100644
index 0000000..7d88f66
--- /dev/null
+++ b/.licenserc.yaml
@@ -0,0 +1,39 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+header:
+ license:
+ spdx-id: Apache-2.0
+ copyright-owner: Apache Software Foundation
+
+ paths-ignore:
+ - "**/bin/**"
+ - "**/obj/**"
+ - "**/.github/**"
+ - "**/*.md"
+ - "**/.gitignore"
+ - "**/*.MD"
+ - "**/*.json"
+ - "**/.gitignore"
+ - "**/*.sln"
+ - "**/*.csproj"
+ - "DISCLAIMER"
+ - "LICENSE"
+ - "NOTICE"
+
+ comment: on-failure
diff --git a/client/Apache.ShenYu.Client.Tests/Apache.ShenYu.Client.Tests.csproj b/client/Apache.ShenYu.Client.Tests/Apache.ShenYu.Client.Tests.csproj
index 0d226e0..efc5b74 100644
--- a/client/Apache.ShenYu.Client.Tests/Apache.ShenYu.Client.Tests.csproj
+++ b/client/Apache.ShenYu.Client.Tests/Apache.ShenYu.Client.Tests.csproj
@@ -1,30 +1,28 @@
-<!--
- - Licensed under the Apache License, Version 2.0 (the "License");
- - you may not use this file except in compliance with the License.
- - You may obtain a copy of the License at
- -
- - http://www.apache.org/licenses/LICENSE-2.0
- -
- - Unless required by applicable law or agreed to in writing, software
- - distributed under the License is distributed on an "AS IS" BASIS,
- - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- - See the License for the specific language governing permissions and
- - limitations under the License.
--->
-
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFramework>netcoreapp3.1</TargetFramework>
+ <TargetFramework>net5</TargetFramework>
+ <Version>2.5.0</Version>
+ <FileVersion>$(Version)</FileVersion>
+ <Company>Apache Software Foundation</Company>
+ <Copyright>$(Company)</Copyright>
+ <Title>Apache.ShenYu.Client.Tests</Title>
+ <RootNamespace>$(Title)</RootNamespace>
<IsPackable>false</IsPackable>
- <RootNamespace>ShenyuClientTest</RootNamespace>
+ <LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
- <PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
- <PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
- <PackageReference Include="coverlet.collector" Version="1.3.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
+ <PackageReference Include="xunit" Version="2.4.1" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
+ <PackageReference Include="coverlet.collector" Version="3.1.0">
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
</ItemGroup>
<ItemGroup>
diff --git a/client/Apache.ShenYu.Client/Utils/IpUtils.cs b/client/Apache.ShenYu.Client.Tests/Utils/IpUtilsTest.cs
similarity index 51%
copy from client/Apache.ShenYu.Client/Utils/IpUtils.cs
copy to client/Apache.ShenYu.Client.Tests/Utils/IpUtilsTest.cs
index 8b31bd7..5140e70 100644
--- a/client/Apache.ShenYu.Client/Utils/IpUtils.cs
+++ b/client/Apache.ShenYu.Client.Tests/Utils/IpUtilsTest.cs
@@ -16,29 +16,21 @@
*/
using System.Net.NetworkInformation;
-using System.Net.Sockets;
+using System.Text.RegularExpressions;
+using Apache.ShenYu.Client.Utils;
+using Xunit;
-namespace Apache.ShenYu.Client.Utils
+namespace Apache.ShenYu.Client.Tests.Utils
{
- public static class IpUtils
+ public class IpUtilsTest
{
- public static string GetLocalIPv4(NetworkInterfaceType type)
+ [Fact]
+ public void GetLocalIPv4Test()
{
- string output = "";
- foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
- {
- if (item.NetworkInterfaceType == type && item.OperationalStatus == OperationalStatus.Up)
- {
- foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
- {
- if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
- {
- return ip.Address.ToString();
- }
- }
- }
- }
- return output;
+ Regex rx = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
+ var ret = IpUtils.GetLocalIPv4(NetworkInterfaceType.Ethernet);
+ var isMatch = rx.IsMatch(ret);
+ Assert.True(isMatch);
}
}
-}
\ No newline at end of file
+}
diff --git a/client/Apache.ShenYu.Client/Utils/IpUtils.cs b/client/Apache.ShenYu.Client/Utils/IpUtils.cs
index 8b31bd7..d3d890c 100644
--- a/client/Apache.ShenYu.Client/Utils/IpUtils.cs
+++ b/client/Apache.ShenYu.Client/Utils/IpUtils.cs
@@ -15,6 +15,8 @@
* limitations under the License.
*/
+using System.Collections.Generic;
+using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;
@@ -22,23 +24,27 @@ namespace Apache.ShenYu.Client.Utils
{
public static class IpUtils
{
+ private const string LocalHostIp = "127.0.0.1";
public static string GetLocalIPv4(NetworkInterfaceType type)
{
- string output = "";
+ List<string> ipv4Addresses = new List<string>();
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
{
- if (item.NetworkInterfaceType == type && item.OperationalStatus == OperationalStatus.Up)
+ if (item.OperationalStatus != OperationalStatus.Up)
{
- foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
+ continue;
+ }
+
+ foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
+ {
+ if (ip.Address.AddressFamily == AddressFamily.InterNetwork && !ip.Address.ToString().Equals(LocalHostIp))
{
- if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
- {
- return ip.Address.ToString();
- }
+ ipv4Addresses.Add(ip.Address.ToString());
}
}
}
- return output;
+ ipv4Addresses.Sort();
+ return ipv4Addresses.Last();
}
}
-}
\ No newline at end of file
+}