-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (97 loc) · 4.16 KB
/
create-nuget.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
name: Build NuGet
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
check-version-change:
runs-on: windows-latest
outputs:
version_changed: ${{ steps.check.outputs.version_changed }}
steps:
- name: Extract repo name
run: |
$repoName = "${{ github.repository }}".Split('/')[1]
echo "REPO_NAME=$repoName" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'
token: ${{ secrets.BUILD_TOKEN }}
- name: Check for version.json changes
id: check
run: |
$versionFile = ".version/version.json"
$versionChanged = git diff --name-only ${{ github.event.before }} ${{ github.sha }} | Select-String -Pattern $versionFile -Quiet
if ($versionChanged) {
echo "VERSION_CHANGED=true" | Out-File -Append -FilePath $Env:GITHUB_ENV
} else {
echo "VERSION_CHANGED=false" | Out-File -Append -FilePath $Env:GITHUB_ENV
}
echo "version_changed=$versionChanged" >> $GITHUB_ENV
- name: Add GitHub Packages source
run: |
nuget sources Add -Name "GitHub" -Source "https://nuget.pkg.github.com/PrimeEagle/index.json" -Username ${{ github.repository_owner }} -Password ${{ secrets.BUILD_TOKEN }}
create-package:
needs: check-version-change
runs-on: windows-latest
if: github.event_name == 'workflow_dispatch' || needs.check-version-change.outputs.version_changed == 'True'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'
token: ${{ secrets.BUILD_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ secrets.DOTNET_VERSION }}
- name: Add GitHub Packages source
run: |
nuget sources Add -Name "GitHub" -Source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" -Username ${{ github.repository_owner }} -Password ${{ secrets.BUILD_TOKEN }}
- name: Read Version from version.json
run: |
$versionFile = ".version/version.json"
$versionJson = Get-Content $versionFile -Raw | ConvertFrom-Json
echo "VERSION_NUMBER=$($versionJson.version)" | Out-File -Append -FilePath $Env:GITHUB_ENV
- name: Print Version Number
run: echo "Version number is $env:VERSION_NUMBER"
- name: Pack
run: dotnet pack $env:GITHUB_ENV.sln --configuration Release -o nupkgs /p:Version=${{ env.VERSION_NUMBER }} /p:ServerBuild=true
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: nuget-packages
path: nupkgs/*.nupkg
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: nuget-packages
path: nupkgs
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ secrets.DOTNET_VERSION }}
- name: Determine Package File
id: package_file
run: |
$PACKAGE_FILE = Get-ChildItem nupkgs/*.nupkg | Sort-Object LastWriteTime | Select-Object -Last 1 -ExpandProperty FullName
echo "PACKAGE_FILE=$PACKAGE_FILE" | Out-File -Append -FilePath $Env:GITHUB_ENV
- name: Publish
run: |
dotnet nuget push "${{ env.PACKAGE_FILE }}" --source "github" --skip-duplicate --api-key ${{ secrets.BUILD_TOKEN }}
- name: Update version-nuget.json
run: |
$NugetVersion = "${{ env.VERSION_NUMBER }}"
$VersionData = @{
version = $NugetVersion
}
$nugetVersionFile = ".version/version-nuget.json"
$VersionData | ConvertTo-Json | Set-Content -Path $nugetVersionFile
git config --global user.email "${{ secrets.USER_EMAIL }}"
git config --global user.name "${{ github.repository_owner }}"
git add $nugetVersionFile
git commit -m "Update NuGet package version to $NugetVersion"
git push