Skip to content

Commit

Permalink
Merge pull request #31 from s2quake/ci/improve-ci
Browse files Browse the repository at this point in the history
Add github action on push tag
  • Loading branch information
s2quake authored Jun 30, 2024
2 parents 7714824 + e57d462 commit a7c320a
Show file tree
Hide file tree
Showing 5 changed files with 78 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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ To be released.
* Improve CI to make sure minimal checks are done before merge [[#26]]
* Set actual sha to PackageProjectUrl property [[#27]]
* Change json library to System.Text.Json [[#28]]
* Add github action on push tag [[#31]]

[#26]: https://github.com/s2quake/communication/pull/26
[#27]: https://github.com/s2quake/communication/pull/27
[#28]: https://github.com/s2quake/communication/pull/28
[#31]: https://github.com/s2quake/communication/pull/31


2.0.2
Expand Down

0 comments on commit a7c320a

Please sign in to comment.