-
Notifications
You must be signed in to change notification settings - Fork 5
143 lines (121 loc) · 4.89 KB
/
dotnet-lint.yaml
File metadata and controls
143 lines (121 loc) · 4.89 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: dotnet lint
on:
workflow_dispatch:
schedule:
- cron: 0 1 * * 1 # At AM10:00 JST on Monday
env:
SLN_ROOT: src/dotnet/
jobs:
lint_csharp:
permissions:
contents: read
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
id: app-token
with:
app-id: ${{ secrets.SYNCED_ACTIONS_BOT_APPID }}
private-key: ${{ secrets.SYNCED_ACTIONS_BOT_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
- uses: actions/setup-dotnet@baa11fbfe1d6520db94683bd5c7a3818018e4309 # v5.1.0
with:
dotnet-version: 10.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@b90c4f18e3daa4f8fd266e41eba4f351b2e00b75 # v1.2.0
# 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"
} | tee -a "$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"
} | tee -a "$GITHUB_ENV"
# Commit if change happen, then craete PR. force push when branch/pr already exists.
- name: git auth
if: ${{ steps.git-check.outputs.modified == 'true' }}
run: |
git remote set-url origin "https://github-actions:${GITHUB_TOKEN}@github.com/${{ github.repository }}"
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git checkout -b "auto-pr/dotnet-format"
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: commit
uses: ./.github/actions/git-push
with:
commit-message: "[automated] dotnet format by ${{ github.workflow }}"
ref: "auto-pr/dotnet-format"
github-token: ${{ steps.app-token.outputs.token }}
- name: Create PullRequest
if: ${{ steps.git-check.outputs.modified == 'true' }}
run: |
pr_exists=$(gh pr list --head "auto-pr/dotnet-format" --base "${DEFAULT_BRANCH}")
if [ -n "$pr_exists" ]; then
echo "PR already exists for auto-pr/dotnet-format -> ${DEFAULT_BRANCH}. Skipping creation."
exit 0
fi
title="[dotnet format] Automated changes"
cat << 'EOF' > pr_body.txt
## 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
Target project number is ${{ env.PROJECT_LENGTH }}.
${{ env.FORMAT_PROJECTS }}
---
This PR was created automatically via [${{ env.WORKFLOW_NAME }}](${{ env.GITHUB_ACTIONS_RUN_URL }}), job [link](${{ env.GITHUB_ACTIONS_JOB_URL }}).
EOF
gh pr create --title "$title" --body-file "./pr_body.txt" --label "automated pr"
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITHUB_ACTIONS_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_ACTIONS_JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ job.check_run_id }}
WORKFLOW_NAME: ${{ github.workflow }}