Merge pull request #4 from dotnet-campus/t/lindexi/ci

加上代码格式化机器人
This commit is contained in:
LanXiaofang
2022-03-16 20:26:52 +08:00
committed by GitHub
5 changed files with 157 additions and 40 deletions

82
.editorconfig Normal file
View File

@@ -0,0 +1,82 @@
[*]
end_of_line = crlf
charset = utf-8-bom
indent_size = 4
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true
[*.{xml,csproj,vbproj,props,targets}]
indent_size =2
indent_style = space
tab_width =2
[*.{cs,vb}]
dotnet_sort_system_directives_first = true
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true
dotnet_style_prefer_conditional_expression_over_return = true
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_readonly_field = true:suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
[*.cs]
csharp_indent_case_contents = true
csharp_indent_labels = flush_left
csharp_indent_switch_labels = true
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
csharp_prefer_braces = true:silent
csharp_prefer_simple_default_expression = true:suggestion
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
csharp_space_after_cast = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_around_binary_operators = before_and_after
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_var_elsewhere = true:silent
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent

View File

@@ -10,6 +10,14 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
- name: Build with dotnet
run: dotnet build --configuration Release

59
.github/workflows/dotnet-format.yml vendored Normal file
View File

@@ -0,0 +1,59 @@
name: Code format check
# 代码格式化机器人,详细请看 [dotnet 基于 dotnet format 的 GitHub Action 自动代码格式化机器人](https://blog.lindexi.com/post/dotnet-%E5%9F%BA%E4%BA%8E-dotnet-format-%E7%9A%84-GitHub-Action-%E8%87%AA%E5%8A%A8%E4%BB%A3%E7%A0%81%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%9C%BA%E5%99%A8%E4%BA%BA.html )
on:
push:
branches:
- master
jobs:
dotnet-format:
runs-on: windows-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
- name: Install dotnetCampus.EncodingNormalior
run: dotnet tool update -g dotnetCampus.EncodingNormalior
- name: Fix encoding
run: EncodingNormalior -f . --TryFix true
- name: Install dotnet-format
run: dotnet tool install -g dotnet-format
- name: Run dotnet format
run: dotnet format
- name: Commit files
# 下面将使用机器人的账号,你可以替换为你自己的账号
run: |
git config --local user.name "github-actions-dotnet-formatter[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -a -m 'Automated dotnet-format update'
continue-on-error: true
- name: Create Pull Request
# if: steps.format.outputs.has-changes == 'true' # 如果有格式化,才继续
uses: peter-evans/create-pull-request@v3
with:
title: '[Bot] Automated PR to fix formatting errors'
body: |
Automated PR to fix formatting errors
committer: GitHub <noreply@github.com>
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
# 以下是给定代码审查者,需要设置仓库有权限的开发者
assignees: lindexi,walterlv,kkwpsv
reviewers: lindexi,walterlv,kkwpsv
# 对应的上传分支
branch: t/bot/fix-codeformatting

View File

@@ -1,40 +0,0 @@
# 去掉注释可以合并 master 分支自动打包
# 为什么不期望推送 master 自动打包?原因是打出来的 CBB 没有 Tag 不利于回滚找到代码
# name: publish nuget
# on:
# push:
# branches:
# - master
# jobs:
# build:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v1
# - name: Setup .NET Core
# uses: actions/setup-dotnet@v1
# with:
# dotnet-version: 3.1.300
# - name: Build with dotnet
# run: |
# dotnet build --configuration Release
# dotnet pack --configuration Release --no-build
# - name: Install Nuget
# uses: nuget/setup-nuget@v1
# with:
# nuget-version: '5.x'
# - name: Add private GitHub registry to NuGet
# run: |
# nuget sources add -name github -Source https://nuget.pkg.github.com/dotnet-campus/index.json -Username dotnet-campus -Password ${{ secrets.GITHUB_TOKEN }}
# - name: Push generated package to GitHub registry
# run: |
# nuget push .\bin\Release\*.nupkg -Source github -SkipDuplicate
# nuget push .\bin\Release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }}

View File

@@ -12,6 +12,14 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
- name: Install dotnet tool
run: dotnet tool install -g dotnetCampus.TagToVersion