Skip to content

Commit a173e05

Browse files
authored
chore: [DevOps] Minor Spec Update Job Improvements (#299)
1 parent 7ec7dff commit a173e05

File tree

1 file changed

+44
-34
lines changed

1 file changed

+44
-34
lines changed

.github/workflows/spec-update.yaml

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
outputs:
3838
spec_diff: ${{ steps.spec_diff.outputs.spec_diff }}
3939
branch: ${{ steps.push.outputs.branch }}
40+
pr_url: ${{ steps.create-pr.outputs.pr_url }}
4041
compilation_result: ${{ steps.compile.outputs.compilation_result }}
4142
test_result: ${{ steps.compile.outputs.test_result }}
4243
env:
@@ -50,6 +51,15 @@ jobs:
5051
with:
5152
token: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
5253

54+
- name: "Checkout or Create Branch"
55+
id: branch
56+
# Checkout branch if it exists, otherwise create it
57+
run: |
58+
BRANCH="spec-update/$CHOICE/$REF"
59+
git fetch origin $BRANCH || true
60+
git checkout -B $BRANCH origin/$BRANCH || git checkout -b $BRANCH
61+
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
62+
5363
- name: "Download specification file"
5464
id: download
5565
env:
@@ -83,27 +93,6 @@ jobs:
8393
echo "spec_diff=false" >> "$GITHUB_OUTPUT"
8494
fi
8595
86-
- name: "Checkout or Create Branch"
87-
# Always create a new branch to ensure we generate from a clean state.
88-
# In case a PR exist we can't delete and re-create the branch (without closing the PR first).
89-
# So the workflow will exist in this case.
90-
id: branch
91-
env:
92-
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
93-
run: |
94-
BRANCH="spec-update/$CHOICE/$REF"
95-
if gh pr list --head $BRANCH --json number -q '.[].number' | grep -q .; then
96-
echo "An open PR already exists for this branch. Please close the PR first before re-running the workflow."
97-
exit 1
98-
fi
99-
100-
if git ls-remote --exit-code origin refs/heads/$BRANCH >/dev/null 2>&1; then
101-
echo "Branch '$BRANCH' exists on remote, deleting it..."
102-
git push origin --delete $BRANCH
103-
fi
104-
git checkout -b $BRANCH
105-
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
106-
10796
- name: "Setup java"
10897
uses: actions/setup-java@v4
10998
if: steps.spec_diff.outputs.spec_diff == 'true'
@@ -133,6 +122,7 @@ jobs:
133122
fi
134123
else
135124
echo "compilation_result=failure" >> "$GITHUB_OUTPUT"
125+
echo "test_result=skipped" >> "$GITHUB_OUTPUT"
136126
fi
137127
138128
- name: "Push changes"
@@ -141,40 +131,60 @@ jobs:
141131
run: |
142132
git config --global user.email "[email protected]"
143133
git config --global user.name "SAP Cloud SDK Bot"
144-
git add .
134+
git add --all
135+
git status
145136
git commit -m "Update $CHOICE based on $REF"
146137
git push --set-upstream origin ${{ steps.branch.outputs.branch }}
147138
148139
- name: "Create PR"
149-
if: ${{ env.CREATE_PR && steps.spec_diff.outputs.spec_diff == 'true'}}
140+
id: create-pr
141+
if: ${{ env.CREATE_PR == 'true' && steps.spec_diff.outputs.spec_diff == 'true'}}
150142
env:
151143
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
144+
BRANCH: ${{ steps.branch.outputs.branch }}
152145
run: |
153-
gh pr create --base main --head ${{ steps.branch.outputs.branch }} --title "feat: [DevOps] Update $CHOICE Specification" --body "
146+
if gh pr list --head $BRANCH --json number -q '.[].number' | grep -q .; then
147+
echo "An open PR already exists for this branch. Skipping PR creation."
148+
exit 0
149+
fi
150+
151+
PR_URL=$(gh pr create --base main --head $BRANCH --title "feat: [DevOps] Update $CHOICE specification" --body "
154152
## Context
155153
156154
Update $CHOICE specification file based on $REF.
157155
158156
This PR was created automatically by the [spec-update workflow](https://github.com/SAP/ai-sdk-java/actions/workflows/spec-update.yaml).
159157
You can commit on top of this branch, but as long as this PR is open the action can't be re-run.
160158
161-
- Compilation outcome: ${{ steps.compile.output.test_result }}
162-
- Test run outcome: ${{ steps.compile.output.test_result }}
159+
- Compilation outcome: ${{ steps.compile.outputs.compilation_result }}
160+
- Test run outcome: ${{ steps.compile.outputs.test_result }}
163161
164162
Before merging, make sure to update tests and release notes, if necessary.
165163
166164
## Definition of Done
167165
168166
- [ ] Unit tests cover new classes
169167
- [ ] Release notes updated
170-
"
168+
") && echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
171169
172-
- name: "Print Summary"
170+
- name: Generate Job Summary
173171
if: ${{ always() }}
172+
env:
173+
BRANCH: ${{ steps.branch.outputs.branch }}
174+
PR_URL: ${{ steps.create-pr.outputs.pr_url }}
174175
run: |
175-
echo "Branch creation: ${{ steps.branch.outcome }}"
176-
echo "File download outcome: ${{ steps.download.outcome }}"
177-
echo "Spec file contained changes: ${{ steps.spec_diff.outputs.spec_diff }}"
178-
echo "Client generation outcome: ${{ steps.generate.outcome }}"
179-
echo "Client compilation outcome: ${{ steps.compile.output.compilation_result }}"
180-
echo "Client test outcome: ${{ steps.compile.output.test_result }}"
176+
DIFF_URL="https://github.com/SAP/ai-sdk-java/compare/main...$BRANCH"
177+
echo "## Workflow Execution Summary" >> $GITHUB_STEP_SUMMARY
178+
echo "" >> $GITHUB_STEP_SUMMARY
179+
echo "| Step | Status |" >> $GITHUB_STEP_SUMMARY
180+
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
181+
echo "| File Download | ${{ steps.download.outcome == 'success' && '✅' || '❌' }} ${{ steps.download.outcome }}" >> $GITHUB_STEP_SUMMARY
182+
echo "| Spec File Changes | ${{ steps.spec_diff.outputs.spec_diff == 'true' && '🔄 Changes Detected' || '⏹️ No Changes' }}" >> $GITHUB_STEP_SUMMARY
183+
184+
if ${{ steps.spec_diff.outputs.spec_diff == 'true' }}; then
185+
echo "| Client Generation | ${{ steps.generate.outcome == 'success' && '✅' || '❌' }} ${{ steps.generate.outcome }}" >> $GITHUB_STEP_SUMMARY
186+
echo "| Client Compilation | ${{ steps.compile.outputs.compilation_result == 'success' && '✅' || '❌' }} ${{ steps.compile.outputs.compilation_result }}" >> $GITHUB_STEP_SUMMARY
187+
echo "| Client Testing | ${{ steps.compile.outputs.test_result == 'success' && '✅' || steps.compile.outputs.test_result == 'skipped' && '⏩' || '❌' }} ${{ steps.compile.outputs.test_result }}" >> $GITHUB_STEP_SUMMARY
188+
echo "| Branch Creation | ${{ steps.push.outcome == 'success' && '✅ [Branch Link]($DIFF_URL)' || '❌ failure' }}" >> $GITHUB_STEP_SUMMARY
189+
echo "| Pull Request Creation | ${{ env.CREATE_PR == 'false' && '⏩ skipped' || '' }}${{ env.CREATE_PR == 'true' && steps.push.outcome == 'success' && '✅ [PR Link]($PR_URL)' || '' }}" >> $GITHUB_STEP_SUMMARY
190+
fi

0 commit comments

Comments
 (0)