Skip to content

dotnet lint

dotnet lint #140

Workflow file for this run

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
pull-requests: write
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.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"
} >> "$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@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
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 }}"