-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (70 loc) · 2.65 KB
/
Copy pathcommon-build.yml
File metadata and controls
87 lines (70 loc) · 2.65 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
name: Build
on:
workflow_call:
secrets:
DYNAMICWEB_NUGET_API_KEY:
required: true
permissions:
contents: read
pull-requests: write
issues: write
env:
PROJECT_PATH: '**/*.csproj'
PRIVATE_NUGET_FEED_URL: 'https://core.nuget.dynamicweb-cms.com/v3/index.json'
PRIVATE_NUGET_FEED_API_KEY: ${{ secrets.DYNAMICWEB_NUGET_API_KEY }}
jobs:
build-and-publish:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Generate prerelease version
id: version
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
RUN_NUMBER=${{ github.run_number }}
# Use dotnet to evaluate the VersionPrefix property
BASE_VERSION=$(dotnet msbuild ${{ env.PROJECT_PATH }} -getProperty:VersionPrefix -nologo)
# If VersionPrefix is empty, try Version property
if [ -z "$BASE_VERSION" ]; then
BASE_VERSION=$(dotnet msbuild ${{ env.PROJECT_PATH }} -getProperty:Version -nologo)
fi
# Fail only if both properties are empty
if [ -z "$BASE_VERSION" ]; then
echo "Error: Could not extract VersionPrefix or Version from ${{ env.PROJECT_PATH }}"
exit 1
fi
PRERELEASE_VERSION="${BASE_VERSION}-pr${PR_NUMBER}.${RUN_NUMBER}"
echo "prerelease_version=${PRERELEASE_VERSION}" >> $GITHUB_OUTPUT
echo "Extracted base version: ${BASE_VERSION}"
echo "Generated prerelease version: ${PRERELEASE_VERSION}"
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Pack NuGet package
run: |
dotnet pack ${{ env.PROJECT_PATH }} \
--no-build \
--configuration Release \
--output ./artifacts \
-p:PackageVersion=${{ steps.version.outputs.prerelease_version }} \
-p:VersionSuffix=""
- name: Push to Dynamicweb NuGet feed
run: |
dotnet nuget push ./artifacts/*.nupkg \
--api-key ${{ secrets.DYNAMICWEB_NUGET_API_KEY }} \
--source ${{ env.PRIVATE_NUGET_FEED_URL }} \
--skip-duplicate
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package-pr${{ github.event.pull_request.number }}
path: ./artifacts/*.nupkg