-
Notifications
You must be signed in to change notification settings - Fork 1
83 lines (65 loc) · 2.8 KB
/
publish.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
name: Publish
on:
workflow_dispatch:
release:
types: [published]
env:
BRANCH_NAME: ${{ github.event.release.target_commitish }}
SOLUTION_NAME: ${{ vars.SOLUTION_NAME }}
DOTNET_VERSION: '9.0.x'
NUGET_SOURCE: 'https://api.nuget.org/v3/index.json'
BUILD_CONFIGURATION: ''
VERSION_SUFFIX: ''
jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- name: Release Configuration
if: ${{ env.BRANCH_NAME == 'main' && (github.event.release.prerelease == false || github.event_name == 'workflow_dispatch') }}
run: |
echo "BUILD_CONFIGURATION=Release" >> $GITHUB_ENV
- name: Debug Configuration
if: ${{ (github.event.release.prerelease || github.event_name == 'workflow_dispatch') }}
run: |
echo "BUILD_CONFIGURATION=Debug" >> $GITHUB_ENV
- name: Check Build Configuration
if: ${{ env.BUILD_CONFIGURATION == '' }}
run: |
echo "Invalid Build Configuration"
exit 1
- name: Checkout Code
uses: actions/checkout@v4
- name: Get Current Version
id: get_version
shell: pwsh
run: |
Import-Module ./solution-helper.psm1 -Force
$build_version = Get-Version
echo "build_version=$build_version" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Get Version Suffix
id: get_version_suffix
shell: bash
run: |
# Fetch the list of releases
releases=$(gh release list --json createdAt,tagName --limit 100)
# Filter the releases based on the starting version number, sort them by date, and extract the most recent one
latest_release=$(echo "$releases" | jq -r --arg build_version "$build_version" 'map(select(.tagName | startswith($build_version))) | sort_by(.createdAt) | reverse | .[0] | .tagName')
version_suffix=${latest_release#*$build_version-}
if [ "$version_suffix" == "$build_version" ]; then
version_suffix=""
fi
echo "VERSION_SUFFIX=$version_suffix" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore Dependencies
run: dotnet restore ${{ env.SOLUTION_NAME }}
- name: Build
run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} ${{ env.SOLUTION_NAME }}
- name: Test
run: dotnet test --no-build --verbosity normal --configuration ${{ env.BUILD_CONFIGURATION }} ${{ env.SOLUTION_NAME }}
- name: Pack and Push
run: dotnet pack --no-build --configuration ${{ env.BUILD_CONFIGURATION }} -p:PackageOutputPath=../../output --version-suffix "${{ env.VERSION_SUFFIX }}" -p:PackageSource='${{ env.NUGET_SOURCE }}' -p:PushAfterPack=true -p:PackageApiKey='${{ secrets.NUGET_API_KEY }}'