-
-
Notifications
You must be signed in to change notification settings - Fork 230
71 lines (64 loc) · 2.98 KB
/
format-code.yml
File metadata and controls
71 lines (64 loc) · 2.98 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
name: format code
on:
pull_request:
paths:
- 'src/**'
- 'test/**'
- 'samples/**'
- '.github/workflows/format-code.yml'
jobs:
format-code:
name: Format Code
# Run on 'macos' because Linux is missing the `ios` workload: https://github.com/dotnet/runtime/issues/85505
# Pin macos to get the version of XCode that we need: https://github.com/actions/runner-images/issues/10703
runs-on: macos-15
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
- name: Setup Environment
uses: ./.github/actions/environment
- name: Restore .NET Dependencies
# We should be able to get rid of the restore here, if we install the correct workloads in actions/environment
run: |
dotnet workload restore
dotnet restore Sentry.slnx --nologo
- name: Format Code
# We exclude `./**/*OptionsSetup.cs` from the format because the tool struggles with
# source generators.
#
# We exclude `test/Sentry.Tests/AttributeReaderTests.cs` because dotnet-format tries to
# delete assertions in there.
# - see https://github.com/getsentry/sentry-dotnet/pull/4911#discussion_r2795717887
run: dotnet format Sentry.slnx --no-restore --report ./dotnet-format-report --exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs
- name: Upload Format Report
if: ${{ always() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
archive: false
path: ./dotnet-format-report/
if-no-files-found: ignore
- name: Exclude Format Report from Git
run: |
if [ -d ./dotnet-format-report ]; then
echo '*' > ./dotnet-format-report/.gitignore
fi
# actions/checkout fetches only a single commit in a detached HEAD state. Therefore
# we need to pass the current branch, otherwise we can't commit the changes.
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs.
#
# For fork PRs we can't push back to the contributor's branch, so we fail the check
# instead — prompting the contributor to run dotnet format locally.
- name: Commit Formatted Code
run: |
if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then
if [[ $(git status) != *"nothing to commit"* ]]; then
echo "::error::Formatting issues found. Please run the following command locally and push the result:"
echo "::error:: dotnet format Sentry.slnx --no-restore --exclude ./modules ./**/*OptionsSetup.cs ./test/Sentry.Tests/AttributeReaderTests.cs"
exit 1
fi
echo "All code formatted correctly."
else
./scripts/commit-formatted-code.sh $GITHUB_HEAD_REF
fi