-
Notifications
You must be signed in to change notification settings - Fork 5
109 lines (100 loc) · 3.41 KB
/
dotnet-lint.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: dotnet lint
on:
workflow_dispatch:
schedule:
- cron: 0 1 * * 1 # At AM10:00 JST on Monday
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
NUGET_XMLDOC_MODE: skip
SLN_ROOT: src/dotnet/
# colour output
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1
TERM: xterm
jobs:
lint_csharp:
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
# dotnet list
- name: Obtain csproj to lint
run: |
projects=$(dotnet sln list | tail -n +3 | sort | xargs -n 1 echo ' *')
{
echo "FORMAT_PROJECTS<<EOF"
echo "${projects}"
echo "EOF"
} >> "$GITHUB_ENV"
working-directory: ${{ env.SLN_ROOT }}
- name: Add dotnet-format problem matcher
uses: xt0rted/dotnet-format-problem-matcher@v1
# dotnet format is build-in from dotnet 6.0 sdk
- name: Dotnet Format
run: dotnet format --verbosity diagnostic --exclude "Sandbox.Fail.Tests"
working-directory: ${{ env.SLN_ROOT }}
# is change happen?
- name: Check for modified files
id: git-check
run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> "$GITHUB_OUTPUT"
# get directory stats
- name: List modified directories
if: ${{ steps.git-check.outputs.modified == 'true' }}
run: |
dirs=$(git diff --dirstat=files)
{
echo "CHANGED_DIRS<<EOF"
echo "${dirs}"
echo "EOF"
} >> "$GITHUB_ENV"
# get files stats
- name: List modified files
if: ${{ steps.git-check.outputs.modified == 'true' }}
run: |
files=$(git diff --name-only)
{
echo "CHANGED_FILES<<EOF"
echo "${files}"
echo "EOF"
} >> "$GITHUB_ENV"
# Commit if change happen, then craete PR. force push when branch/pr already exists.
- name: Create PullRequest
if: ${{ steps.git-check.outputs.modified == 'true' }}
id: cpr
uses: peter-evans/create-pull-request@v7
with:
base: "main"
branch: "auto-pr/dotnet-format"
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
delete-branch: true
commit-message: "[dotnet format] Automated changes"
title: "[dotnet format] Automated changes"
body: |
## tl;dr;
dotnet format generated changes based on .editorconfig
## Stats
changed directories
```
${{ env.CHANGED_DIRS }}
```
## Files
<details>
<summary>Click to show.</summary>
```
${{ env.CHANGED_FILES }}
```
</details>
## Target Projects
${{ env.FORMAT_PROJECTS }}
labels: |
automated pr
- name: Check outputs
if: ${{ steps.git-check.outputs.modified == 'true' }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"