-
Notifications
You must be signed in to change notification settings - Fork 8
148 lines (128 loc) · 5.22 KB
/
release.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
name: Release
on:
workflow_dispatch:
inputs:
new_package_version:
description: 'New package version'
required: true
should_push_nuget:
description: 'Push to NuGet'
default: 'true'
required: false
should_push_github:
description: 'Push to GitHub package registry'
default: 'true'
required: false
should_commit_new_version:
description: 'Commit and push version increment'
default: 'true'
required: false
should_tag_new_version:
description: 'Tag version release'
default: 'true'
required: false
should_create_github_release:
description: 'Create GitHub Release'
default: 'true'
required: false
jobs:
release:
if: github.actor == 'eduherminio'
runs-on: ubuntu-latest
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
ARTIFACT_DIR: ./artifacts
PROJECT_NAME: AoCHelper
steps:
- name: Install hub tool
if: github.event.inputs.should_create_github_release == 'true'
run: |
sudo apt-get update && sudo apt-get install -y hub
- uses: actions/checkout@v4
- name: Configure git user
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Set version to ${{ github.event.inputs.new_package_version }}
shell: pwsh
run: |
$input_path = "src/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.csproj"
$regex = "(?<=<Version>).*(?=</Version>)"
(Get-Content $input_path) -Replace $regex, '${{ github.event.inputs.new_package_version }}' | Out-File $input_path
- name: Build
run: dotnet build -c Release /p:DeterministicBuild=true
- name: Run tests
run: dotnet test -c Release --no-build --collect:"XPlat Code Coverage"
- name: 'Generate test coverage report'
continue-on-error: true
uses: danielpalme/ReportGenerator-GitHub-Action@5
with:
reports: 'tests/**/*.cobertura.xml'
targetdir: 'coveragereport'
reporttypes: 'HtmlInline_AzurePipelines_Dark'
assemblyfilters: '+*'
classfilters: '+*;-*Exception'
filefilters: '+*'
verbosity: 'Info'
title: '${{ env.PROJECT_NAME }} #${{ github.run_number }} (${{ env.GITHUB_REF_SLUG }})'
tag: '${{ github.run_number }}_${{ github.run_id }}'
customSettings: 'numberOfReportsParsedInParallel=3;numberOfReportsMergedInParallel=3'
- name: 'Upload test coverage report'
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}.${{ github.event.inputs.new_package_version }}-coverage-${{ env.GITHUB_REF_SLUG }}-${{ github.run_number }}
path: coveragereport/
if-no-files-found: error
- name: Pack
run: |
dotnet pack -c Release --no-build src/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.csproj --include-symbols -o ${{ env.ARTIFACT_DIR }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}.${{ github.event.inputs.new_package_version }}-${{ env.GITHUB_REF_SLUG }}-${{ github.run_number }}
path: |
${{ env.ARTIFACT_DIR }}/*.nupkg
${{ env.ARTIFACT_DIR }}/*.snupkg
if-no-files-found: error
- name: Push to NuGet
if: github.event.inputs.should_push_nuget == 'true'
run: |
nuget push '${{ env.ARTIFACT_DIR }}/*.nupkg' -ApiKey ${{ secrets.NuGetKey }} -Source https://api.nuget.org/v3/index.json -SkipDuplicate -Verbosity detailed
- name: Push to GitHub packages registry
if: github.event.inputs.should_push_github == 'true'
run: |
nuget push '${{ env.ARTIFACT_DIR }}/*.nupkg' -ApiKey ${{ secrets.GitHubToken }} -Source https://nuget.pkg.github.com/eduherminio/index.json -SkipDuplicate -Verbosity detailed
- name: Commit and push version increment
if: github.event.inputs.should_commit_new_version == 'true'
continue-on-error: true
run: |
git switch ${{ env.GITHUB_REF_SLUG }}
git status
git commit -am "🚀 Release v${{ github.event.inputs.new_package_version }}"
git push
- name: Create git tag
if: github.event.inputs.should_tag_new_version == 'true'
run: |
git switch ${{ env.GITHUB_REF_SLUG }}
git status
git tag -a v${{ github.event.inputs.new_package_version }} -m "v${{ github.event.inputs.new_package_version }}"
git push --tags
- name: Create GitHub release and upload assets
if: github.event.inputs.should_create_github_release == 'true' && github.event.inputs.should_tag_new_version == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GitHubToken }}
run: |
set -x
assets=()
for asset in ${{ env.ARTIFACT_DIR }}/*; do
assets+=("-a" "$asset")
done
tag_name="v${{ github.event.inputs.new_package_version }}"
hub release create "${assets[@]}" --message "$tag_name" "$tag_name"