-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (95 loc) · 3.03 KB
/
release.yml
File metadata and controls
112 lines (95 loc) · 3.03 KB
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
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: "Package/release version (e.g. 1.3.1)"
required: true
type: string
permissions:
contents: write
concurrency:
group: release-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Resolve version
id: vars
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
TAG="v${VERSION}"
else
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
fi
if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+].*)?$ ]]; then
echo "Invalid version: ${VERSION}"
exit 1
fi
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
- name: Ensure tag exists for manual runs
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
TAG="${{ steps.vars.outputs.tag }}"
git fetch --tags --force
if ! git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "Tag ${TAG} does not exist in repository."
echo "Create and push it first (for example: git tag ${TAG} && git push origin ${TAG})."
exit 1
fi
- name: Restore
run: dotnet restore Clockworks.sln
- name: Build
run: dotnet build Clockworks.sln -c Release --no-restore
- name: Test
run: dotnet test tests/Clockworks.Tests.csproj -c Release --no-build --nologo
- name: Pack
run: >
dotnet pack src/Clockworks.csproj
-c Release
--no-build
-p:PackageVersion=${{ steps.vars.outputs.version }}
-o artifacts/packages
- name: Validate NuGet API key
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
shell: bash
run: |
if [[ -z "${NUGET_API_KEY}" ]]; then
echo "NUGET_API_KEY secret is missing or empty."
echo "Set repository secret NUGET_API_KEY before running release workflow."
exit 1
fi
- name: Push package to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: >
dotnet nuget push artifacts/packages/*.nupkg
--api-key "${NUGET_API_KEY}"
--source https://api.nuget.org/v3/index.json
--skip-duplicate
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.vars.outputs.tag }}
generate_release_notes: true
files: |
artifacts/packages/*.nupkg
artifacts/packages/*.snupkg