Skip to content

Commit f9563dd

Browse files
committed
chore: [DevOps] Spec File Update Process
1 parent 4ba7069 commit f9563dd

File tree

2 files changed

+140
-1
lines changed

2 files changed

+140
-1
lines changed

.github/workflows/continuous-integration.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ env:
1414
jobs:
1515

1616
continuous-integration:
17-
# https://wiki.one.int.sap/wiki/display/DevFw/SUGAR
1817
runs-on: ubuntu-latest
1918
steps:
2019

.github/workflows/spec-update.yaml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: "Spec File Update Workflow"
2+
3+
on:
4+
push:
5+
branches:
6+
- chore/spec-update-job
7+
8+
workflow_dispatch:
9+
inputs:
10+
file:
11+
description: "Which spec file to update"
12+
type: choice
13+
required: false
14+
options:
15+
- core
16+
- grounding
17+
- orchestration
18+
default: orchestration
19+
file-ref:
20+
description: "Branch or tag to checkout the spec file from"
21+
required: false
22+
default: main
23+
type: string
24+
create-pr:
25+
description: "Create a pull request after updating the spec file"
26+
required: false
27+
default: true
28+
type: boolean
29+
30+
env:
31+
MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C
32+
JAVA_VERSION: 17
33+
34+
jobs:
35+
generate:
36+
name: "Download, Generate, Compile and Push"
37+
runs-on: [ubuntu-latest]
38+
permissions:
39+
pull-requests: write
40+
contents: write
41+
outputs:
42+
spec_diff: ${{ steps.spec_diff.outputs.spec_diff }}
43+
branch: ${{ steps.push.outputs.branch }}
44+
env:
45+
API_BASE_URL: "https://github.tools.sap/api/v3/repos"
46+
CHOICE: "orchestration" # TODO: replace with ${{ github.event.inputs.file }}
47+
REF: "v0.48.2" # TODO: replace with ${{ github.event.inputs.file-ref }}
48+
CREATE_PR: "true" # TODO: replace with ${{ github.event.inputs.create-pr }}
49+
steps:
50+
- name: "Checkout repository"
51+
uses: actions/checkout@v4
52+
- name: "Checkout or Create Branch"
53+
id: branch
54+
run: |
55+
BRANCH="spec-update/$CHOICE/$REF"
56+
git checkout -b $BRANCH
57+
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
58+
59+
- name: "Download specification file"
60+
id: download
61+
run: |
62+
gh auth login --hostname github.tools.sap --with-token ${{ secrets.GH_TOOLS_TOKEN }}
63+
64+
case $CHOICE in
65+
core)
66+
API_URL="$API_BASE_URL/cloudsdk/cloud-sdk-java-tests/contents/aicore.yaml?ref=$REF"
67+
FILE_PATH='core/src/main/resources/spec/aicore.yaml'
68+
;;
69+
grounding)
70+
# TODO
71+
exit 1
72+
;;
73+
orchestration)
74+
API_URL="$API_BASE_URL/AI/llm-orchestration/contents/src/spec/api.yaml?ref=$REF"
75+
FILE_PATH='orchestration/src/main/resources/spec/orchestration.yaml'
76+
;;
77+
esac
78+
79+
echo "Downloading $CHOICE specification file from $API_URL ..."
80+
81+
gh api $API_URL -H "Accept: application/vnd.github.raw" > $FILE_PATH
82+
83+
- name: "Exit if there are no changes"
84+
id: spec_diff
85+
run: |
86+
if [[ `git status --porcelain` ]]; then
87+
echo "spec_diff=true" >> "$GITHUB_OUTPUT"
88+
else
89+
echo "spec_diff=false" >> "$GITHUB_OUTPUT"
90+
fi
91+
92+
- name: "Setup java"
93+
uses: actions/setup-java@v4
94+
if: steps.spec_diff.outputs.spec_diff == 'true'
95+
with:
96+
distribution: "temurin"
97+
java-version: ${{ env.JAVA_VERSION }}
98+
cache: 'maven'
99+
100+
- name: "Generate Client"
101+
id: generate
102+
if: steps.spec_diff.outputs.spec_diff == 'true'
103+
run: |
104+
echo "success=false" >> "$GITHUB_OUTPUT"
105+
mvn process-sources -Dgenerate ${{ env.MVN_MULTI_THREADED_ARGS }}
106+
echo "success=true" >> "$GITHUB_OUTPUT"
107+
108+
- name: "Compile Client"
109+
id: compile
110+
if: steps.spec_diff.outputs.spec_diff == 'true'
111+
run: |
112+
mvn test-compile ${{ env.MVN_MULTI_THREADED_ARGS }}
113+
114+
- name: "Push changes"
115+
id: push
116+
if: steps.spec_diff.outputs.spec_diff == 'true'
117+
run: |
118+
# TODO: decide if timestamp is necessary
119+
# TIME=$(date '+%d-%m--%H:%M')
120+
121+
git add .
122+
git commit -m "Update $CHOICE on $REF at $TIME"
123+
git push origin $BRANCH
124+
125+
- name: "Create pull request"
126+
if: ${{ env.CREATE_PR }}
127+
run: |
128+
gh pr create --base main --head ${{ steps.push.outputs.branch }} --title "feat: [DevOps] Update $CHOICE Specification"
129+
130+
- name: "Handle failure"
131+
if: ${{ failure() }}
132+
run: |
133+
echo "Failed to update $CHOICE specification file"
134+
echo "File download outcome: ${{ steps.download.outcome }}"
135+
echo "Spec file contained changes: ${{ steps.spec_diff.output.spec_diff }}"
136+
echo "Client generation outcome: ${{ steps.generate.output.success }}"
137+
echo "Client compilation outcome: ${{ steps.compile.outcome }}"
138+
139+
# TODO: Delete branch?
140+
# git push origin --delete ${{ steps.push.outputs.branch }}

0 commit comments

Comments
 (0)