-
-
Notifications
You must be signed in to change notification settings - Fork 27
155 lines (131 loc) · 4.97 KB
/
ci.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
name: ci
on:
workflow_dispatch:
push:
pull_request:
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET 7
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release
- name: Test
run: dotnet test --configuration Release --logger trx --results-directory reports --collect:"XPlat Code Coverage"
- name: Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: report
path: reports/*.trx
reporter: dotnet-trx
semver:
name: semver
needs: test
runs-on: ubuntu-latest
outputs:
label: ${{steps.VERSION.outputs.label}}
semver: ${{steps.VERSION.outputs.semver}}
nuget: ${{steps.VERSION.outputs.nuget}}
prerelease: ${{steps.VERSION.outputs.prerelease}}
applicable: ${{steps.VERSION.outputs.applicable}}
previous: ${{steps.LAST.outputs.tag}}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup GitVersion
run: dotnet tool install --global GitVersion.Tool
- name: Fetch Git tags
run: git fetch --tags --unshallow
- name: Fetch main branch
if: github.ref != 'refs/heads/main'
run: git branch --create-reflog main origin/main
- name: Query last tag
id: LAST
run: echo ::set-output name=tag::$(git describe --tags --abbrev=0)
- name: Update version
run: dotnet-gitversion /updateprojectfiles /updateassemblyinfo /output buildserver
- name: Set job output
id: VERSION
run: |
echo '::set-output name=label::${{env.GitVersion_PreReleaseLabel}}'
echo '::set-output name=semver::${{env.GitVersion_LegacySemVer}}'
echo '::set-output name=nuget::${{env.GitVersion_NuGetPreReleaseTagV2}}'
echo '::set-output name=prerelease::${{env.GitVersion_PreReleaseLabel == 'alpha' || env.GitVersion_PreReleaseLabel == 'beta' }}'
echo '::set-output name=applicable::${{github.ref == 'refs/heads/main' || env.GitVersion_PreReleaseLabel == 'alpha' || env.GitVersion_PreReleaseLabel == 'beta'}}'
- name: Push version bump
if: ${{env.GitVersion_PreReleaseLabel == '' || env.GitVersion_PreReleaseLabel == 'alpha' || env.GitVersion_PreReleaseLabel == 'beta'}}
uses: EndBug/add-and-commit@v9
with:
author_name: github-actions[bot]
author_email: github-actions[bot]@users.noreply.github.com
message: "Bumped version to ${{env.GitVersion_LegacySemVer}}"
approve:
name: approve
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Approve pull request
uses: juliangruber/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.number }}
release:
name: release
needs: semver
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
nuget_key: ${{ secrets.NUGET_KEY }}
steps:
- name: Setup Ruby v3
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
- name: Install changelog generator
run: gem install github_changelog_generator
- name: Generate changelog
run: github_changelog_generator -u ${{github.repository_owner}} -p ${{github.event.repository.name}} --token ${{secrets.GITHUB_TOKEN}} --since-tag ${{needs.semver.outputs.previous}} --future-release ${{needs.semver.outputs.semver}}
- name: Create release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
tag_name: ${{needs.semver.outputs.semver}}
name: v${{needs.semver.outputs.semver}}
body_path: CHANGELOG.md
prerelease: ${{needs.semver.outputs.prerelease}}
publish:
name: publish
needs: semver
runs-on: ubuntu-latest
if: github.event_name == 'push' && needs.semver.outputs.applicable == 'true'
env:
nuget_key: ${{ secrets.NUGET_KEY }}
steps:
- name: Checkout code
if: ${{env.nuget_key != ''}}
uses: actions/checkout@v3
- name: Setup .NET 7
if: ${{env.nuget_key != ''}}
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Restore dependencies
if: ${{env.nuget_key != ''}}
run: dotnet restore
- name: Pack
if: ${{env.nuget_key != ''}}
run: dotnet pack --configuration Release --output nupkgs --include-symbols --include-source
- name: Publish project to NuGet
if: ${{env.nuget_key != ''}}
run: dotnet nuget push '**/*.nupkg' -k ${{env.nuget_key}} -s https://api.nuget.org/v3/index.json --skip-duplicate