From 3c442703fb1a60ebf2e6a373c70dc03f94fa22ec Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 13:12:24 +0200 Subject: [PATCH 1/9] add updatecli for plugins --- .gitattributes | 1 + .../{updatecli.yaml => action-updatecli.yaml} | 7 +- .gitignore | 2 +- updatecli/updatecli.d/update-plugins.ps1 | 33 +++++ updatecli/updatecli.d/update-plugins.sh | 7 + updatecli/updatecli.d/update-plugins.yaml | 128 ++++++++++++++++++ updatecli/updatecli.d/weekly.yaml | 32 ++--- 7 files changed, 192 insertions(+), 18 deletions(-) create mode 100644 .gitattributes rename .github/workflows/{updatecli.yaml => action-updatecli.yaml} (71%) create mode 100644 updatecli/updatecli.d/update-plugins.ps1 create mode 100644 updatecli/updatecli.d/update-plugins.sh create mode 100644 updatecli/updatecli.d/update-plugins.yaml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..fcadb2cf9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.github/workflows/updatecli.yaml b/.github/workflows/action-updatecli.yaml similarity index 71% rename from .github/workflows/updatecli.yaml rename to .github/workflows/action-updatecli.yaml index d3eadd7e7..dab807f4c 100644 --- a/.github/workflows/updatecli.yaml +++ b/.github/workflows/action-updatecli.yaml @@ -18,11 +18,16 @@ jobs: - name: Install updatecli # Until https://github.com/updatecli/updatecli/pull/336 run: | - curl -sSL https://github.com/updatecli/updatecli/releases/download/v0.16.1/updatecli_Linux_x86_64.tar.gz -o updatecli.tgz + curl -sSL https://github.com/updatecli/updatecli/releases/download/v0.23.2/updatecli_Linux_x86_64.tar.gz -o updatecli.tgz tar xzf updatecli.tgz -C /usr/local/bin updatecli version rm -f updatecli.tgz + - name: Install Jenkins Plugin Installation Manager Tool + run: | + curl -sSL https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.3/jenkins-plugin-manager-2.12.3.jar -o "$GITHUB_WORKSPACE/plugin-manager.jar" + echo "PLUGIN_MANAGER_JAR_PATH=$GITHUB_WORKSPACE/plugin-manager.jar" >> $GITHUB_ENV + - name: Diff continue-on-error: true run: | diff --git a/.gitignore b/.gitignore index 737afc70d..337fa3e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ pct-report.* logs/ megawar.war pct.jar - +plugin-manager.jar diff --git a/updatecli/updatecli.d/update-plugins.ps1 b/updatecli/updatecli.d/update-plugins.ps1 new file mode 100644 index 000000000..4c89a9a78 --- /dev/null +++ b/updatecli/updatecli.d/update-plugins.ps1 @@ -0,0 +1,33 @@ +param( + [string] $JenkinsVersion, + [string] $PluginManagerJar = './plugin-manager.jar' +) + +$JenkinsVersionX = $JenkinsVersion -replace '\d+$', 'x' + +$pomPath = "bom-${JenkinsVersionX}/pom.xml" +$pom = New-Object System.Xml.XmlDocument +$pom.PreserveWhitespace = $true +$pom.Load($pomPath) + +# Select Dependencies and Skip BOM +$dependencies = $pom.Project.DependencyManagement.Dependencies.Dependency | Select-Object -Skip 1 + +foreach ($dependency in $dependencies) { + $artifact = $dependency.artifactId + $oldVersion = $dependency.version + $plugin = "${artifact}:${oldVersion}" + [string] $output = & java -jar "$PluginManagerJar" --no-download --available-updates --jenkins-version "$JenkinsVersion" --plugins $plugin + if ($output -inotlike '*No available updates*') { + # Exaple output: + # Available updates: + # credentials (2.6.1) has an available update: 2.6.1.1 + + # Grab the version number at the end of the line + $version = $output.Trim().Split(' ')[-1] + Write-Output "Changed $artifact from $oldVersion to $version" + $dependency.version = $version + } +} + +$pom.Save($pomPath) diff --git a/updatecli/updatecli.d/update-plugins.sh b/updatecli/updatecli.d/update-plugins.sh new file mode 100644 index 000000000..856c3c4dd --- /dev/null +++ b/updatecli/updatecli.d/update-plugins.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -eux -o pipefail + +jenkinsVersion="$1" +jar="${PLUGIN_MANAGER_JAR_PATH:-"./plugin-manager.jar"}" +pwsh -NoProfile -File "./updatecli/updatecli.d/update-plugins.ps1" -JenkinsVersion "${jenkinsVersion}" -PluginManagerJar "${jar}" diff --git a/updatecli/updatecli.d/update-plugins.yaml b/updatecli/updatecli.d/update-plugins.yaml new file mode 100644 index 000000000..12c952429 --- /dev/null +++ b/updatecli/updatecli.d/update-plugins.yaml @@ -0,0 +1,128 @@ +--- +scms: + github: + kind: github + spec: + user: "{{ .github.user }}" + email: "{{ .github.email }}" + owner: "{{ .github.owner }}" + repository: "{{ .github.repository }}" + token: "{{ requiredEnv .github.token }}" + username: "{{ .github.username }}" + branch: "{{ .github.branch }}" + +sources: + jenkins2.289.x: + name: Get Last Jenkins Stable Version + kind: githubrelease + spec: + owner: "jenkinsci" + repository: "jenkins" + token: "{{ requiredEnv .github.token }}" + versionfilter: + kind: regex + pattern: 'jenkins-2.289.\d+$' + transformers: + - trimPrefix: "jenkins-" + jenkins2.303.x: + name: Get Last Jenkins Stable Version + kind: githubrelease + spec: + owner: "jenkinsci" + repository: "jenkins" + token: "{{ requiredEnv .github.token }}" + versionfilter: + kind: regex + pattern: 'jenkins-2.303.\d+$' + transformers: + - trimPrefix: "jenkins-" + jenkins2.319.x: + name: Get Last Jenkins Stable Version + kind: githubrelease + spec: + owner: "jenkinsci" + repository: "jenkins" + token: "{{ requiredEnv .github.token }}" + versionfilter: + kind: regex + pattern: 'jenkins-2.319.\d+$' + transformers: + - trimPrefix: "jenkins-" + jenkins2.332.x: + name: Get Last Jenkins Stable Version + kind: githubrelease + spec: + owner: "jenkinsci" + repository: "jenkins" + token: "{{ requiredEnv .github.token }}" + versionfilter: + kind: regex + pattern: 'jenkins-2.332.\d+$' + transformers: + - trimPrefix: "jenkins-" +conditions: + jenkins2.289.x: + name: Test if Jenkins stable published + kind: maven + sourceid: jenkins2.289.x + spec: + url: "repo.jenkins-ci.org" + repository: "releases" + groupid: "org.jenkins-ci.main" + artifactid: "jenkins-war" + jenkins2.303.x: + name: Test if Jenkins stable published + kind: maven + sourceid: jenkins2.303.x + spec: + url: "repo.jenkins-ci.org" + repository: "releases" + groupid: "org.jenkins-ci.main" + artifactid: "jenkins-war" + jenkins2.319.x: + name: Test if Jenkins stable published + kind: maven + sourceid: jenkins2.319.x + spec: + url: "repo.jenkins-ci.org" + repository: "releases" + groupid: "org.jenkins-ci.main" + artifactid: "jenkins-war" + jenkins2.332.x: + name: Test if Jenkins stable published + kind: maven + sourceid: jenkins2.332.x + spec: + url: "repo.jenkins-ci.org" + repository: "releases" + groupid: "org.jenkins-ci.main" + artifactid: "jenkins-war" +targets: + jenkins2.289.x: + name: 'Update 2.289.x plugins' + sourceid: jenkins2.289.x + kind: shell + spec: + command: bash ./updatecli/updatecli.d/update-plugins.sh + scmid: github + jenkins2.303.x: + name: 'Update 2.303.x plugins' + sourceid: jenkins2.303.x + kind: shell + spec: + command: bash ./updatecli/updatecli.d/update-plugins.sh + scmid: github + jenkins2.319.x: + name: 'Update 2.319.x plugins' + sourceid: jenkins2.319.x + kind: shell + spec: + command: bash ./updatecli/updatecli.d/update-plugins.sh + scmid: github + jenkins2.332.x: + name: 'Update 2.332.x plugins' + sourceid: jenkins2.332.x + kind: shell + spec: + command: bash ./updatecli/updatecli.d/update-plugins.sh + scmid: github diff --git a/updatecli/updatecli.d/weekly.yaml b/updatecli/updatecli.d/weekly.yaml index d61fc8051..e2a31c53b 100644 --- a/updatecli/updatecli.d/weekly.yaml +++ b/updatecli/updatecli.d/weekly.yaml @@ -1,4 +1,16 @@ --- +scms: + github: + kind: github + spec: + user: "{{ .github.user }}" + email: "{{ .github.email }}" + owner: "{{ .github.owner }}" + repository: "{{ .github.repository }}" + token: "{{ requiredEnv .github.token }}" + username: "{{ .github.username }}" + branch: "{{ .github.branch }}" + sources: jenkinsWeekly: name: Get Last Jenkins Weekly Version @@ -13,27 +25,15 @@ conditions: name: Test if Jenkins weekly published kind: maven spec: - owner: "maven" url: "repo.jenkins-ci.org" repository: "releases" - groupID: "org.jenkins-ci.main" - artifactID: "jenkins-war" + groupid: "org.jenkins-ci.main" + artifactid: "jenkins-war" targets: default: name: 'Update weekly version' - sourceID: jenkinsWeekly + sourceid: jenkinsWeekly kind: shell spec: command: bash ./updatecli/updatecli.d/weekly-apply.sh - scm: - github: - user: "{{ .github.user }}" - email: "{{ .github.email }}" - owner: "{{ .github.owner }}" - repository: "{{ .github.repository }}" - token: "{{ requiredEnv .github.token }}" - username: "{{ .github.username }}" - branch: "{{ .github.branch }}" - pullRequest: - labels: - - dependencies + scmid: github From 5a914a762ca7dc0f7cef9640cc32ab58e867b625 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 14:07:44 +0200 Subject: [PATCH 2/9] use regex to select version --- .github/workflows/action-updatecli.yaml | 2 +- updatecli/updatecli.d/update-plugins.ps1 | 6 +++--- updatecli/updatecli.d/update-plugins.sh | 0 3 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 updatecli/updatecli.d/update-plugins.sh diff --git a/.github/workflows/action-updatecli.yaml b/.github/workflows/action-updatecli.yaml index dab807f4c..a8f84211c 100644 --- a/.github/workflows/action-updatecli.yaml +++ b/.github/workflows/action-updatecli.yaml @@ -25,7 +25,7 @@ jobs: - name: Install Jenkins Plugin Installation Manager Tool run: | - curl -sSL https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.3/jenkins-plugin-manager-2.12.3.jar -o "$GITHUB_WORKSPACE/plugin-manager.jar" + curl -sSL https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.3/jenkins-plugin-manager-2.12.3.jar -o "${GITHUB_WORKSPACE:-.}/plugin-manager.jar" echo "PLUGIN_MANAGER_JAR_PATH=$GITHUB_WORKSPACE/plugin-manager.jar" >> $GITHUB_ENV - name: Diff diff --git a/updatecli/updatecli.d/update-plugins.ps1 b/updatecli/updatecli.d/update-plugins.ps1 index 4c89a9a78..f278c1ad4 100644 --- a/updatecli/updatecli.d/update-plugins.ps1 +++ b/updatecli/updatecli.d/update-plugins.ps1 @@ -24,9 +24,9 @@ foreach ($dependency in $dependencies) { # credentials (2.6.1) has an available update: 2.6.1.1 # Grab the version number at the end of the line - $version = $output.Trim().Split(' ')[-1] - Write-Output "Changed $artifact from $oldVersion to $version" - $dependency.version = $version + $newVersion = ($output | Select-String -Pattern 'update: (.+)').matches.Groups[1].Value + Write-Output "Changed $artifact from $oldVersion to $newVersion" + $dependency.version = $newVersion } } diff --git a/updatecli/updatecli.d/update-plugins.sh b/updatecli/updatecli.d/update-plugins.sh old mode 100644 new mode 100755 From bff99fa3336f7f0333632cd6fa90831ea039b0ed Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 14:16:02 +0200 Subject: [PATCH 3/9] download plugin manager to updatecli workspace --- updatecli/updatecli.d/update-plugins.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/updatecli/updatecli.d/update-plugins.sh b/updatecli/updatecli.d/update-plugins.sh index 856c3c4dd..b8005837b 100755 --- a/updatecli/updatecli.d/update-plugins.sh +++ b/updatecli/updatecli.d/update-plugins.sh @@ -4,4 +4,10 @@ set -eux -o pipefail jenkinsVersion="$1" jar="${PLUGIN_MANAGER_JAR_PATH:-"./plugin-manager.jar"}" + +# check if jar does not exist +if [ ! -f "$jar" ]; then + curl -sSL https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/2.12.3/jenkins-plugin-manager-2.12.3.jar -o "$jar" +fi + pwsh -NoProfile -File "./updatecli/updatecli.d/update-plugins.ps1" -JenkinsVersion "${jenkinsVersion}" -PluginManagerJar "${jar}" From 0efab81519985f9e42db54aa24fdc3d56d0d4a2c Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 14:17:03 +0200 Subject: [PATCH 4/9] print output --- updatecli/updatecli.d/update-plugins.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/updatecli/updatecli.d/update-plugins.ps1 b/updatecli/updatecli.d/update-plugins.ps1 index f278c1ad4..08023487c 100644 --- a/updatecli/updatecli.d/update-plugins.ps1 +++ b/updatecli/updatecli.d/update-plugins.ps1 @@ -18,6 +18,7 @@ foreach ($dependency in $dependencies) { $oldVersion = $dependency.version $plugin = "${artifact}:${oldVersion}" [string] $output = & java -jar "$PluginManagerJar" --no-download --available-updates --jenkins-version "$JenkinsVersion" --plugins $plugin + $output if ($output -inotlike '*No available updates*') { # Exaple output: # Available updates: From 16f2beaf067a078512add8011a32b563f3d53798 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 14:32:23 +0200 Subject: [PATCH 5/9] make sure output is not null --- updatecli/updatecli.d/update-plugins.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/updatecli/updatecli.d/update-plugins.ps1 b/updatecli/updatecli.d/update-plugins.ps1 index 08023487c..33893a636 100644 --- a/updatecli/updatecli.d/update-plugins.ps1 +++ b/updatecli/updatecli.d/update-plugins.ps1 @@ -18,8 +18,7 @@ foreach ($dependency in $dependencies) { $oldVersion = $dependency.version $plugin = "${artifact}:${oldVersion}" [string] $output = & java -jar "$PluginManagerJar" --no-download --available-updates --jenkins-version "$JenkinsVersion" --plugins $plugin - $output - if ($output -inotlike '*No available updates*') { + if ($null -ne $output -and $output -inotlike '*No available updates*') { # Exaple output: # Available updates: # credentials (2.6.1) has an available update: 2.6.1.1 From 5dc9f0ce142f8b1b608356dec9e4f3f6a926e1cf Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 14:38:17 +0200 Subject: [PATCH 6/9] check java --- updatecli/updatecli.d/update-plugins.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/updatecli/updatecli.d/update-plugins.ps1 b/updatecli/updatecli.d/update-plugins.ps1 index 33893a636..6b3cf087d 100644 --- a/updatecli/updatecli.d/update-plugins.ps1 +++ b/updatecli/updatecli.d/update-plugins.ps1 @@ -5,6 +5,14 @@ param( $JenkinsVersionX = $JenkinsVersion -replace '\d+$', 'x' +if (Get-Command 'java' -ErrorAction SilentlyContinue) { + $java = 'java' +} elseif ($IsLinux) { + $java = '/usr/bin/java' +} else { + $java = 'java' +} + $pomPath = "bom-${JenkinsVersionX}/pom.xml" $pom = New-Object System.Xml.XmlDocument $pom.PreserveWhitespace = $true @@ -17,7 +25,7 @@ foreach ($dependency in $dependencies) { $artifact = $dependency.artifactId $oldVersion = $dependency.version $plugin = "${artifact}:${oldVersion}" - [string] $output = & java -jar "$PluginManagerJar" --no-download --available-updates --jenkins-version "$JenkinsVersion" --plugins $plugin + [string] $output = & $java -jar "$PluginManagerJar" --no-download --available-updates --jenkins-version "$JenkinsVersion" --plugins $plugin if ($null -ne $output -and $output -inotlike '*No available updates*') { # Exaple output: # Available updates: From 57261400795aea8cbeea7b3b9076998251a3fb19 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 14:50:46 +0200 Subject: [PATCH 7/9] test from this branch --- updatecli/values.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/updatecli/values.yaml b/updatecli/values.yaml index ac89ff522..e2cbdb5cd 100644 --- a/updatecli/values.yaml +++ b/updatecli/values.yaml @@ -3,6 +3,6 @@ github: email: "41898282+github-actions[bot]@users.noreply.github.com" username: "github-actions" token: "UPDATECLI_GITHUB_TOKEN" - owner: "jenkinsci" - repository: "bom" - branch: "master" \ No newline at end of file + owner: "jetersen" + repository: "jenkins-bom" + branch: "fix/bomPlugins" # TODO revert before merge From c201430ff0189bc6d4a4841814f651c8c0a749d3 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 19:22:58 +0200 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com> --- updatecli/updatecli.d/update-plugins.ps1 | 2 +- updatecli/values.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/updatecli/updatecli.d/update-plugins.ps1 b/updatecli/updatecli.d/update-plugins.ps1 index 6b3cf087d..acda77fc7 100644 --- a/updatecli/updatecli.d/update-plugins.ps1 +++ b/updatecli/updatecli.d/update-plugins.ps1 @@ -27,7 +27,7 @@ foreach ($dependency in $dependencies) { $plugin = "${artifact}:${oldVersion}" [string] $output = & $java -jar "$PluginManagerJar" --no-download --available-updates --jenkins-version "$JenkinsVersion" --plugins $plugin if ($null -ne $output -and $output -inotlike '*No available updates*') { - # Exaple output: + # Example output: # Available updates: # credentials (2.6.1) has an available update: 2.6.1.1 diff --git a/updatecli/values.yaml b/updatecli/values.yaml index e2cbdb5cd..971c817e8 100644 --- a/updatecli/values.yaml +++ b/updatecli/values.yaml @@ -3,6 +3,6 @@ github: email: "41898282+github-actions[bot]@users.noreply.github.com" username: "github-actions" token: "UPDATECLI_GITHUB_TOKEN" - owner: "jetersen" - repository: "jenkins-bom" - branch: "fix/bomPlugins" # TODO revert before merge + owner: "jenkinsci" + repository: "bom" + branch: "master" From 07936590607f8813bfb2cc622c94f9452ba2aa96 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sat, 23 Apr 2022 19:30:44 +0200 Subject: [PATCH 9/9] restore pull requests --- updatecli/updatecli.d/update-plugins.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/updatecli/updatecli.d/update-plugins.yaml b/updatecli/updatecli.d/update-plugins.yaml index 12c952429..c8f3794d6 100644 --- a/updatecli/updatecli.d/update-plugins.yaml +++ b/updatecli/updatecli.d/update-plugins.yaml @@ -126,3 +126,18 @@ targets: spec: command: bash ./updatecli/updatecli.d/update-plugins.sh scmid: github +pullrequests: + default: + title: 'Bump pinned plugins' + kind: github + scmid: github + targets: + - jenkins2.289.x + - jenkins2.303.x + - jenkins2.319.x + - jenkins2.332.x + spec: + labels: + - dependencies + automerge: true + mergemethod: squash