This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (130 loc) · 5.04 KB
/
package-updates.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: update-packages
#UTC Time, Central is 6 hours behind UTC, 24 hour time format.
on:
schedule:
- cron: "0 10,22 * * *"
workflow_dispatch:
inputs:
logLevel:
description: "Log level"
required: true
default: "warning"
type: choice
options:
- info
- warning
- debug
jobs:
update-packages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Package Updates
run: |
dotnet nuget add source `
--username "AutoUpdates" `
--password "${{ secrets.AZDO_NUGET_REPO }}" `
--store-password-in-clear-text `
--name IS-Nuget "https://pkgs.dev.azure.com/JackHenry/_packaging/IS-Nuget/nuget/v3/index.json"
git config --global user.email "[email protected]"
git config --global user.name "AutoUpdates"
# only update the nuget packages that start with 'Jha.'
Set-Variable -Name "PACKAGEIDSTARTSWITH" -Value "Jha." -Option Constant
# jira ticket
Set-Variable -Name "DEFAULTJIRATICKET" -Value "BSL-2921" -Option Constant
$JiraTicket = "${{ vars.PACKAGE_UPDATE_JIRA_TICKET }}"
if (-NOT $JiraTicket) {
$JiraTicket = $DefaultJiraTicket
}
# the name of the feature branch that is created.
Set-Variable -Name "FEATUREBRANCH" -Value "update-bot/package-updates" -Option Constant
$branchExists = git ls-remote --heads origin $featureBranch
Write-Host "Branch Exists: " $branchExists
# creates new branch.
function Add-NewBranch {
if ($branchExists) {
git checkout $featureBranch
}
else {
git checkout -b $featureBranch
}
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create a new branch."
exit 1
}
}
# pushes the new branch.
function Push-NewBranch {
git add -A
git commit -m "Updating Jha.* Packages."
if ($branchExists) {
git push origin HEAD:$featureBranch
}
else {
git push -u origin $featureBranch
}
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to push new branch."
exit 1
}
}
# creates a pull request.
function Add-PullRequest {
$prState = gh pr view --json state | ConvertFrom-Json
Write-Host "PR State " $prState.state
if ($null -eq $prState -or $prState.state -eq "CLOSED" -or $prState.state -eq "MERGED" ) {
$body = "Description: Updating Jha.* Packages. `r`nJira-Tickets: $JiraTicket`r`n"
gh pr create --title "Jha.* Packages Updates (Bump)" --body $body
}
Write-Host "PR State " $prState.state
Write-Host "PR Data " $prState
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create a pull request."
exit 1
}
}
# update with dotnet commands.
function Update-WithDotNet {
[CmdletBinding()]
param(
[Parameter(mandatory = $true)]
[string] $projectFileName,
[Parameter(mandatory = $true)]
[string] $packageName
)
dotnet add $projectFileName package $packageName
}
Write-Host "Updating project " $ProjectsToInclude.projects
# create new feature branch
Add-NewBranch
# get the cs proj files
$csProjFiles = Get-ChildItem -Path ${GITHUB_WORKSPACE} -Force -Recurse -Include "*.csproj"
Write-Host "CSProj Files: $csProjFiles"
# loop through the cs proj files
foreach ($childItem in $csProjFiles) {
[xml]$xmlElm = Get-Content -Path $childItem
$xmlElm.Project.ItemGroup.PackageReference | Where-Object {
$_.include -ne $null -and $_.include.StartsWith($PackageIdStartsWith)
} | ForEach-Object {
Write-Host "Updating reference " $_.include
Update-WithDotNet -projectFileName $childItem -packageName $_.include
}
}
if (-not (git status --porcelain)) {
Write-Host "Clean!"
Write-Host "All files up-to-date for" ${GITHUB_WORKSPACE}
}
else {
Write-Host "Not Clean!"
# commit branch
Write-Host "Commiting branch."
Push-NewBranch
# create PR
Write-Host "Creating pull request for branch $featureBranch."
Add-PullRequest
}
shell: pwsh
env:
GH_TOKEN: ${{ secrets.AUTOBOT_GITHUB_TOKEN }}