11name : .NET build
2-
32on :
43 push :
54 branches : [ master ]
65 pull_request :
76 branches : [ master ]
8-
97jobs :
108 build :
11-
129 runs-on : ubuntu-latest
1310 steps :
14- - name : Determine Git Checkout information
15- id : checkout-info
16- run : |
17- if [ $GITHUB_EVENT_NAME == 'pull_request' ]; then
18- BRANCH_NAME=$(echo ${{ github.event.pull_request.head.ref }})
19- REPOSITORY_NAME=$(echo ${{ github.event.pull_request.head.repo.full_name }})
20- else
21- BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
22- REPOSITORY_NAME=$(echo ${{ github.repository }})
23- fi
24-
25- echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
26- echo "REPOSITORY_NAME=$REPOSITORY_NAME" >> $GITHUB_ENV
27- echo "Git checkout information:"
28- echo "Branch name: $BRANCH_NAME"
29- echo "Repository name: $REPOSITORY_NAME"
30-
3111 - name : Git Checkout
32- uses : actions/checkout@v2
12+ uses : actions/checkout@v3
3313 with :
3414 ref : ${{github.event.pull_request.head.ref}}
3515 repository : ${{github.event.pull_request.head.repo.full_name}}
36-
37- - name : Force fetch tags
38- run : |
39- # get current repository tags
40- git fetch --tags --force
41-
42- # deal with forked repositories
43- git remote add upstream https://github.com/${{ github.repository }}
44- git fetch --tags upstream
45-
46- - name : Find last tag
47- id : prev-version-tag
48- run : |
49- last_tag=$(git tag -l "*[0-9].*[0-9].*[0-9]*" --sort "-version:refname" | head -n 1)
50- echo "::set-output name=tag::$last_tag"
51-
52- - name : Find last commit message
53- id : last-commit-message
54- run : |
55- last_commit_message=$(git log -1 --pretty=%s $BRANCH_NAME --)
56- echo "Last commit message found:"
57- echo " $last_commit_message"
58- echo "LAST_COMMIT_MESSAGE=$last_commit_message" >> $GITHUB_ENV
59-
60- - name : Bump next build version options
61- id : semvers
62- uses : " WyriHaximus/github-action-next-semvers@v1.0"
63- with :
64- version : ${{ steps.prev-version-tag.outputs.tag }}
65-
66- - name : Set next build version
67- id : build-context
68- env :
69- MAJOR : ${{steps.semvers.outputs.major}}
70- MINOR : ${{steps.semvers.outputs.minor}}
71- PATCH : ${{steps.semvers.outputs.patch}}
72- CURRENT : ${{steps.prev-version-tag.outputs.tag}}
73- run : |
74- echo "::set-output name=current-version::$CURRENT"
75-
76- if [[ $LAST_COMMIT_MESSAGE =~ ^major:.*$ ]]; then
77- echo "Bumping to next major version."
78- NEXT_VERSION="$MAJOR"
79- elif [[ $LAST_COMMIT_MESSAGE =~ ^feat:.*$ ]]; then
80- echo "Bumping to next minor version."
81- NEXT_VERSION="$MINOR"
82- elif [[ $LAST_COMMIT_MESSAGE =~ ^(fix|ci|refactor|chore):.*$ ]]; then
83- echo "Bumping to next patch version."
84- NEXT_VERSION="$PATCH"
85- else
86- echo "Skipping version bump."
87- NEXT_VERSION="$CURRENT"
88- fi
89-
90- if [[ $BRANCH_NAME = 'master' ]]; then
91- echo '::set-output name=context::release'
92- elif [[ $NEXT_VERSION != $CURRENT ]]; then
93- NEXT_VERSION="$NEXT_VERSION-beta"
94- echo '::set-output name=context::beta'
95- else
96- echo '::set-output name=context::beta'
97- fi
98-
99- echo "::set-output name=next-version::$NEXT_VERSION"
100- echo "Next version is: $NEXT_VERSION"
101- echo "BUILD_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
102-
103- - name : Print build version
104- run : echo "Build version will be $BUILD_VERSION"
105-
106- - name : Update project version
107- uses : roryprimrose/set-vs-sdk-project-version@v1
108- with :
109- projectFilter : ' *.csproj'
110- version : ${{ env.BUILD_VERSION }}
111- assemblyVersion : ${{ env.BUILD_VERSION }}
112- fileVersion : ${{ env.BUILD_VERSION }}
113- informationalVersion : ${{ env.BUILD_VERSION }}
114-
11516 - name : Setup .NET
116- uses : actions/setup-dotnet@v1
17+ uses : actions/setup-dotnet@v3
11718 with :
118- dotnet-version : |
119- 3.1.x
120- 6.0.x
121-
19+ dotnet-version : 6.0.x
20+ dotnet-quality : ga
12221 - name : Setup Report Generator
12322 run : dotnet tool install --global dotnet-reportgenerator-globaltool
124-
12523 - name : MongoDB in GitHub Actions
126- uses : supercharge/mongodb-github-action@1.6 .0
24+ uses : supercharge/mongodb-github-action@1.9 .0
12725 with :
12826 mongodb-version : ' 4.4'
129-
13027 - name : Restore dependencies
13128 run : dotnet restore
132-
13329 - name : Build
13430 run : dotnet build --no-restore -c Release
135-
31+ # Generate code coverage reports, which are recovered by Codacy afterwards.
13632 - name : Test
137- run : dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory:"../../coverage-outputs" -m:1 -c Release
138-
33+ run : dotnet test --no-build --verbosity normal -m:1 -c Release --collect:"XPlat Code Coverage" --results-directory:"../../coverage-outputs"
13934 - name : Merge coverage results
14035 run : |
141- reportgenerator -reports:"../../coverage-outputs/**/*.xml" -targetdir:"../../coverage-outputs" -reporttypes:SonarQube
36+ reportgenerator -reports:"../../coverage-outputs/**/*.xml" -targetdir:"../../coverage-outputs" -reporttypes:Cobertura
14237 rm -rfv ../../coverage-outputs/*/
143- ls -la ../../coverage-outputs
144-
145- - name : Clean
146- run : dotnet clean -c Release
147-
148- - name : Clear Nuget locals
149- run : dotnet nuget locals all --clear
150-
151- - name : Delete build tag if exists
152- uses : dev-drprasad/delete-tag-and-release@v0.2.0
153- continue-on-error : true
154- with :
155- delete_release : false
156- tag_name : ${{ env.BUILD_VERSION }}
157- env :
158- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
159-
160- - name : Set build tag
161- uses : anothrNick/github-tag-action@1.26.0
162- continue-on-error : true
163- env :
164- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
165- DEFAULT_BUMP : none
166- WITH_V : false
167- CUSTOM_TAG : ${{ env.BUILD_VERSION }}
168- TAG_CONTEXT : branch
169- RELEASE_BRANCHES : .*
38+ ls -la ../../coverage-outputs
0 commit comments