dotnet format 도구를 이용해 파일 범위 네임스페이스를 일괄 적용하는 방법을 알려 줍니다.
1개의 좋아요
호스팅 서버로 Github를 쓰신다면 Github Action과 함께할 수 있습니다.
제가 좋아하는 방식인데 예를들어 아래처럼 workflow를 만든다면 매일 오전 9시에 해당 Repo 안에 있는 코드를 분석해 포맷을 맞춰줍니다.
(하루에 한 번이라고 생각하는 것이 좋습니다. 깃헙 액션이 시간을 잘 안지키더군요…)
name: Daily code format check
on:
schedule:
- cron: 0 0 * * * # Every day at midnight (UTC)
jobs:
dotnet-format:
runs-on: windows-latest
steps:
- name: Install dotnet-format
run: dotnet tool install -g dotnet-format
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Run dotnet format
id: format
uses: jfversluis/dotnet-format@v1.0.5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
action: "fix"
workspace: "MySoultion.sln"
- name: Commit files
if: steps.format.outputs.has-changes == 'true'
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -a -m 'Automated dotnet-format update'
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
title: '[housekeeping] 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>
labels: housekeeping
assignees: level120
reviewers: level120
branch: housekeeping/fix-codeformatting
1개의 좋아요
여담이지만 dotnet 쪽 Repo에서도 이와 같이 사용합니다.
https://github.com/dotnet/maui/blob/main/.github/workflows/dotnet-format-daily.yml
이렇게 작성된 워크플로우는 특이점이 발견되면 아래와 같이 알아서 수정하여 PR을 올려줍니다.
2개의 좋아요