-
Notifications
You must be signed in to change notification settings - Fork 60
172 lines (171 loc) · 6.14 KB
/
build.yaml
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: build
run-name: Build and test
on:
pull_request:
types: [opened, reopened, synchronize]
merge_group:
types: [checks_requested]
push:
branches:
- main
release:
types: [published]
jobs:
formatting:
name: Check formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup .NET
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
with:
dotnet-version: 8.0.303
- name: Install tools
run: dotnet tool restore
- name: Check formatting
run: dotnet csharpier --check .
coverage:
name: Check code coverage
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup .NET
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
with:
dotnet-version: 8.0.303
- name: Run tests
run: dotnet test -c Debug --collect:"XPlat Code Coverage" --settings coverlet.runsettings ArchUnitNETTests/
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
run-tests:
name: Run tests
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup .NET
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
with:
dotnet-version: 8.0.303
- name: Run tests
run: dotnet test -c Debug
publish-docs:
name: Publish documentation
runs-on: ubuntu-latest
needs:
- formatting
- coverage
- run-tests
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup doxygen
run: sudo apt-get install doxygen graphviz
- name: Create temporary directory
run: |
tmpdir=$(mktemp -d -p "$GITHUB_WORKSPACE")
mkdir -p $tmpdir
relative_path=$(realpath --relative-to="$GITHUB_WORKSPACE" "$tmpdir")
echo "Created temporary directory $tmpdir ($relative_path relative to $GITHUB_WORKSPACE)"
echo "DOCS_TEMP_DIR=$relative_path" >> "$GITHUB_ENV"
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+$ ]]; then
echo "DOCS_TEMP_DIR_SUBPATH=stable" >> "$GITHUB_ENV"
else
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+$ ]]; then
echo "DOCS_TEMP_DIR_SUBPATH=preview" >> "$GITHUB_ENV"
else
echo "DOCS_TEMP_DIR_SUBPATH=latest" >> "$GITHUB_ENV"
fi
fi
- name: Checkout gh-pages branch
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: gh-pages
path: ${{ env.DOCS_TEMP_DIR }}
- name: Generate documentation
working-directory: ${{ env.DOCS_TEMP_DIR }}/${{ env.DOCS_TEMP_DIR_SUBPATH }}
run: |
rm -rf '*'
doxygen "$GITHUB_WORKSPACE/documentation/Doxyfile"
touch .nojekyll
- name: Check release conditions
run: |
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+(-[a-z]+.[0-9]+)?|"refs/heads/main"$ ]]; then
echo "CREATE_RELEASE=true" >> "$GITHUB_ENV"
else
echo "CREATE_RELEASE=false" >> "$GITHUB_ENV"
fi
- name: Commit and push changes
if: env.CREATE_RELEASE == 'true'
working-directory: ${{ env.DOCS_TEMP_DIR }}
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add -A
if [[ "$(git status --porcelain)" ]]; then
git commit -m "Update documentation for $GITHUB_REF_NAME"
git push
else
echo "No changes to commit"
fi
- name: Update readthedocs preview
if: env.CREATE_RELEASE == 'true' && env.DOCS_TEMP_DIR_SUBPATH == 'preview'
run: |
git fetch origin preview
git checkout preview
git reset --hard "$GITHUB_REF"
git push origin --force-with-lease
publish-packages:
name: Publish packages
if: github.event_name == 'release'
runs-on: windows-latest
environment: deploy
needs:
- formatting
- coverage
- run-tests
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup .NET
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1
with:
dotnet-version: 8.0.303
- name: Build
run: dotnet build -c Release
- name: Pack
run: |
$semver = "$env:GITHUB_REF_NAME"
if ($semver -match '^(\d+)\.(\d+)\.\d+') {
$major = $matches[1]
$minor = $matches[2]
$packageVersion = "$env:GITHUB_REF_NAME"
$assemblyVersion = "$major.$minor.$env:GITHUB_RUN_NUMBER.0"
Write-Host "Package version: $packageVersion"
Write-Host "Assembly version: $assemblyVersion"
dotnet pack -c Release --output nupkgs -p:PackageVersion=$packageVersion -p:AssemblyVersion=$assemblyVersion
} else {
throw "Invalid semver format"
}
- name: Check release conditions
shell: bash
run: |
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+(-[a-z]+.[0-9]+)?|"refs/heads/main"$ ]]; then
echo "CREATE_RELEASE=true" >> "$GITHUB_ENV"
else
echo "CREATE_RELEASE=false" >> "$GITHUB_ENV"
fi
- name: Push
if: env.CREATE_RELEASE == 'true'
run: dotnet nuget push .\nupkgs\*.nupkg --source https://api.nuget.org/v3/index.json --api-key "$env:NUGET_API_KEY"
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}