Skip to content

Commit 9b09747

Browse files
committed
CI: build
1 parent 8e8130f commit 9b09747

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed

.github/workflows/build-and-test.yml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: build-and-test (reusable workflow)
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
dotnet-version:
10+
description: "required dotnet version. The default is '8.0.x'."
11+
required: true
12+
type: string
13+
default: '8.0.x'
14+
dotnet-framework:
15+
description: "target framework for dotnet test. The default is 'net8.0'."
16+
required: true
17+
type: string
18+
default: 'net8.0'
19+
configuration:
20+
description: "The configuration to use for building the package. The default is 'Release'."
21+
required: true
22+
type: string
23+
default: 'Release'
24+
25+
jobs:
26+
build-and-test:
27+
runs-on: ubuntu-22.04
28+
env:
29+
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
30+
steps:
31+
- run: echo "The inputs.dotnet version is ${{ inputs.dotnet-version }}, framework is ${{ inputs.dotnet-framework }}."
32+
- run: echo "The inputs.configuration is ${{ inputs.configuration }}."
33+
- run: echo "The job was automatically triggered by a ${{ github.event_name }} event."
34+
- run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!"
35+
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
36+
37+
- name: Check out repository code
38+
uses: actions/checkout@v4
39+
- run: echo "The ${{ github.repository }} repository has been cloned to the runner."
40+
- run: echo "The workflow is now ready to test your code on the runner."
41+
- name: List files in the repository
42+
run: |
43+
ls -la ${{ github.workspace }}
44+
sudo cat ./.github/workflows/build-and-test.yml
45+
46+
- name: Setup dotnet
47+
uses: actions/setup-dotnet@v4
48+
with:
49+
dotnet-version: ${{ inputs.dotnet-version }}
50+
global-json-file: global.json
51+
cache: false
52+
53+
- name: Display dotnet version
54+
run: |
55+
DOTNET_VERSION=$(dotnet --version)
56+
echo "DOTNET_VERSION=$DOTNET_VERSION" >> $GITHUB_ENV
57+
DOTNET_VERSION_MAJOR=$(echo $DOTNET_VERSION | cut -d '.' -f 1)
58+
DOTNET_VERSION_MINOR=$(echo $DOTNET_VERSION | cut -d '.' -f 2)
59+
echo "DOTNET_VERSION_MAJOR=$DOTNET_VERSION_MAJOR" >> $GITHUB_ENV
60+
echo "DOTNET_VERSION_MINOR=$DOTNET_VERSION_MINOR" >> $GITHUB_ENV
61+
echo "DOTNET_VERSION_MAJOR_MINOR=$DOTNET_VERSION_MAJOR.$DOTNET_VERSION_MINOR" >> $GITHUB_ENV
62+
echo "dotnet ${{ env.DOTNET_VERSION }} is installed."
63+
64+
- name: Fixing error 'No usable version of libssl was found' for dotnet 3.1.x
65+
if: ${{ env.DOTNET_VERSION_MAJOR_MINOR == '3.1' }}
66+
run: |
67+
sudo apt-get update
68+
sudo apt-get install -y libssl-dev libssl1.1
69+
70+
- name: Install dependencies
71+
run: dotnet restore
72+
- name: Build
73+
run: dotnet build --no-restore --configuration ${{ inputs.configuration }}
74+
75+
- name: Test with the dotnet CLI
76+
run: dotnet test --no-build --framework ${{ inputs.dotnet-framework }} --configuration ${{ inputs.configuration }} --verbosity normal --logger trx --results-directory "TestResults-${{ inputs.configuration }}-${{ inputs.dotnet-framework }}"
77+
- name: Upload dotnet test results
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: dontet-results-${{ inputs.configuration }}-${{ inputs.dotnet-framework }}
81+
path: TestResults-${{ inputs.configuration }}-${{ inputs.dotnet-framework }}
82+
if: ${{ always() }}
83+
84+
- run: echo "This job's status is ${{ job.status }}."
85+

.github/workflows/test.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: test
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches: [ master ]
9+
paths-ignore:
10+
- "*.md"
11+
- ".github/**"
12+
pull_request:
13+
branches: [ master ]
14+
paths-ignore:
15+
- "*.md"
16+
- ".github/**"
17+
18+
jobs:
19+
build-and-test:
20+
strategy:
21+
matrix:
22+
dotnet:
23+
- version: '3.1.x'
24+
framework: 'netcoreapp3.1'
25+
configuration: [ Debug, Release ]
26+
uses: ./.github/workflows/build-and-test.yml
27+
with:
28+
dotnet-version: ${{ matrix.dotnet.version }}
29+
dotnet-framework: ${{ matrix.dotnet.framework }}
30+
configuration: ${{ matrix.configuration }}
31+

Demo.sln

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29409.12
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.35806.99 d17.13
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{672FEA18-F072-4549-9C4C-DBD1F9CDC7BB}"
77
EndProject
@@ -23,6 +23,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Data.Host", "src\Core\
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Data", "src\Core\Demo.Data\Demo.Data.csproj", "{FD8A1277-9337-4B0B-8800-AA269AC317BF}"
2525
EndProject
26+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
27+
ProjectSection(SolutionItems) = preProject
28+
.github\workflows\build-and-test.yml = .github\workflows\build-and-test.yml
29+
.github\workflows\test.yml = .github\workflows\test.yml
30+
EndProjectSection
31+
EndProject
2632
Global
2733
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2834
Debug|Any CPU = Debug|Any CPU
@@ -54,6 +60,7 @@ Global
5460
{FD6D39EB-05EB-4F9C-8547-0880A6AF25ED} = {672FEA18-F072-4549-9C4C-DBD1F9CDC7BB}
5561
{69FD9DCC-3F64-430E-8722-CA33A58E3ED4} = {672FEA18-F072-4549-9C4C-DBD1F9CDC7BB}
5662
{FD8A1277-9337-4B0B-8800-AA269AC317BF} = {672FEA18-F072-4549-9C4C-DBD1F9CDC7BB}
63+
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {E9754587-13F5-4E3A-9F3F-71C98EF97990}
5764
EndGlobalSection
5865
GlobalSection(ExtensibilityGlobals) = postSolution
5966
SolutionGuid = {2AEDFD1F-BBE1-4727-9978-2FB04DCE84AF}

0 commit comments

Comments
 (0)