Skip to content

Commit 0570d40

Browse files
committed
Update CI
1 parent 9829ede commit 0570d40

File tree

4 files changed

+116
-62
lines changed

4 files changed

+116
-62
lines changed

.github/workflows/main.yml

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
name: Build-and-test
1+
name: Build and Test
2+
23
on:
34
push:
45
branches:
5-
- '*'
6+
- master
7+
- main
68
pull_request:
79
branches:
8-
- '*'
10+
- master
11+
- main
12+
913
jobs:
1014
build:
1115
runs-on: ubuntu-latest
12-
timeout-minutes: 3
1316
steps:
1417
- name: Checkout
1518
uses: actions/checkout@v4
@@ -18,9 +21,51 @@ jobs:
1821
test:
1922
runs-on: ubuntu-latest
2023
needs: build
21-
timeout-minutes: 3
2224
steps:
2325
- name: Checkout
2426
uses: actions/checkout@v4
2527
- name: Test
2628
run: dotnet test --configuration Release
29+
sonarqube:
30+
name: sonarqube
31+
runs-on: ubuntu-latest
32+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
33+
steps:
34+
- name: Set up JDK 17
35+
uses: actions/setup-java@v4
36+
with:
37+
distribution: 'microsoft' # See 'Supported distributions' for available options
38+
java-version: '17'
39+
- uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
42+
- name: Cache SonarCloud packages
43+
uses: actions/cache@v4
44+
with:
45+
path: ~\sonar\cache
46+
key: ${{ runner.os }}-sonar
47+
restore-keys: ${{ runner.os }}-sonar
48+
- name: Cache SonarCloud scanner
49+
id: cache-sonar-scanner
50+
uses: actions/cache@v4
51+
with:
52+
path: .\.sonar\scanner
53+
key: ${{ runner.os }}-sonar-scanner
54+
restore-keys: ${{ runner.os }}-sonar-scanner
55+
- name: Install SonarCloud scanner
56+
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
57+
shell: powershell
58+
run: |
59+
New-Item -Path .\.sonar\scanner -ItemType Directory
60+
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
61+
- name: Build and analyze
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
64+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
65+
shell: powershell
66+
run: |
67+
dotnet tool install --global dotnet-coverage
68+
.\.sonar\scanner\dotnet-sonarscanner begin /k:"RxTelegram_RxTelegram.Bot" /o:"rxtelegram" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
69+
dotnet build --configuration Release
70+
dotnet-coverage collect 'dotnet test' -f xml -o 'coverage.xml' --settings CodeCoverage.runsettings
71+
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"

.github/workflows/publish.yml

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,72 @@
11
name: Publish-to-nuget
22
on:
3-
workflow_run:
4-
workflows: ["Check-code-quality"]
5-
branches: ["v[0-9]+.[0-9]+.[0-9]+"]
6-
types:
7-
- completed
3+
push:
4+
tags:
5+
- "v[0-9]+.[0-9]+.[0-9]+"
6+
87
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
- name: Build
14+
run: dotnet build --configuration Release
15+
test:
16+
runs-on: ubuntu-latest
17+
needs: build
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- name: Test
22+
run: dotnet test --configuration Release
23+
sonarqube:
24+
name: sonarqube
25+
runs-on: ubuntu-latest
26+
needs: test
27+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
28+
steps:
29+
- name: Set up JDK 17
30+
uses: actions/setup-java@v4
31+
with:
32+
distribution: 'microsoft' # See 'Supported distributions' for available options
33+
java-version: '17'
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
37+
- name: Cache SonarCloud packages
38+
uses: actions/cache@v4
39+
with:
40+
path: ~\sonar\cache
41+
key: ${{ runner.os }}-sonar
42+
restore-keys: ${{ runner.os }}-sonar
43+
- name: Cache SonarCloud scanner
44+
id: cache-sonar-scanner
45+
uses: actions/cache@v4
46+
with:
47+
path: .\.sonar\scanner
48+
key: ${{ runner.os }}-sonar-scanner
49+
restore-keys: ${{ runner.os }}-sonar-scanner
50+
- name: Install SonarCloud scanner
51+
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
52+
shell: powershell
53+
run: |
54+
New-Item -Path .\.sonar\scanner -ItemType Directory
55+
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
56+
- name: Build and analyze
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
59+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
60+
shell: powershell
61+
run: |
62+
dotnet tool install --global dotnet-coverage
63+
.\.sonar\scanner\dotnet-sonarscanner begin /k:"RxTelegram_RxTelegram.Bot" /o:"rxtelegram" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
64+
dotnet build --configuration Release
65+
dotnet-coverage collect 'dotnet test' -f xml -o 'coverage.xml' --settings CodeCoverage.runsettings
66+
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
967
publish:
1068
runs-on: ubuntu-latest
11-
timeout-minutes: 3
69+
needs: sonarqube
1270
steps:
1371
- name: Download build result
1472
uses: actions/download-artifact@v4
@@ -20,3 +78,5 @@ jobs:
2078
run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output .
2179
- name: Push nuget to nuget.org
2280
run: dotnet nuget push RxTelegram.Bot.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json
81+
- name: Publish release
82+
uses: ghalactic/github-release-from-tag@v5

.github/workflows/sonarqube.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

RxTelegram.Bot.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
2020
ProjectSection(SolutionItems) = preProject
2121
.github\workflows\main.yml = .github\workflows\main.yml
2222
.github\workflows\publish.yml = .github\workflows\publish.yml
23-
.github\workflows\sonarqube.yml = .github\workflows\sonarqube.yml
2423
EndProjectSection
2524
EndProject
2625
Global

0 commit comments

Comments
 (0)