Skip to content

Commit 5c6bed8

Browse files
committed
added test ci
1 parent 2dd66b9 commit 5c6bed8

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: '10.0.x'
21+
22+
- name: Restore dependencies
23+
run: dotnet restore src/IsNullOrEmpty.slnx
24+
25+
- name: Build
26+
run: dotnet build src/IsNullOrEmpty.slnx --no-restore --configuration Release
27+
28+
- name: Upload build artifacts
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: build-artifacts
32+
path: |
33+
src/**/bin/Release
34+
tests/**/bin/Release
35+
36+
test:
37+
runs-on: ubuntu-latest
38+
needs: build
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Setup .NET
44+
uses: actions/setup-dotnet@v4
45+
with:
46+
dotnet-version: '10.0.x'
47+
48+
- name: Download build artifacts
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: build-artifacts
52+
53+
- name: Restore dependencies
54+
run: dotnet restore src/IsNullOrEmpty.slnx
55+
56+
- name: Test with coverage
57+
run: dotnet test src/IsNullOrEmpty.slnx --no-build --configuration Release --collect:"XPlat Code Coverage" --results-directory ./coverage
58+
59+
- name: Find coverage file
60+
id: coverage
61+
run: echo "file=$(find ./coverage -name 'coverage.cobertura.xml' | head -1)" >> $GITHUB_OUTPUT
62+
63+
- name: Upload coverage to Codecov
64+
uses: codecov/codecov-action@v5
65+
with:
66+
files: ${{ steps.coverage.outputs.file }}
67+
fail_ci_if_error: false
68+
token: ${{ secrets.CODECOV_TOKEN }}
69+
70+
publish:
71+
runs-on: ubuntu-latest
72+
needs: test
73+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
74+
permissions:
75+
contents: write
76+
packages: write
77+
78+
steps:
79+
- uses: actions/checkout@v4
80+
with:
81+
fetch-depth: 0
82+
83+
- name: Setup .NET
84+
uses: actions/setup-dotnet@v4
85+
with:
86+
dotnet-version: '10.0.x'
87+
88+
- name: Extract version from csproj
89+
id: version
90+
run: |
91+
VERSION=$(grep -oP '(?<=<Version>)[^<]+' src/IsNullOrEmpty/IsNullOrEmpty.csproj)
92+
echo "version=$VERSION" >> $GITHUB_OUTPUT
93+
echo "Extracted version: $VERSION"
94+
95+
- name: Check if tag exists
96+
id: tag_check
97+
run: |
98+
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
99+
echo "exists=true" >> $GITHUB_OUTPUT
100+
echo "Tag v${{ steps.version.outputs.version }} already exists. Skipping publish."
101+
else
102+
echo "exists=false" >> $GITHUB_OUTPUT
103+
echo "Tag v${{ steps.version.outputs.version }} does not exist. Will publish."
104+
fi
105+
106+
- name: Restore dependencies
107+
if: steps.tag_check.outputs.exists == 'false'
108+
run: dotnet restore src/IsNullOrEmpty.slnx
109+
110+
- name: Build
111+
if: steps.tag_check.outputs.exists == 'false'
112+
run: dotnet build src/IsNullOrEmpty.slnx --configuration Release --no-restore
113+
114+
- name: Pack
115+
if: steps.tag_check.outputs.exists == 'false'
116+
run: dotnet pack src/IsNullOrEmpty/IsNullOrEmpty.csproj --configuration Release --no-build --output ./nupkg
117+
118+
- name: Publish to NuGet
119+
if: steps.tag_check.outputs.exists == 'false'
120+
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
121+
122+
- name: Publish to GitHub Packages
123+
if: steps.tag_check.outputs.exists == 'false'
124+
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
125+
126+
- name: Create and push tag
127+
if: steps.tag_check.outputs.exists == 'false'
128+
run: |
129+
git config user.name "github-actions[bot]"
130+
git config user.email "github-actions[bot]@users.noreply.github.com"
131+
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
132+
git push origin "v${{ steps.version.outputs.version }}"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Extensions.IsNullOrEmpty
44
[![NuGet Version](https://img.shields.io/nuget/v/Kebechet.Extensions.IsNullOrEmpty)](https://www.nuget.org/packages/Kebechet.Extensions.IsNullOrEmpty/)
55
[![NuGet Downloads](https://img.shields.io/nuget/dt/Kebechet.Extensions.IsNullOrEmpty)](https://www.nuget.org/packages/Kebechet.Extensions.IsNullOrEmpty/)
6+
[![CI](https://github.com/Kebechet/Extensions.IsNullOrEmpty/actions/workflows/ci.yml/badge.svg)](https://github.com/Kebechet/Extensions.IsNullOrEmpty/actions/workflows/ci.yml)
67
[![codecov](https://codecov.io/gh/Kebechet/Extensions.IsNullOrEmpty/graph/badge.svg)](https://codecov.io/gh/Kebechet/Extensions.IsNullOrEmpty)
78
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/samuel_sidor.svg?style=social&label=Follow%20samuel_sidor)](https://x.com/samuel_sidor)
89

0 commit comments

Comments
 (0)