|
| 1 | +name: Update Spring Cloud Azure Support File |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + - cron: '0 0 * * *' |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +env: |
| 8 | + PR_TITLE: "Update Spring Boot and Spring Cloud versions for the Spring compatibility tests" |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + issues: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + check-open-pr: |
| 17 | + name: Check Open Pull Request |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + has_open_pr: ${{ steps.check.outputs.has_open_pr }} |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + - name: Check for Existing Open Pull Request |
| 24 | + id: check |
| 25 | + uses: actions/github-script@v7 |
| 26 | + with: |
| 27 | + script: | |
| 28 | + const prTitle = process.env.PR_TITLE; |
| 29 | + const { data: pullRequests } = await github.rest.pulls.list({ |
| 30 | + owner: context.repo.owner, |
| 31 | + repo: context.repo.repo, |
| 32 | + state: 'open' |
| 33 | + }); |
| 34 | +
|
| 35 | + const openPRs = pullRequests.filter(pr => pr.title === prTitle); |
| 36 | + core.setOutput('has_open_pr', openPRs.length > 0 ? 'true' : 'false'); |
| 37 | +
|
| 38 | + update: |
| 39 | + name: Update Support File and Create PR |
| 40 | + needs: check-open-pr |
| 41 | + if: ${{ needs.check-open-pr.outputs.has_open_pr == 'false' }} |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + fetch-depth: 0 |
| 47 | + - name: Generate Spring Cloud Azure Support File |
| 48 | + run: | |
| 49 | + python ./sdk/spring/scripts/generate_spring_cloud_azure_support_file.py |
| 50 | + - name: Set Branch Name with Timestamp |
| 51 | + run: | |
| 52 | + TIMESTAMP=$(date +%Y%m%d-%H%M%S) |
| 53 | + GITHUB_ACTION_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |
| 54 | +
|
| 55 | + echo "BRANCH_NAME=update-spring-cloud-azure-support-file-${TIMESTAMP}" >> $GITHUB_ENV |
| 56 | +
|
| 57 | + echo "COMMIT_MESSAGE<<EOF" >> $GITHUB_ENV |
| 58 | + echo "${PR_TITLE}." >> $GITHUB_ENV |
| 59 | + echo "This commit is created by GitHub Action: ${GITHUB_ACTION_URL}" >> $GITHUB_ENV |
| 60 | + echo "EOF" >> $GITHUB_ENV |
| 61 | +
|
| 62 | + echo "PULL_REQUEST_BODY<<EOF" >> $GITHUB_ENV |
| 63 | + echo "${PR_TITLE}." >> $GITHUB_ENV |
| 64 | + echo "This commit is created by GitHub Action: ${GITHUB_ACTION_URL}" >> $GITHUB_ENV |
| 65 | + echo "EOF" >> $GITHUB_ENV |
| 66 | + - name: Make Decision Based on Git Diff |
| 67 | + run: | |
| 68 | + git checkout -b "${{ env.BRANCH_NAME }}" |
| 69 | + if [[ -n "$(git status -s)" ]]; then |
| 70 | + echo "NEED_UPDATE_FILE=true" >> $GITHUB_ENV |
| 71 | + else |
| 72 | + echo "No file changes, no commits." |
| 73 | + fi |
| 74 | + - name: Update Spring Cloud Azure Timeline |
| 75 | + if: ${{ env.NEED_UPDATE_FILE == 'true' }} |
| 76 | + run: | |
| 77 | + TODAY=$(date +%Y-%m-%d) |
| 78 | + TIMELINE_FILE=docs/spring/Spring-Cloud-Azure-Timeline.md |
| 79 | + SUPPORT_FILE=sdk/spring/pipeline/spring-cloud-azure-supported-spring.json |
| 80 | +
|
| 81 | + OLD_4X=$(git show "HEAD:${SUPPORT_FILE}" | jq -Sc '[.[] | select(."spring-boot-version" | startswith("4."))] | sort_by([."spring-boot-version", ."spring-cloud-version", .supportStatus, .current])') |
| 82 | + NEW_4X=$(jq -Sc '[.[] | select(."spring-boot-version" | startswith("4."))] | sort_by([."spring-boot-version", ."spring-cloud-version", .supportStatus, .current])' "${SUPPORT_FILE}") |
| 83 | +
|
| 84 | + if [[ "${OLD_4X}" == "${NEW_4X}" ]]; then |
| 85 | + echo "No Spring Boot 4.x changes detected, skip timeline update." |
| 86 | + exit 0 |
| 87 | + fi |
| 88 | +
|
| 89 | + SUPPORTED_LINES=$(jq -r ' |
| 90 | + .[] |
| 91 | + | select(.supportStatus == "SUPPORTED") |
| 92 | + | select(.["spring-boot-version"] | startswith("4.")) |
| 93 | + | " - spring-boot-dependencies:\(.["spring-boot-version"]) and spring-cloud-dependencies:\(.["spring-cloud-version"])." |
| 94 | + ' "${SUPPORT_FILE}") |
| 95 | +
|
| 96 | + if [[ -z "${SUPPORTED_LINES}" ]]; then |
| 97 | + echo "No supported Spring Boot 4.x entries found, skip timeline update." |
| 98 | + exit 0 |
| 99 | + fi |
| 100 | +
|
| 101 | + NEW_ENTRY=$(printf ' - **%s**: In "java - spring - compatibility - tests" pipeline, run unit tests:\n%s' "$TODAY" "$SUPPORTED_LINES") |
| 102 | + awk -v entry="$NEW_ENTRY" ' |
| 103 | + { print } |
| 104 | + /^## Timeline$/ && !inserted { print entry; inserted=1 } |
| 105 | + ' "$TIMELINE_FILE" > "$TIMELINE_FILE.tmp" |
| 106 | + mv "$TIMELINE_FILE.tmp" "$TIMELINE_FILE" |
| 107 | + - name: Push Commit |
| 108 | + if: ${{ env.NEED_UPDATE_FILE == 'true' }} |
| 109 | + run: | |
| 110 | + git config --global user.email github-actions@github.com |
| 111 | + git config --global user.name github-actions |
| 112 | + git add sdk/spring/pipeline/spring-cloud-azure-supported-spring.json |
| 113 | + git add docs/spring/Spring-Cloud-Azure-Timeline.md |
| 114 | + git commit -m "${{ env.COMMIT_MESSAGE }}" |
| 115 | + git push origin "${{ env.BRANCH_NAME }}" |
| 116 | + - name: Create Pull Request |
| 117 | + id: create_pr |
| 118 | + if: ${{ env.NEED_UPDATE_FILE == 'true' }} |
| 119 | + uses: actions/github-script@v7 |
| 120 | + with: |
| 121 | + script: | |
| 122 | + const pr = await github.rest.pulls.create({ |
| 123 | + owner: context.repo.owner, |
| 124 | + repo: context.repo.repo, |
| 125 | + title: process.env.PR_TITLE, |
| 126 | + head: process.env.BRANCH_NAME, |
| 127 | + base: 'main', |
| 128 | + body: process.env.PULL_REQUEST_BODY |
| 129 | + }); |
| 130 | + core.setOutput('pull_request_number', String(pr.data.number)); |
| 131 | + - name: Comment on Pull Request |
| 132 | + if: ${{ env.NEED_UPDATE_FILE == 'true' }} |
| 133 | + uses: actions/github-script@v7 |
| 134 | + with: |
| 135 | + script: | |
| 136 | + const prNumber = Number('${{ steps.create_pr.outputs.pull_request_number }}'); |
| 137 | + if (!prNumber) { |
| 138 | + console.log('No pull request was created, nothing to comment on.'); |
| 139 | + return; |
| 140 | + } |
| 141 | +
|
| 142 | + await github.rest.issues.createComment({ |
| 143 | + owner: context.repo.owner, |
| 144 | + repo: context.repo.repo, |
| 145 | + issue_number: prNumber, |
| 146 | + body: '/azp run java - spring - tests' |
| 147 | + }); |
0 commit comments