forked from litedb-org/LiteDB
-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (139 loc) · 4.62 KB
/
publish.yml
File metadata and controls
165 lines (139 loc) · 4.62 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Build & Publish
on:
workflow_dispatch:
env:
DOTNET_VERSION: '10.0.x'
OUTPUT: './artifacts'
jobs:
publish:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# -------------------------
# Skip logic
# -------------------------
- name: Check skip
id: skip
shell: pwsh
run: |
$msg = git log -1 --pretty=%s
if ($msg -match "^(docs|nobuild):") {
"skip=true" >> $env:GITHUB_OUTPUT
} else {
"skip=false" >> $env:GITHUB_OUTPUT
}
- if: steps.skip.outputs.skip == 'true'
run: exit 0
# -------------------------
# Prerelease strategy
# -------------------------
- name: Set prerelease
id: pre
shell: pwsh
run: |
if ($env:GITHUB_REF -eq "refs/heads/main" -or $env:GITHUB_REF -eq "refs/heads/master") {
"type=" >> $env:GITHUB_OUTPUT
}
elseif ($env:GITHUB_REF -eq "refs/heads/develop") {
"type=dev" >> $env:GITHUB_OUTPUT
}
else {
"type=alpha" >> $env:GITHUB_OUTPUT
}
# -------------------------
# Versioning
# -------------------------
- name: Version
id: version
uses: ./.github/actions/versioning
with:
prerelease: ${{ steps.pre.outputs.type }}
# -------------------------
# Restore + Build solution
# -------------------------
- name: Restore
run: dotnet restore
- name: Build
shell: pwsh
run: |
$assemblyVersion = "${{ steps.version.outputs.version }}" -replace '-.*$', ''
dotnet build `
-c Release `
-p:Version=$assemblyVersion `
-p:InformationalVersion=${{ steps.version.outputs.version }}
# -------------------------
# Find packable projects
# -------------------------
- name: Find packable projects
id: packable
shell: pwsh
run: |
$projects = Get-ChildItem -Recurse -Filter *.csproj |
Where-Object { $_.FullName -notmatch '\\(obj|bin)\\' }
$packable = @()
foreach ($proj in $projects) {
$content = Get-Content $proj.FullName -Raw
if ($content -notmatch "<IsPackable>\s*false\s*</IsPackable>") {
$packable += $proj.FullName
}
}
$result = $packable -join "`n"
"projects<<EOF" >> $env:GITHUB_OUTPUT
$result >> $env:GITHUB_OUTPUT
"EOF" >> $env:GITHUB_OUTPUT
# -------------------------
# Pack ALL packable projects
# -------------------------
- name: Pack
shell: pwsh
run: |
$projects = "${{ steps.packable.outputs.projects }}" -split "`n" | Where-Object { $_ } | ForEach-Object { $_.Trim() }
$version = "${{ steps.version.outputs.version }}"
if ("${{ steps.version.outputs.is_prerelease }}" -eq "true") {
$timestamp = Get-Date -Format "yyyyMMddHHmm"
$version = "$version+$timestamp"
}
foreach ($proj in $projects) {
Write-Host "Packing $proj"
dotnet pack $proj `
-c Release `
--no-build `
-p:PackageVersion=$version `
-o $env:OUTPUT
}
# -------------------------
# Publish NuGet
# -------------------------
- name: Publish
shell: pwsh
run: |
$nupkgs = Join-Path $env:OUTPUT '*.nupkg'
dotnet nuget push $nupkgs `
--api-key "${{ secrets.NUGET_API_KEY }}" `
--source "https://api.nuget.org/v3/index.json" `
--skip-duplicate
# -------------------------
# Tag + Release (stable only)
# -------------------------
- name: Tag
if: steps.version.outputs.is_prerelease != 'true'
shell: pwsh
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
git tag ${{ steps.version.outputs.version_tag }}
git push origin --tags
- name: Release
if: steps.version.outputs.is_prerelease != 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version_tag }}
name: Release ${{ steps.version.outputs.version }}
body_path: CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}