-
-
Notifications
You must be signed in to change notification settings - Fork 105
144 lines (125 loc) · 5.04 KB
/
Publish.yml
File metadata and controls
144 lines (125 loc) · 5.04 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
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
name: Publish NuGet Package
# This job builds and publishes the package to NuGet.
# It depends on the included tests job to complete successfully.
# This workflow finds the most recent tag that starts with
# the selected major version (sorted by creatordate)
# and runs the test, build and publish tasks for that tag.
on:
workflow_dispatch:
inputs:
major_version:
description: 'Select the major version to publish (tag prefix). The workflow will pick the most recent tag that starts with this value (e.g. v3 -> v3.2.1).'
required: true
type: choice
options:
- v3
# - v4
jobs:
tests:
runs-on: ubuntu-22.04 # ubuntu-24.04 does not include mono needed for net4x tests
outputs:
VERSION: ${{ steps.resolve.outputs.VERSION }}
TAG_NAME: ${{ steps.resolve.outputs.TAG_NAME }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Show matching major version tags and select latest by creatordate
id: resolve
shell: bash
run: |
set -euo pipefail
# Call the script to resolve the latest tag for the requested major version.
# Script writes TAG_NAME and VERSION to $GITHUB_OUTPUT and $GITHUB_ENV when run on Actions.
chmod +x .github/workflows/PublishResolveVersion.sh
.github/workflows/PublishResolveVersion.sh "${{ github.event.inputs.major_version }}"
- name: Set Git config for line endings
run: git config --global core.autocrlf true
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x
8.0.x
6.0.x
3.1.x
- name: Checkout tag
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history for all tags and branches
ref: ${{ steps.resolve.outputs.TAG_NAME }}
- name: Remove Demo
run: dotnet sln ./src/SmartFormat.sln remove ./src/Demo/Demo.csproj
- name: Restore dependencies
run: dotnet restore ./src/SmartFormat.sln
- name: Build
run: dotnet build ./src/SmartFormat.sln --no-restore --configuration Release -p:nowarn=1591
- name: Test
run: dotnet test ./src/SmartFormat.sln --no-build --configuration Release --verbosity quiet
publish:
runs-on: ubuntu-24.04
needs: tests
steps:
- name: Checkout tag
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history for all tags and branches
# Reuse the tag name from tests job
ref: ${{ needs.tests.outputs.TAG_NAME }}
- name: Set Git config for line endings
run: git config --global core.autocrlf true
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x
- name: Use verified version
run: |
# Reuse the version from tests job
echo "Using version: ${{ needs.tests.outputs.VERSION }}"
echo "VERSION=${{ needs.tests.outputs.VERSION }}" >> $GITHUB_ENV
- name: Set version variables
run: |
FileVersion=${VERSION%%-*}
AssemblyVersion=${VERSION%%.*}.0.0
echo "FILE_VERSION=$FileVersion" >> $GITHUB_ENV
echo "ASSEMBLY_VERSION=$AssemblyVersion" >> $GITHUB_ENV
echo "File Version: $FileVersion"
echo "Assembly Version: $AssemblyVersion"
- name: Restore dependencies
run: dotnet restore ./src/SmartFormat.Deploy.sln
- name: Build and pack for publishing
run: |
# For version e.g. "3.1.0-pre.1", the FileVersion will be "3.1.0" and the AssemblyVersion will be "3.0.0"
# AssemblyVersion must only change for major releases
dotnet build ./src/SmartFormat.Deploy.sln --configuration Release \
-p:Version=${{env.VERSION}} \
-p:FileVersion=${{env.FILE_VERSION}} \
-p:AssemblyVersion=${{env.ASSEMBLY_VERSION}} \
-p:Nullable=enable \
-p:IncludeSymbols=true \
-p:SymbolPackageFormat=snupkg \
-p:ContinuousIntegrationBuild=true
dotnet pack ./src/SmartFormat.Deploy.sln --configuration Release \
-p:Version=${{env.VERSION}} \
-p:IncludeSymbols=true \
-p:SymbolPackageFormat=snupkg \
--no-build \
-p:PackageVersion=${{env.VERSION}} \
-p:PackageOutputPath=${{ github.workspace }}/artifacts
- name: Store artifacts
uses: actions/upload-artifact@v7
with:
name: SmartFormat-Packages_${{env.VERSION}}.${{github.run_number}}
path: |
${{ github.workspace }}/artifacts/
- name: Push package to NuGet
# Does not fail, if the package already exists
# Note: Symbol packages get uploaded automatically with the main package
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
for pkg in ${{ github.workspace }}/artifacts/*.nupkg; do
dotnet nuget push "$pkg" --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" --skip-duplicate
done