Skip to content

Commit 5bb5f88

Browse files
committed
minor improvements
1 parent 16f24fd commit 5bb5f88

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

.github/workflows/spec-update.yaml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ jobs:
5050
with:
5151
token: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
5252

53+
- name: "Checkout or Create Branch"
54+
id: branch
55+
# Checkout branch if it exists, otherwise create it
56+
run: |
57+
BRANCH="spec-update/$CHOICE/$REF"
58+
git fetch origin $BRANCH || true
59+
git checkout -B $BRANCH origin/$BRANCH || git checkout -b $BRANCH
60+
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
61+
5362
- name: "Download specification file"
5463
id: download
5564
env:
@@ -83,27 +92,6 @@ jobs:
8392
echo "spec_diff=false" >> "$GITHUB_OUTPUT"
8493
fi
8594
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-
10795
- name: "Setup java"
10896
uses: actions/setup-java@v4
10997
if: steps.spec_diff.outputs.spec_diff == 'true'
@@ -150,8 +138,14 @@ jobs:
150138
if: ${{ env.CREATE_PR == 'true' && steps.spec_diff.outputs.spec_diff == 'true'}}
151139
env:
152140
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
141+
BRANCH: ${{ steps.branch.outputs.branch }}
153142
run: |
154-
gh pr create --base main --head ${{ steps.branch.outputs.branch }} --title "feat: [DevOps] Update $CHOICE Specification" --body "
143+
if gh pr list --head $BRANCH --json number -q '.[].number' | grep -q .; then
144+
echo "An open PR already exists for this branch. Skipping PR creation."
145+
exit 0
146+
fi
147+
148+
gh pr create --base main --head $BRANCH --title "feat: [DevOps] Update $CHOICE Specification" --body "
155149
## Context
156150
157151
Update $CHOICE specification file based on $REF.
@@ -173,9 +167,9 @@ jobs:
173167
- name: "Print Summary"
174168
if: ${{ always() }}
175169
run: |
176-
echo "Branch creation: ${{ steps.branch.outcome }}"
177170
echo "File download outcome: ${{ steps.download.outcome }}"
178171
echo "Spec file contained changes: ${{ steps.spec_diff.outputs.spec_diff }}"
179172
echo "Client generation outcome: ${{ steps.generate.outcome }}"
180173
echo "Client compilation outcome: ${{ steps.compile.output.compilation_result }}"
181174
echo "Client test outcome: ${{ steps.compile.output.test_result }}"
175+
echo "Branch creation: ${{ steps.push.outcome }}"

0 commit comments

Comments
 (0)