|
| 1 | +schedules: |
| 2 | + - cron: "0 8 * * MON" # Weekly on Monday at 8 AM UTC |
| 3 | + displayName: Weekly Java Version Check |
| 4 | + branches: |
| 5 | + include: |
| 6 | + - dev |
| 7 | + always: true |
| 8 | + |
| 9 | +trigger: none # Manual trigger only, no CI builds |
| 10 | + |
| 11 | +pr: none # Not triggered by PRs |
| 12 | + |
| 13 | +resources: |
| 14 | + repositories: |
| 15 | + - repository: 1es |
| 16 | + type: git |
| 17 | + name: 1ESPipelineTemplates/1ESPipelineTemplates |
| 18 | + ref: refs/tags/release |
| 19 | + |
| 20 | +variables: |
| 21 | + - name: System.Debug |
| 22 | + value: false |
| 23 | + |
| 24 | +extends: |
| 25 | + template: v1/1ES.Unofficial.PipelineTemplate.yml@1es |
| 26 | + parameters: |
| 27 | + pool: |
| 28 | + name: 1es-pool-azfunc-public |
| 29 | + image: 1es-ubuntu-22.04 |
| 30 | + os: linux |
| 31 | + |
| 32 | + sdl: |
| 33 | + sourceAnalysisPool: |
| 34 | + name: 1es-pool-azfunc-public |
| 35 | + image: 1es-windows-2022 |
| 36 | + os: windows |
| 37 | + |
| 38 | + stages: |
| 39 | + - stage: ValidateLinux |
| 40 | + displayName: 'Validate Linux JDK Versions' |
| 41 | + jobs: |
| 42 | + - job: ValidateLinuxJDKs |
| 43 | + displayName: 'Detect and Validate Linux JDKs' |
| 44 | + timeoutInMinutes: 60 |
| 45 | + pool: |
| 46 | + name: 1es-pool-azfunc-public |
| 47 | + image: 1es-ubuntu-22.04 |
| 48 | + os: linux |
| 49 | + templateContext: |
| 50 | + outputs: |
| 51 | + - output: pipelineArtifact |
| 52 | + targetPath: '$(System.DefaultWorkingDirectory)/eng/ci/templates/java-versions.yml' |
| 53 | + artifactName: 'java-versions-linux' |
| 54 | + displayName: 'Publish Linux java-versions.yml' |
| 55 | + |
| 56 | + steps: |
| 57 | + - checkout: self |
| 58 | + persistCredentials: true |
| 59 | + clean: true |
| 60 | + |
| 61 | + - task: UsePythonVersion@0 |
| 62 | + displayName: 'Use Python 3.11' |
| 63 | + inputs: |
| 64 | + versionSpec: '3.11' |
| 65 | + addToPath: true |
| 66 | + |
| 67 | + - script: | |
| 68 | + python eng/scripts/check-java-versions.py --os linux |
| 69 | + displayName: 'Check and validate Linux Java versions' |
| 70 | + continueOnError: false |
| 71 | + |
| 72 | + - stage: ValidateWindows |
| 73 | + displayName: 'Validate Windows JDK Versions' |
| 74 | + dependsOn: [] # Run in parallel with Linux |
| 75 | + jobs: |
| 76 | + - job: ValidateWindowsJDKs |
| 77 | + displayName: 'Detect and Validate Windows JDKs' |
| 78 | + timeoutInMinutes: 60 |
| 79 | + pool: |
| 80 | + name: 1es-pool-azfunc-public |
| 81 | + image: 1es-windows-2022 |
| 82 | + os: windows |
| 83 | + templateContext: |
| 84 | + outputs: |
| 85 | + - output: pipelineArtifact |
| 86 | + targetPath: '$(System.DefaultWorkingDirectory)/eng/ci/templates/java-versions.yml' |
| 87 | + artifactName: 'java-versions-windows' |
| 88 | + displayName: 'Publish Windows java-versions.yml' |
| 89 | + |
| 90 | + steps: |
| 91 | + - checkout: self |
| 92 | + persistCredentials: true |
| 93 | + clean: true |
| 94 | + |
| 95 | + - task: UsePythonVersion@0 |
| 96 | + displayName: 'Use Python 3.11' |
| 97 | + inputs: |
| 98 | + versionSpec: '3.11' |
| 99 | + addToPath: true |
| 100 | + |
| 101 | + - script: | |
| 102 | + python eng/scripts/check-java-versions.py --os windows |
| 103 | + displayName: 'Check and validate Windows Java versions' |
| 104 | + continueOnError: false |
| 105 | + |
| 106 | + - stage: CreatePR |
| 107 | + displayName: 'Create Pull Request' |
| 108 | + dependsOn: |
| 109 | + - ValidateLinux |
| 110 | + - ValidateWindows |
| 111 | + condition: succeeded() |
| 112 | + jobs: |
| 113 | + - job: MergeAndCreatePR |
| 114 | + displayName: 'Merge Changes and Create PR' |
| 115 | + timeoutInMinutes: 30 |
| 116 | + pool: |
| 117 | + name: 1es-pool-azfunc-public |
| 118 | + image: 1es-ubuntu-22.04 |
| 119 | + os: linux |
| 120 | + |
| 121 | + steps: |
| 122 | + - checkout: self |
| 123 | + persistCredentials: true |
| 124 | + clean: true |
| 125 | + |
| 126 | + - task: DownloadPipelineArtifact@2 |
| 127 | + displayName: 'Download Linux artifact' |
| 128 | + inputs: |
| 129 | + artifactName: 'java-versions-linux' |
| 130 | + targetPath: '$(Pipeline.Workspace)/java-versions-linux' |
| 131 | + |
| 132 | + - task: DownloadPipelineArtifact@2 |
| 133 | + displayName: 'Download Windows artifact' |
| 134 | + inputs: |
| 135 | + artifactName: 'java-versions-windows' |
| 136 | + targetPath: '$(Pipeline.Workspace)/java-versions-windows' |
| 137 | + |
| 138 | + - script: | |
| 139 | + python eng/scripts/merge-java-versions.py \ |
| 140 | + --linux $(Pipeline.Workspace)/java-versions-linux/java-versions.yml \ |
| 141 | + --windows $(Pipeline.Workspace)/java-versions-windows/java-versions.yml \ |
| 142 | + --output eng/ci/templates/java-versions.yml |
| 143 | + displayName: 'Merge version updates' |
| 144 | + |
| 145 | + - bash: | |
| 146 | + # Configure git |
| 147 | + git config user.email "azfunc-java-worker-bot@microsoft.com" |
| 148 | + git config user.name "Azure Functions Java Worker Bot" |
| 149 | + |
| 150 | + # Check if there are changes |
| 151 | + if git diff --quiet eng/ci/templates/java-versions.yml; then |
| 152 | + echo "No changes detected in java-versions.yml" |
| 153 | + echo "##vso[task.setvariable variable=HasChanges]false" |
| 154 | + else |
| 155 | + echo "Changes detected in java-versions.yml" |
| 156 | + echo "##vso[task.setvariable variable=HasChanges]true" |
| 157 | + |
| 158 | + # Show the diff |
| 159 | + echo "Changes:" |
| 160 | + git diff eng/ci/templates/java-versions.yml |
| 161 | + fi |
| 162 | + displayName: 'Check for changes' |
| 163 | + |
| 164 | + - bash: | |
| 165 | + BRANCH_NAME="automated/update-java-versions-$(date +%Y%m%d-%H%M%S)" |
| 166 | + echo "Creating branch: $BRANCH_NAME" |
| 167 | + git checkout -b $BRANCH_NAME |
| 168 | + |
| 169 | + # Stage and commit changes |
| 170 | + git add eng/ci/templates/java-versions.yml |
| 171 | + git commit -m "Update Java versions |
| 172 | + |
| 173 | + Auto-detected new Java versions from Microsoft OpenJDK releases. |
| 174 | + |
| 175 | + This PR was automatically generated by the Java version check pipeline. |
| 176 | + |
| 177 | + Pipeline Run: $(Build.BuildNumber)" |
| 178 | + |
| 179 | + # Push the branch |
| 180 | + git push origin $BRANCH_NAME |
| 181 | + |
| 182 | + # Store branch name for PR creation |
| 183 | + echo "##vso[task.setvariable variable=BranchName]$BRANCH_NAME" |
| 184 | + displayName: 'Commit and push changes' |
| 185 | + condition: eq(variables['HasChanges'], 'true') |
| 186 | + |
| 187 | + - bash: | |
| 188 | + set -e |
| 189 | + |
| 190 | + BRANCH_NAME="$(BranchName)" |
| 191 | + GITHUB_REPO="Azure/azure-functions-java-worker" |
| 192 | + |
| 193 | + echo "Branch name: $BRANCH_NAME" |
| 194 | + echo "GitHub repository: $GITHUB_REPO" |
| 195 | + |
| 196 | + # Extract GitHub token from the git remote URL credentials |
| 197 | + # Azure Pipelines injects the token into the git config |
| 198 | + GIT_TOKEN=$(git config --get-urlmatch http.extraheader https://github.com/${GITHUB_REPO} | sed -n 's/.*AUTHORIZATION: basic \(.*\)/\1/p' | base64 -d | cut -d: -f2) |
| 199 | + |
| 200 | + if [ -z "$GIT_TOKEN" ]; then |
| 201 | + echo "WARNING: Could not extract GitHub token from git config" |
| 202 | + echo "Attempting to use System.AccessToken directly..." |
| 203 | + GIT_TOKEN="$(System.AccessToken)" |
| 204 | + fi |
| 205 | + |
| 206 | + # Check if PR already exists |
| 207 | + echo "Checking for existing PR from branch: $BRANCH_NAME" |
| 208 | + EXISTING_PR=$(curl -s \ |
| 209 | + -H "Authorization: token ${GIT_TOKEN}" \ |
| 210 | + -H "Accept: application/vnd.github+json" \ |
| 211 | + "https://api.github.com/repos/${GITHUB_REPO}/pulls?head=Azure:${BRANCH_NAME}&state=open") |
| 212 | + |
| 213 | + PR_COUNT=$(echo "$EXISTING_PR" | grep -c '"number":' || true) |
| 214 | + |
| 215 | + if [ "$PR_COUNT" -gt 0 ]; then |
| 216 | + PR_NUMBER=$(echo "$EXISTING_PR" | grep -o '"number":[0-9]*' | head -1 | grep -o '[0-9]*') |
| 217 | + echo "PR already exists for branch $BRANCH_NAME" |
| 218 | + echo "Existing PR: https://github.com/${GITHUB_REPO}/pull/${PR_NUMBER}" |
| 219 | + exit 0 |
| 220 | + fi |
| 221 | + |
| 222 | + CURRENT_DATE=$(date -u +"%Y-%m-%d %H:%M:%S UTC") |
| 223 | + BUILD_NUM="$(Build.BuildNumber)" |
| 224 | + |
| 225 | + # Create JSON payload for PR |
| 226 | + cat > /tmp/pr_payload.json << 'JSONEOF' |
| 227 | + { |
| 228 | + "title": "Update Java versions to latest releases", |
| 229 | + "body": "This PR updates the Java version variables in `eng/ci/templates/java-versions.yml` to the latest versions.\n\n## Changes\n- Auto-detected and validated new Java versions\n- **JDK 8**: From Adoptium (Eclipse Temurin)\n- **JDK 11, 17, 21, 25**: From Microsoft OpenJDK\n- Linux JDKs validated on Linux pool\n- Windows JDKs validated on Windows pool\n- All JDK installations were validated using `java -version`\n\n## Automated Process\nThis PR was automatically created by the Java Version Check Pipeline.\n\n## Review Checklist\n- [ ] Verify version numbers are correct\n- [ ] Check that both Linux and Windows versions are updated\n- [ ] Ensure CI tests pass with new versions\n\n**Pipeline Run:** BUILDNUMBER_PLACEHOLDER\n**Date:** CURRENTDATE_PLACEHOLDER", |
| 230 | + "head": "BRANCHNAME_PLACEHOLDER", |
| 231 | + "base": "dev" |
| 232 | + } |
| 233 | + JSONEOF |
| 234 | + |
| 235 | + # Replace placeholders |
| 236 | + sed -i "s|BRANCHNAME_PLACEHOLDER|${BRANCH_NAME}|g" /tmp/pr_payload.json |
| 237 | + sed -i "s|BUILDNUMBER_PLACEHOLDER|${BUILD_NUM}|g" /tmp/pr_payload.json |
| 238 | + sed -i "s|CURRENTDATE_PLACEHOLDER|${CURRENT_DATE}|g" /tmp/pr_payload.json |
| 239 | + |
| 240 | + echo "Creating pull request on GitHub..." |
| 241 | + PR_RESPONSE=$(curl -s -w "\n%{http_code}" \ |
| 242 | + -X POST \ |
| 243 | + -H "Authorization: token ${GIT_TOKEN}" \ |
| 244 | + -H "Accept: application/vnd.github+json" \ |
| 245 | + -H "Content-Type: application/json" \ |
| 246 | + -d @/tmp/pr_payload.json \ |
| 247 | + "https://api.github.com/repos/${GITHUB_REPO}/pulls") |
| 248 | + |
| 249 | + HTTP_CODE=$(echo "$PR_RESPONSE" | tail -n1) |
| 250 | + RESPONSE_BODY=$(echo "$PR_RESPONSE" | head -n-1) |
| 251 | + |
| 252 | + echo "HTTP Status: $HTTP_CODE" |
| 253 | + |
| 254 | + if [ "$HTTP_CODE" = "201" ]; then |
| 255 | + PR_NUMBER=$(echo "$RESPONSE_BODY" | grep -o '"number":[0-9]*' | head -1 | grep -o '[0-9]*') |
| 256 | + echo "Pull request created successfully! PR #$PR_NUMBER" |
| 257 | + echo "URL: https://github.com/${GITHUB_REPO}/pull/${PR_NUMBER}" |
| 258 | + else |
| 259 | + echo "ERROR: Failed to create pull request" |
| 260 | + echo "Response: $RESPONSE_BODY" |
| 261 | + echo "" |
| 262 | + echo "The branch has been pushed to: $BRANCH_NAME" |
| 263 | + echo "You can manually create a PR at:" |
| 264 | + echo "https://github.com/${GITHUB_REPO}/compare/dev...${BRANCH_NAME}" |
| 265 | + exit 1 |
| 266 | + fi |
| 267 | + displayName: 'Create Pull Request on GitHub' |
| 268 | + condition: eq(variables['HasChanges'], 'true') |
| 269 | + env: |
| 270 | + SYSTEM_ACCESSTOKEN: $(System.AccessToken) |
0 commit comments