-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathupdate-spring-cloud-azure-support-file.yml
More file actions
147 lines (133 loc) · 5.76 KB
/
Copy pathupdate-spring-cloud-azure-support-file.yml
File metadata and controls
147 lines (133 loc) · 5.76 KB
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
name: Update Spring Cloud Azure Support File
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
env:
PR_TITLE: "Update Spring Boot and Spring Cloud versions for the Spring compatibility tests"
permissions:
contents: write
pull-requests: write
issues: write
jobs:
check-open-pr:
name: Check Open Pull Request
runs-on: ubuntu-latest
outputs:
has_open_pr: ${{ steps.check.outputs.has_open_pr }}
steps:
- uses: actions/checkout@v4
- name: Check for Existing Open Pull Request
id: check
uses: actions/github-script@v7
with:
script: |
const prTitle = process.env.PR_TITLE;
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
const openPRs = pullRequests.filter(pr => pr.title === prTitle);
core.setOutput('has_open_pr', openPRs.length > 0 ? 'true' : 'false');
update:
name: Update Support File and Create PR
needs: check-open-pr
if: ${{ needs.check-open-pr.outputs.has_open_pr == 'false' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Spring Cloud Azure Support File
run: |
python ./sdk/spring/scripts/generate_spring_cloud_azure_support_file.py
- name: Set Branch Name with Timestamp
run: |
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
GITHUB_ACTION_URL="https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
echo "BRANCH_NAME=update-spring-cloud-azure-support-file-${TIMESTAMP}" >> $GITHUB_ENV
echo "COMMIT_MESSAGE<<EOF" >> $GITHUB_ENV
echo "${PR_TITLE}." >> $GITHUB_ENV
echo "This commit is created by GitHub Action: ${GITHUB_ACTION_URL}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "PULL_REQUEST_BODY<<EOF" >> $GITHUB_ENV
echo "${PR_TITLE}." >> $GITHUB_ENV
echo "This commit is created by GitHub Action: ${GITHUB_ACTION_URL}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Make Decision Based on Git Diff
run: |
git checkout -b "${{ env.BRANCH_NAME }}"
if [[ -n "$(git status -s)" ]]; then
echo "NEED_UPDATE_FILE=true" >> $GITHUB_ENV
else
echo "No file changes, no commits."
fi
- name: Update Spring Cloud Azure Timeline
if: ${{ env.NEED_UPDATE_FILE == 'true' }}
run: |
TODAY=$(date +%Y-%m-%d)
TIMELINE_FILE=docs/spring/Spring-Cloud-Azure-Timeline.md
SUPPORT_FILE=sdk/spring/pipeline/spring-cloud-azure-supported-spring.json
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])')
NEW_4X=$(jq -Sc '[.[] | select(."spring-boot-version" | startswith("4."))] | sort_by([."spring-boot-version", ."spring-cloud-version", .supportStatus, .current])' "${SUPPORT_FILE}")
if [[ "${OLD_4X}" == "${NEW_4X}" ]]; then
echo "No Spring Boot 4.x changes detected, skip timeline update."
exit 0
fi
SUPPORTED_LINES=$(jq -r '
.[]
| select(.supportStatus == "SUPPORTED")
| select(.["spring-boot-version"] | startswith("4."))
| " - spring-boot-dependencies:\(.["spring-boot-version"]) and spring-cloud-dependencies:\(.["spring-cloud-version"])."
' "${SUPPORT_FILE}")
if [[ -z "${SUPPORTED_LINES}" ]]; then
echo "No supported Spring Boot 4.x entries found, skip timeline update."
exit 0
fi
NEW_ENTRY=$(printf ' - **%s**: In "java - spring - compatibility - tests" pipeline, run unit tests:\n%s' "$TODAY" "$SUPPORTED_LINES")
awk -v entry="$NEW_ENTRY" '
{ print }
/^## Timeline$/ && !inserted { print entry; inserted=1 }
' "$TIMELINE_FILE" > "$TIMELINE_FILE.tmp"
mv "$TIMELINE_FILE.tmp" "$TIMELINE_FILE"
- name: Push Commit
if: ${{ env.NEED_UPDATE_FILE == 'true' }}
run: |
git config --global user.email github-actions@github.com
git config --global user.name github-actions
git add sdk/spring/pipeline/spring-cloud-azure-supported-spring.json
git add docs/spring/Spring-Cloud-Azure-Timeline.md
git commit -m "${{ env.COMMIT_MESSAGE }}"
git push origin "${{ env.BRANCH_NAME }}"
- name: Create Pull Request
id: create_pr
if: ${{ env.NEED_UPDATE_FILE == 'true' }}
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: process.env.PR_TITLE,
head: process.env.BRANCH_NAME,
base: 'main',
body: process.env.PULL_REQUEST_BODY
});
core.setOutput('pull_request_number', String(pr.data.number));
- name: Comment on Pull Request
if: ${{ env.NEED_UPDATE_FILE == 'true' }}
uses: actions/github-script@v7
with:
script: |
const prNumber = Number('${{ steps.create_pr.outputs.pull_request_number }}');
if (!prNumber) {
console.log('No pull request was created, nothing to comment on.');
return;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: '/azp run java - spring - tests'
});