Skip to content

Commit 468d860

Browse files
committed
Add check if PR exists
1 parent e3e04ab commit 468d860

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

.github/workflows/spec-update.yaml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
outputs:
4242
spec_diff: ${{ steps.spec_diff.outputs.spec_diff }}
4343
branch: ${{ steps.push.outputs.branch }}
44+
compilation_result: ${{ steps.compile.outputs.compilation_result }}
45+
test_result: ${{ steps.compile.outputs.test_result }}
4446
env:
4547
API_BASE_URL: "https://github.tools.sap/api/v3/repos"
4648
CHOICE: "orchestration" # TODO: replace with ${{ github.event.inputs.file }}
@@ -54,8 +56,15 @@ jobs:
5456

5557
- name: "Checkout or Create Branch"
5658
id: branch
59+
env:
60+
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
5761
run: |
5862
BRANCH="spec-update/$CHOICE/$REF"
63+
if gh pr list --head $BRANCH --json number -q '.[].number' | grep -q .; then
64+
echo "An open PR already exists for this branch. Please close the PR first before re-running the workflow."
65+
exit 1
66+
fi
67+
5968
if git ls-remote --exit-code origin refs/heads/$BRANCH >/dev/null 2>&1; then
6069
echo "Branch '$BRANCH' exists on remote, deleting it..."
6170
git push origin --delete $BRANCH
@@ -104,7 +113,7 @@ jobs:
104113
java-version: ${{ env.JAVA_VERSION }}
105114
cache: 'maven'
106115

107-
- name: "Generate Client"
116+
- name: "Generate"
108117
id: generate
109118
if: steps.spec_diff.outputs.spec_diff == 'true'
110119
run: |
@@ -120,7 +129,7 @@ jobs:
120129
git commit -m "Update $CHOICE based on $REF"
121130
git push --set-upstream origin ${{ steps.branch.outputs.branch }}
122131
123-
- name: "Create pull request"
132+
- name: "Create PR"
124133
if: ${{ env.CREATE_PR && steps.spec_diff.outputs.spec_diff == 'true'}}
125134
env:
126135
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
@@ -142,11 +151,20 @@ jobs:
142151
- [ ] Release notes updated
143152
"
144153
145-
- name: "Compile Client"
154+
- name: "Compile and Test"
146155
id: compile
147156
if: steps.spec_diff.outputs.spec_diff == 'true'
148157
run: |
149-
mvn test-compile ${{ env.MVN_MULTI_THREADED_ARGS }}
158+
if mvn test-compile ${{ env.MVN_MULTI_THREADED_ARGS }} ; then
159+
echo "compilation_result=success" >> "$GITHUB_OUTPUT"
160+
if mvn test ${{ env.MVN_MULTI_THREADED_ARGS }} ; then
161+
echo "test_result=success" >> "$GITHUB_OUTPUT"
162+
else
163+
echo "test_result=failure" >> "$GITHUB_OUTPUT"
164+
fi
165+
else
166+
echo "compilation_result=failure" >> "$GITHUB_OUTPUT"
167+
fi
150168
151169
- name: "Handle failure"
152170
if: ${{ failure() }}
@@ -155,4 +173,5 @@ jobs:
155173
echo "File download outcome: ${{ steps.download.outcome }}"
156174
echo "Spec file contained changes: ${{ steps.spec_diff.outputs.spec_diff }}"
157175
echo "Client generation outcome: ${{ steps.generate.outcome }}"
158-
echo "Client compilation outcome: ${{ steps.compile.outcome }}"
176+
echo "Client compilation outcome: ${{ steps.compile.output.compilation_result }}"
177+
echo "Client test outcome: ${{ steps.compile.output.test_result }}"

0 commit comments

Comments
 (0)