Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Jun 30, 2024
1 parent 59f0cd2 commit 0ff84ba
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 32 deletions.
11 changes: 8 additions & 3 deletions .github/scripts/pack-on-pull-request.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/local/bin/pwsh
param (
[Parameter(Mandatory = $true)]
[string]$OutputPath,
[int]$PullRequestNumber,
[string]$KeyPath
[Parameter(Mandatory = $true)]
[int]$PullRequestNumber
)

if (!$Env:PRIVATE_KEY_PATH) {
Write-Error "Environment variable 'PRIVATE_KEY_PATH' is not set."
}

.github/scripts/pack.ps1 `
-OutputPath $OutputPath `
-PullRequestNumber $PullRequestNumber `
-KeyPath $KeyPath
-KeyPath $Env:PRIVATE_KEY_PATH
41 changes: 31 additions & 10 deletions .github/scripts/pack-on-push-main.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
#!/usr/local/bin/pwsh
param (
[Parameter(Mandatory = $true)]
[string]$OutputPath,
[string]$KeyPath,
[string]$NugetApiKey
[Parameter(Mandatory = $true)]
[ValidateScript({ $_ })]
[string]$CommitSHA
)

$commitMessage = "$(git log -1 --pretty=%B)"
if (!$Env:PRIVATE_KEY_PATH) {
Write-Error "Environment variable 'PRIVATE_KEY_PATH' is not set."
}

if (!$Env:NUGET_API_KEY) {
Write-Error "Environment variable 'NUGET_API_KEY' is not set."
}

$commitMessage = "$(git log $CommitSHA -1 --pretty=%B)"
$pattern = "(?<=Merge pull request #)(\d+)"
if (!($commitMessage -match $pattern)) {
Write-Error "Commit message does not contain a pull request number."
}
$pullRequestNumber = $matches[1]

Remove-Item -Force -Recurse pack -ErrorAction SilentlyContinue
Remove-Item -Path $OutputPath -Force -Recurse -ErrorAction SilentlyContinue

$commitSHA = "$(git log -1 --pretty=%H)"
.github/scripts/pack.ps1 `
-OutputPath $OutputPath `
-PullRequestNumber $matches[1] `
-KeyPath $KeyPath `
-CommitSHA $commitSHA
-PullRequestNumber $pullRequestNumber `
-KeyPath $Env:PRIVATE_KEY_PATH `
-CommitSHA $CommitSHA

$labelsValue = gh pr view $pullRequestNumber --json labels | ConvertFrom-Json -AsHashtable
$labels = $labelsValue | Select-Object -ExpandProperty labels | ForEach-Object {
$_.name
}
$skipNugetUpload = $labels -contains "skip nuget upload"
if ($skipNugetUpload) {
Write-Host "Skipping NuGet upload"
}

Get-ChildItem -Path $OutputPath -Filter "*.nupkg" | ForEach-Object {
$nupkgs = Get-ChildItem -Path $OutputPath -Filter "*.nupkg" | ForEach-Object { $_.FullName }
$nupkgs = $skipNugetUpload ? @() : $nupkgs
$nupkgs | ForEach-Object {
dotnet nuget push `
$_ `
--skip-duplicate `
--api-key $NugetApiKey `
--api-key $Env:NUGET_API_KEY `
--source https://api.nuget.org/v3/index.json
}
16 changes: 11 additions & 5 deletions .github/scripts/pack-on-push-tag.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/usr/local/bin/pwsh
param (
[string]$OutputPath,
[string]$KeyPath,
[string]$NugetApiKey,
[string]$tagName
)

Remove-Item -Force -Recurse pack -ErrorAction SilentlyContinue
if (!$Env:PRIVATE_KEY_PATH) {
Write-Error "Environment variable 'PRIVATE_KEY_PATH' is not set."
}

if (!$Env:NUGET_API_KEY) {
Write-Error "Environment variable 'NUGET_API_KEY' is not set."
}

Remove-Item -Path $OutputPath -Force -Recurse -ErrorAction SilentlyContinue

.github/scripts/pack.ps1 `
-OutputPath $OutputPath `
-KeyPath $KeyPath `
-KeyPath $Env:PRIVATE_KEY_PATH `
-CommitSHA $tagName

$files = Get-ChildItem -Path pack -Filter "*.nupkg" | ForEach-Object {
dotnet nuget push `
$_ `
--api-key $NugetApiKey `
--api-key $Env:NUGET_API_KEY `
--source https://api.nuget.org/v3/index.json
$_.FullName
}
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,33 @@ on:
jobs:
pack:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 8.0.100
- run: echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk
- run: |
echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk
echo "PRIVATE_KEY_PATH=$(Join-Path $PWD private.snk)" | `
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- if: ${{ github.event_name == 'pull_request' }}
run: |
$Env:PRIVATE_KEY_PATH
.github/scripts/pack-on-pull-request.ps1 `
-OutputPath "pack" `
-PullRequestNumber ${{ github.event.pull_request.number }} `
-KeyPath "$pwd/private.snk"
shell: pwsh
-PullRequestNumber ${{ github.event.pull_request.number }}
- if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |
.github/scripts/pack-on-push-main.ps1 `
-OutputPath "pack" `
-KeyPath "$pwd/private.snk" `
-NugetApiKey ${{ secrets.NUGET_API_KEY }}
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
- if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
run: |
$tagName = "${{ github.ref }}" -replace "refs/tags/", ""
Expand All @@ -40,3 +47,5 @@ jobs:
-NugetApiKey ${{ secrets.NUGET_API_KEY }}
-TagName $tagName
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
10 changes: 0 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@
"cwd": "${workspaceFolder}/src/JSSoft.Communication.Server/bin/Debug/net8.0",
"console": "integratedTerminal",
"stopAtEntry": false
},
{
"name": "pwsh-build",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceFolder}/build.ps1",
"args": [
"-Pack"
],
"cwd": "${cwd}"
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
100
]
},
"[powershell]": {
"editor.rulers": [
100
]
},
"files.exclude": {
".vs": true,
"**/bin": true,
Expand Down

0 comments on commit 0ff84ba

Please sign in to comment.