Skip to content

Commit 58df801

Browse files
committed
feat: publish schemas as zip and within nuget package (#168)
* feat: improve discussion with code rabbit comments
1 parent 54b18d1 commit 58df801

File tree

7 files changed

+319
-1
lines changed

7 files changed

+319
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bld/
3131
[Ll]og/
3232
[Ll]ogs/
3333
.[Pp]ublish/
34+
.[Ss]chemas/
3435

3536
# Visual Studio 2015/2017 cache/options directory
3637
.vs/

Packata.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{95E83BA6
2020
github.ps1 = github.ps1
2121
GitVersion.yml = GitVersion.yml
2222
package.ps1 = package.ps1
23+
package-delta-schemas.ps1 = package-delta-schemas.ps1
2324
EndProjectSection
2425
EndProject
2526
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Project", "Project", "{09BDFA96-353F-419D-890A-D9B9045E66DD}"

appveyor.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ test_script:
6868
.\codecov.exe --dir "./.coverage/"
6969
7070
after_test:
71+
- dotnet tool install -g Schemathief-cli
72+
- pwsh: .\package-delta-schemas.ps1
7173
- dotnet pack src/Packata.Core -p:version="%GitVersion_SemVer%" -c Release --include-symbols --no-build --nologo
7274
- dotnet pack src/Packata.ResourceReaders -p:version="%GitVersion_SemVer%" -c Release --include-symbols --no-build --nologo
7375
- dotnet pack src/Packata.Provisioners -p:version="%GitVersion_SemVer%" -c Release --include-symbols --no-build --nologo
@@ -76,6 +78,7 @@ after_test:
7678
artifacts:
7779
- path: '**\*.nupkg'
7880
- path: '**\*.snupkg'
81+
- path: '**\*.zip'
7982

8083
deploy:
8184
- provider: NuGet
@@ -92,18 +95,26 @@ on_success:
9295
if (($env:APPVEYOR_REPO_BRANCH -eq "main") -and ($null -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)) {
9396
if ($env:GitVersion_Patch -eq '0' -or $env:GitVersion_Patch -eq 0) {
9497
$context = [PSCustomObject] @{
98+
Id = $env:APPVEYOR_PULL_REQUEST_NUMBER
9599
Owner = ($env:APPVEYOR_REPO_NAME -Split '/')[0]
96100
Repository = ($env:APPVEYOR_REPO_NAME -Split '/')[1]
97101
SecretToken = $env:github_access_token
98102
}
99103
if (-not ($context | Check-Release-Published -Tag "v$($env:GitVersion_SemVer)")) {
104+
100105
$context | Publish-Release `
101106
-Tag "v$($env:GitVersion_SemVer)" `
102107
-Name "$(($env:APPVEYOR_REPO_NAME -Split '/')[1]) $($env:GitVersion_SemVer)" `
103108
-ReleaseNotes `
104109
-DiscussionCategory 'Announcements'
105110
106111
Start-Sleep -Seconds 5
112+
113+
if (Test-Path -Path "./.publish") {
114+
$context | Upload-Release-Assets `
115+
-Tag "v$($env:GitVersion_SemVer)" `
116+
-Path "./.publish"
117+
}
107118
}
108119
} else {
109120
Write-Host "No release published on GitHub when patch is not set to zero."

github.ps1

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ function Publish-Release {
218218
[string] $tag,
219219
[string] $name,
220220
[switch] $releaseNotes,
221-
[string] $discussionCategory
221+
[string] $discussionCategory,
222+
[string] $discussionText
222223
)
223224
$body = [PSCustomObject]@{
224225
tag_name=$tag
@@ -228,6 +229,11 @@ function Publish-Release {
228229
if ($discussionCategory) {
229230
$body | Add-Member -MemberType NoteProperty -Name 'discussion_category_name' -Value $discussionCategory
230231
}
232+
233+
if ($discussionText) {
234+
$body | Add-Member -MemberType NoteProperty -Name 'body' -Value $discussionText
235+
}
236+
231237
$response = Send-GitHub-Post-Request `
232238
-Owner $context.Owner `
233239
-Repository $context.Repository `
@@ -236,6 +242,24 @@ function Publish-Release {
236242
-Body $body
237243
}
238244

245+
function Get-Body-PR {
246+
[CmdletBinding()]
247+
Param(
248+
[Parameter(Mandatory=$true)]
249+
[object] $context
250+
)
251+
252+
$comments = Send-GitHub-Get-Request `
253+
-Owner $context.Owner `
254+
-Repository $context.Repository `
255+
-Segments @("pulls", $context.Id) `
256+
-Headers $($context.SecretToken | Get-GitHub-Headers) `
257+
258+
Write-Host "PR id: $($context.Id)"
259+
$parsed = $comments.Content | ConvertFrom-Json
260+
return $parsed.body
261+
}
262+
239263
function Download-Release-Asset {
240264
[CmdletBinding()]
241265
Param(

oups.txt

Lines changed: 241 additions & 0 deletions
Large diffs are not rendered by default.

package-delta-schemas.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
$schemas = @(
4+
@{ Class = "Packata.Core.TableDialect"; Url = "https://datapackage.org/profiles/2.0/tabledialect.json"; Output = ".\.schemas\tabledialect.json"; Error = "Failed to generate TableDialect schema" },
5+
@{ Class = "Packata.Core.Schema"; Url = "https://datapackage.org/profiles/2.0/tableschema.json"; Output = ".\.schemas\tableschema.json"; Error = "Failed to generate Table schema" },
6+
@{ Class = "Packata.Core.Resource"; Url = "https://datapackage.org/profiles/2.0/dataresource.json"; Output = ".\.schemas\dataresource.json"; Error = "Failed to generate Resource schema" },
7+
@{ Class = "Packata.Core.DataPackage"; Url = "https://datapackage.org/profiles/2.0/datapackage.json"; Output = ".\.schemas\datapackage.json"; Error = "Failed to generate DataPackage schema" }
8+
)
9+
10+
$assemblyPath = ".\src\Packata.Core\bin\Release\net8.0\Packata.Core.dll"
11+
12+
$dir = ".\.schemas"
13+
if (Test-Path $dir) {
14+
Remove-Item -Recurse -Force $dir
15+
}
16+
New-Item -Path $dir -ItemType Directory | Out-Null
17+
18+
foreach ($schema in $schemas) {
19+
try {
20+
Write-Host "Generating schema for $($schema.Class)..."
21+
schemathief delta -a $assemblyPath -c $schema.Class -b $schema.Url -x "paths|profile" | Out-File -Encoding UTF8 -FilePath $schema.Output
22+
} catch {
23+
Write-Error $schema.Error
24+
exit 1
25+
}
26+
}
27+
28+
$dir = ".\.publish"
29+
if (Test-Path $dir) {
30+
Remove-Item -Recurse -Force $dir
31+
}
32+
New-Item -Path $dir -ItemType Directory | Out-Null
33+
7z a .\.publish\schemas-$env:GitVersion_SemVer.zip .\.schemas\*.* | Out-Null

src/Packata.Core/Packata.Core.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
<PackageReference Include="YamlDotNet" Version="16.3.0" />
1515
</ItemGroup>
1616

17+
<ItemGroup>
18+
<None Include="..\..\.schemas\**\*">
19+
<Pack>true</Pack>
20+
<PackagePath>contentFiles/any/any/schemas/%(RecursiveDir)%(Filename)%(Extension)</PackagePath>
21+
</None>
22+
</ItemGroup>
23+
1724
</Project>

0 commit comments

Comments
 (0)