Skip to content

dotnet lint

dotnet lint #162

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
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
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@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.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 }}
# Commit if change happen
- name: commit
id: git-check
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 }}
# get directory stats from action outputs
- name: Set changed files and directories
if: ${{ steps.git-check.outputs.changed == '1' }}
run: |
{
echo "CHANGED_DIRS<<EOF"
echo "${{ steps.git-check.outputs.changed-dirs }}"
echo "EOF"
echo "CHANGED_FILES<<EOF"
echo "${{ steps.git-check.outputs.changed-files }}"
echo "EOF"
} | tee -a "$GITHUB_ENV"
- name: Create PullRequest
if: ${{ steps.git-check.outputs.changed == '1' }}
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 }}