-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+changelog-ignore: auto pr for jcdcdev.Eco.Core updates
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: '🔄 Update jcdcdev.Eco.Core NuGet Package' | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0,12 * * *' | ||
jobs: | ||
sync-eco-package: | ||
runs-on: ubuntu-latest | ||
name: '🔧 Sync jcdcdev.Eco.Core NuGet Package' | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
env: | ||
packageId: 'jcdcdev.Eco.Core' | ||
steps: | ||
- name: 📋 Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: 🚀 Execute script | ||
id: sync-eco-package | ||
shell: pwsh | ||
run: | | ||
Push-Location -Path ./src | ||
$result = ./update-nuget-package.ps1 -projectFilePath "./jcdcdev.Eco.Signs/jcdcdev.Eco.Signs.csproj" -packageId $env:packageId | ||
Write-Output "updated=$($result.Updated)" >> $env:GITHUB_OUTPUT | ||
Write-Output "target-version=$($result.TargetVersion)" >> $env:GITHUB_OUTPUT | ||
Write-Output "source-version=$($result.SourceVersion)" >> $env:GITHUB_OUTPUT | ||
Pop-Location | ||
- name: 🤖 Make Pull Request | ||
if: steps.sync-eco-package.outputs.updated == 'true' | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: "feature: Support ${{ env.packageId }} ${{ steps.sync-eco-package.outputs.target-version }}" | ||
title: "Update ${{ env.packageId }} to ${{ steps.sync-eco-package.outputs.target-version }}" | ||
body: "This PR updates the ${{ env.packageId }} NuGet package from ${{ steps.sync-eco-package.outputs.source-version }} to ${{ steps.sync-eco-package.outputs.target-version }}." | ||
branch: "update-${{ env.packageId }}-from-${{ steps.sync-eco-package.outputs.source-version }}-to-${{ steps.sync-eco-package.outputs.target-version }}" | ||
labels: "automated" | ||
reviewers: "jcdcdev" | ||
assignees: "jcdcdev" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$projectFilePath, | ||
[Parameter(Mandatory = $true)] | ||
[string]$packageId, | ||
[Parameter(Mandatory = $false)] | ||
[switch]$checkOnly | ||
) | ||
|
||
$pattern = [regex]"((PackageReference)+.(Include=""$packageId"").+(Version=""(.+)\""))" | ||
|
||
$content = Get-Content -Path $projectFilePath -Raw | ||
$results = $pattern.Matches($content) | ||
|
||
if ($results.Count -eq 0) { | ||
Write-Warning "⚠️ No $packageId package reference found in the project file." | ||
exit 0; | ||
} | ||
|
||
if ($results.Count -gt 1) { | ||
Write-Warning "⚠️ Multiple $packageId package references found in the project file." | ||
exit 1; | ||
} | ||
|
||
$match = $results[0] | ||
|
||
$version = $match.Groups[5].Value | ||
Write-Host "🔃 Current Version`n`n$version`n" | ||
|
||
try { | ||
$latestVersionResponse = Invoke-RestMethod "https://api.nuget.org/v3-flatcontainer/$($packageId.ToLowerInvariant())/index.json" | ||
} | ||
catch { | ||
Write-Warning "⚠️ Failed to retrieve the latest version of $packageId." | ||
exit 1; | ||
} | ||
|
||
$index = $latestVersionResponse.versions.IndexOf($version) | ||
if ($index -eq -1) { | ||
Write-Warning "⚠️ $version is not found in the list of versions on NuGet." | ||
exit 1; | ||
} | ||
|
||
if ($index -eq $latestVersionResponse.versions.Count - 1) { | ||
Write-Host "✅ $packageId is up-to-date." | ||
exit 0; | ||
} | ||
|
||
$updatedVersion = $latestVersionResponse.versions[$index + 1] | ||
|
||
Write-Host "⬆️ Next Version`n`n$updatedVersion`n" | ||
|
||
if (-not $checkOnly) { | ||
$newContent = $match.Value -replace "(Version=`"(.*?)`")", "Version=""$updatedVersion"" " | ||
Write-Verbose "New csproj line: $newContent" | ||
$updatedContent = $content.Replace($match.Value, $newContent) | ||
$updatedContent | Set-Content -Path $projectFilePath -NoNewline -Encoding Default | ||
} | ||
|
||
return @{ | ||
SourceVersion = $version | ||
TargetVersion = $updatedVersion | ||
Updated = $version -ne $updatedVersion | ||
} | ||
|
||
|