-
Notifications
You must be signed in to change notification settings - Fork 2
161 lines (139 loc) · 6.76 KB
/
build.yml
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
# based on https://dusted.codes/github-actions-for-dotnet-core-nuget-packages
name: Build CI
on:
push:
pull_request:
workflow_dispatch:
env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
# Project name to pack and publish
PROJECT_NAME: AspNetCore.VersionInfo
jobs:
build:
runs-on: ubuntu-latest
env:
CONFIGURATION: "Release"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.x'
- name: Use GitVersion
id: gitversion # step id used as reference for output values
uses: gittools/actions/gitversion/[email protected]
- name: Build info
run: |
echo "Build Info"
echo "-----------------------------------------------------------------------"
echo "Configuration: $CONFIGURATION"
echo "Run ID: ${{ github.run_id }}"
echo "Output Run Number: ${{ github.run_number }}"
echo "Major: ${{ steps.gitversion.outputs.Major }}"
echo "Minor: ${{ steps.gitversion.outputs.Minor }}"
echo "Patch: ${{ steps.gitversion.outputs.Patch }}"
echo "PreReleaseTag: ${{ steps.gitversion.outputs.PreReleaseTag }}"
echo "PreReleaseTagWithDash: ${{ steps.gitversion.outputs.PreReleaseTagWithDash }}"
echo "PreReleaseLabel: ${{ steps.gitversion.outputs.PreReleaseLabel }}"
echo "PreReleaseNumber: ${{ steps.gitversion.outputs.PreReleaseNumber }}"
echo "WeightedPreReleaseNumber: ${{ steps.gitversion.outputs.WeightedPreReleaseNumber }}"
echo "BuildMetaData: ${{ steps.gitversion.outputs.BuildMetaData }}"
echo "BuildMetaDataPadded: ${{ steps.gitversion.outputs.BuildMetaDataPadded }}"
echo "FullBuildMetaData: ${{ steps.gitversion.outputs.FullBuildMetaData }}"
echo "MajorMinorPatch: ${{ steps.gitversion.outputs.MajorMinorPatch }}"
echo "SemVer: ${{ steps.gitversion.outputs.SemVer }}"
echo "LegacySemVer: ${{ steps.gitversion.outputs.LegacySemVer }}"
echo "LegacySemVerPadded: ${{ steps.gitversion.outputs.LegacySemVerPadded }}"
echo "AssemblySemVer: ${{ steps.gitversion.outputs.AssemblySemVer }}"
echo "AssemblySemFileVer: ${{ steps.gitversion.outputs.AssemblySemFileVer }}"
echo "FullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}"
echo "InformationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }}"
echo "BranchName: ${{ steps.gitversion.outputs.BranchName }}"
echo "Sha: ${{ steps.gitversion.outputs.Sha }}"
echo "ShortSha: ${{ steps.gitversion.outputs.ShortSha }}"
echo "NuGetVersionV2: ${{ steps.gitversion.outputs.NuGetVersionV2 }}"
echo "NuGetVersion: ${{ steps.gitversion.outputs.NuGetVersion }}"
echo "NuGetPreReleaseTagV2: ${{ steps.gitversion.outputs.NuGetPreReleaseTagV2 }}"
echo "NuGetPreReleaseTag: ${{ steps.gitversion.outputs.NuGetPreReleaseTag }}"
echo "VersionSourceSha: ${{ steps.gitversion.outputs.VersionSourceSha }}"
echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
echo "CommitsSinceVersionSourcePadded: ${{ steps.gitversion.outputs.CommitsSinceVersionSourcePadded }}"
echo "CommitDate: ${{ steps.gitversion.outputs.CommitDate }}"
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Update project version
uses: roryprimrose/set-vs-sdk-project-version@v1
with:
version: "${{ steps.gitversion.outputs.NuGetVersionV2 }}-preview.${{github.run_id}}.${{github.run_number}}"
assemblyVersion: "${{steps.gitversion.outputs.MajorMinorPatch}}.${{github.run_number}}"
fileVersion: "${{steps.gitversion.outputs.MajorMinorPatch}}.${{github.run_number}}"
informationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }}
#if: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/master' }}
- name: Update project version (release)
uses: roryprimrose/set-vs-sdk-project-version@v1
with:
version: ${{ steps.gitversion.outputs.NuGetVersionV2 }}
assemblyVersion: ${{ steps.gitversion.outputs.AssemblySemVer }}
fileVersion: ${{ steps.gitversion.outputs.MajorMinorPatch }}
informationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }}
if: startsWith(github.ref, 'refs/tags/')
#### Start SonarCloud steps
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: ~/.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
mkdir -p ~/.sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path ~/.sonar/scanner
- name: Start Sonarcloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
~/.sonar/scanner/dotnet-sonarscanner begin \
/k:"salem84_AspNetCore.VersionInfo" \
/o:"salem84" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.login="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.cs.opencover.reportsPaths="**\coverage.opencover.xml"
- name: Restore dependencies
run: dotnet restore
- name: Normalize README.md for NuGet publish
run: |
sed -i 's|docs/images|https://raw.githubusercontent.com/${{ github.repository }}/master/docs/images|g' README.md
sed -i 's|<br\/>|,|g' README.md
sed -i 's|!\[/version/badge\](https:[^)]*)|/version/badge|g' README.md
sed -i 's|!\[\(.*\)\](\(https:\/\/via.placeholder.com[^)]*\))|\1|g' README.md
- name: Build
run: dotnet build --no-restore --configuration $CONFIGURATION
- name: Test
run: dotnet test --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=coverage.opencover.xml
- name: Stop Sonarcloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ~/.sonar/scanner/dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"