Skip to content

Commit 12bf682

Browse files
committed
Add Github Action workflow for updating DW Components Release matrix info to confluence
1 parent e2ba556 commit 12bf682

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

.github/workflows/project-codeflare-release.yml

+27
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ on:
3838
description: 'Owner of target community-operators-prod repository used to open a PR against'
3939
required: true
4040
default: 'redhat-openshift-ecosystem'
41+
rhoai-release-version:
42+
description: "RHOAI Release version for updating Component Release Matrix Versions Info "
43+
required: true
4144

4245
jobs:
4346
release-parameters:
@@ -184,3 +187,27 @@ jobs:
184187
185188
- name: Verify generated file
186189
run: cat config/component_metadata.yaml
190+
191+
Update_release_version_info_to_confluence:
192+
runs-on: ubuntu-latest
193+
steps:
194+
- name: Checkout Repository
195+
uses: actions/checkout@v4
196+
197+
- name: Trigger and Update Component Release Matrix Versions Info
198+
run: |
199+
gh workflow run update_confluence.yml --ref updateReleaseDetails \
200+
--field rhoai-release-version=${{ github.event.inputs.rhoai-release-version }} \
201+
--field kueue-version=${{ github.event.inputs.kueue-version }} \
202+
--field codeflare-sdk-version=${{ github.event.inputs.codeflare-sdk-version }} \
203+
--field codeflare-operator-version=${{ github.event.inputs.operator-version }} \
204+
--field kuberay-version=${{ github.event.inputs.kuberay-version }} \
205+
--field appwrapper-version=${{ github.event.inputs.appwrapper-version }}
206+
207+
# wait for a while for Run to be started
208+
sleep 5
209+
run_id=$(gh run list --workflow update-release-matrix-to-confluence.yml --repo https://github.com/project-codeflare/codeflare-operator --limit 1 --json databaseId --jq .[].databaseId)
210+
gh run watch ${run_id} --repo https://github.com/project-codeflare/codeflare-operator --interval 10 --exit-status
211+
env:
212+
GITHUB_TOKEN: ${{ secrets.CODEFLARE_MACHINE_ACCOUNT_TOKEN }}
213+
shell: bash
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Update Confluence Table
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
rhoai-release-version:
7+
description: 'RHOAI Release Version'
8+
required: true
9+
kueue-version:
10+
description: 'Kueue Version'
11+
required: true
12+
codeflare-sdk-version:
13+
description: 'CodeFlare SDK Version'
14+
required: true
15+
codeflare-operator-version:
16+
description: 'CodeFlare operator Version'
17+
required: true
18+
kuberay-version:
19+
description: 'Tested KubeRay version'
20+
required: true
21+
appwrapper-version:
22+
description: 'Tested appwrapper version'
23+
required: true
24+
25+
jobs:
26+
update-confluence:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout Repository
30+
uses: actions/checkout@v4
31+
32+
- name: Release info Parameters
33+
run: |
34+
echo "RHOAI_RELEASE_VERSION=${{ github.event.inputs.rhoai-release-version }}" >> $GITHUB_ENV
35+
echo "KUEUE_VERSION=${{ github.event.inputs.kueue-version }}" >> $GITHUB_ENV
36+
echo "CODEFLARE_SDK_VERSION=${{ github.event.inputs.codeflare-sdk-version }}" >> $GITHUB_ENV
37+
echo "CODEFLARE_OPERATOR_VERSION=${{ github.event.inputs.codeflare-operator-version }}" >> $GITHUB_ENV
38+
echo "KUBERAY_VERSION=${{ github.event.inputs.kuberay-version }}" >> $GITHUB_ENV
39+
echo "APPWRAPPER_VERSION=${{ github.event.inputs.appwrapper-version }}" >> $GITHUB_ENV
40+
41+
- name: Fetch and Update Existing Release Matrix Page Content
42+
run: |
43+
echo "Fetching Release Matrix Confluence Page..."
44+
response=$(curl -H "Authorization: Bearer ${{ secrets.CONFLUENCE_API_TOKEN }}" \
45+
"${{ secrets.CONFLUENCE_BASE_URL }}/rest/api/content?title=${{ secrets.PAGE_TITLE }}&spaceKey=${{ secrets.SPACE_KEY }}&expand=body.storage,version")
46+
47+
echo "$response" | jq '.' > page_data.json
48+
echo "Raw API Response: $response"
49+
50+
PAGE_VERSION=$(jq '.results[0].version.number' page_data.json)
51+
52+
if [[ -z "$PAGE_VERSION" || "$PAGE_VERSION" == "null" ]]; then
53+
echo "Error: Could not retrieve current page version."
54+
exit 1
55+
fi
56+
echo "PAGE_VERSION=$PAGE_VERSION" >> $GITHUB_ENV
57+
58+
EXISTING_CONTENT=$(jq -r '.results[0].body.storage.value' page_data.json)
59+
60+
echo "Existing Release Matrix Page Content: $EXISTING_CONTENT"
61+
62+
if [[ -z "$EXISTING_CONTENT" || "$EXISTING_CONTENT" == "null" ]]; then
63+
echo "Error: Could not retrieve existing page content."
64+
exit 1
65+
fi
66+
67+
# Convert newlines to a placeholder to handle multi-line processing
68+
PLACEHOLDER="__NL__"
69+
MODIFIED_CONTENT=$(echo "$EXISTING_CONTENT" | tr '\n' "$PLACEHOLDER")
70+
71+
# Update the page content with release info also check and update if the release version already exists in the table
72+
if echo "$MODIFIED_CONTENT" | grep -q "<tr[^>]*><td>$RHOAI_RELEASE_VERSION</td>"; then
73+
UPDATED_PAGE_CONTENT=$(echo "$MODIFIED_CONTENT" | sed -E "s|(<tr[^>]*><td>$RHOAI_RELEASE_VERSION</td><td>)[^<]+(</td><td>)[^<]+(</td><td>)[^<]+(</td><td>)[^<]+(</td><td>)[^<]+(</td></tr>)|\1$KUEUE_VERSION\2$CODEFLARE_SDK_VERSION\3$CODEFLARE_OPERATOR_VERSION\4$KUBERAY_VERSION\5$APPWRAPPER_VERSION\6|")
74+
else
75+
UPDATED_ROW="<tr class=\"\"><td>$RHOAI_RELEASE_VERSION</td><td>$KUEUE_VERSION</td><td>$CODEFLARE_SDK_VERSION</td><td>$CODEFLARE_OPERATOR_VERSION</td><td>$KUBERAY_VERSION</td><td>$APPWRAPPER_VERSION</td></tr>"
76+
UPDATED_PAGE_CONTENT=$(echo "$MODIFIED_CONTENT" | sed "s|</tbody>|$UPDATED_ROW</tbody>|")
77+
fi
78+
79+
# Correct JSON encoding without double escaping
80+
UPDATED_PAGE_CONTENT=$(echo "$UPDATED_PAGE_CONTENT" | sed 's/_$//') # Remove trailing underscores
81+
UPDATED_PAGE_CONTENT=$(jq -n --arg content "$UPDATED_PAGE_CONTENT" '$content' | tr -d '\r')
82+
# Store as output
83+
echo "UPDATED_PAGE_CONTENT=$UPDATED_PAGE_CONTENT" >> "$GITHUB_ENV"
84+
85+
- name: Publish updated page content to confluence
86+
run: |
87+
88+
NEW_VERSION=$(( PAGE_VERSION + 1 ))
89+
90+
if [[ -n "$UPDATED_PAGE_CONTENT" && "$UPDATED_PAGE_CONTENT" != "null" ]]; then
91+
echo "Updating Confluence Page using PUT request..."
92+
HTTP_RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X PUT "${{ secrets.CONFLUENCE_BASE_URL }}/rest/api/content/${{ secrets.CONFLUENCE_PAGE_ID }}" \
93+
-H "Authorization: Bearer ${{ secrets.CONFLUENCE_API_TOKEN }}" \
94+
-H "Content-Type: application/json" \
95+
-d "{
96+
\"id\": \"${{ secrets.CONFLUENCE_PAGE_ID }}\",
97+
\"type\": \"page\",
98+
\"title\": \"Distributed Workloads Release Details\",
99+
\"space\": { \"key\": \"${{ secrets.SPACE_KEY }}\" },
100+
\"body\": {
101+
\"storage\": {
102+
\"value\": $UPDATED_PAGE_CONTENT,
103+
\"representation\": \"storage\"
104+
}
105+
},
106+
\"version\": {
107+
\"number\": $NEW_VERSION
108+
}
109+
}")
110+
if [[ "$HTTP_RESPONSE" == "200" || "$HTTP_RESPONSE" == "201" ]]; then
111+
echo "Successfully updated Confluence Page with release version details !"
112+
echo "Response from Confluence:"
113+
cat response.json # Print full response
114+
else
115+
echo "Error: Failed to update Confluence page. HTTP Response Code: $HTTP_RESPONSE"
116+
exit 1
117+
fi
118+
else
119+
echo "Error: UPDATED_PAGE_CONTENT is null or empty."
120+
exit 1
121+
fi

0 commit comments

Comments
 (0)