Skip to content

Commit

Permalink
ci: Add action on push tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Jun 30, 2024
1 parent 7714824 commit 7d622af
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 21 deletions.
11 changes: 11 additions & 0 deletions .github/scripts/pack-on-pull-request.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/local/bin/pwsh
param (
[string]$OutputPath,
[int]$PullRequestNumber,
[string]$KeyPath
)

.github/scripts/pack.ps1 `
-OutputPath $OutputPath `
-PullRequestNumber $PullRequestNumber `
-KeyPath $KeyPath
29 changes: 29 additions & 0 deletions .github/scripts/pack-on-push-main.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/local/bin/pwsh
param (
[string]$OutputPath,
[string]$KeyPath,
[string]$NugetApiKey
)

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

Remove-Item -Force -Recurse pack -ErrorAction SilentlyContinue

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

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

Remove-Item -Force -Recurse pack -ErrorAction SilentlyContinue

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

$files = Get-ChildItem -Path pack -Filter "*.nupkg" | ForEach-Object {
# dotnet nuget push `
# $_ `
# --api-key $NugetApiKey `
# --source https://api.nuget.org/v3/index.json
$_.FullName
}

gh release create --generate-notes --latest --title "Release $tagName" $tagName $files
33 changes: 12 additions & 21 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,24 @@ jobs:
- run: echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk
- if: ${{ github.event_name == 'pull_request' }}
run: |
.github/scripts/pack.ps1 `
.github/scripts/pack-on-pull-request.ps1 `
-OutputPath "pack" `
-PullRequestNumber ${{ github.event.pull_request.number }} `
-KeyPath "$pwd/private.snk"
shell: pwsh
- if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |
$commitMessage = "$(git log -1 --pretty=%B)"
$pattern = "(?<=Merge pull request #)(\d+)"
if (!($commitMessage -match $pattern)) {
Write-Error "Commit message does not contain a pull request number."
}

Remove-Item -Force -Recurse pack -ErrorAction SilentlyContinue

$commitSHA = "$(git log -1 --pretty=%H)"
.github/scripts/pack.ps1 `
.github/scripts/pack-on-push-main.ps1 `
-OutputPath "pack" `
-KeyPath "$pwd/private.snk" `
-NugetApiKey ${{ secrets.NUGET_API_KEY }}
shell: pwsh
- if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
run: |
$tagName = "${{ github.ref }}" -replace "refs/tags/", ""
.github/scripts/pack-on-push-tag.ps1 `
-OutputPath "pack" `
-PullRequestNumber $matches[1] `
-KeyPath "$pwd/private.snk" `
-CommitSHA $commitSHA

Get-ChildItem -Path pack -Filter "*.nupkg" | ForEach-Object {
dotnet nuget push `
$_ `
--skip-duplicate `
--api-key ${{ secrets.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json
}
-NugetApiKey ${{ secrets.NUGET_API_KEY }}
-TagName $tagName
shell: pwsh

0 comments on commit 7d622af

Please sign in to comment.