Skip to content

Commit 7f0a77d

Browse files
authored
Merge pull request #40 from opalsecurity/winnie/plat-190-fix-autogen-python-sdk-gha
[PLAT-190] Fix autogen python sdk gha
2 parents 370795a + cba8cd4 commit 7f0a77d

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

.github/workflows/autogen-remote-changes.yml

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
- name: Set up Node.js
2121
uses: actions/setup-node@v3
2222
with:
23-
node-version: '18'
23+
node-version: '18'
2424
- name: Install OpenAPI Generator CLI
25-
run: npm install @openapitools/openapi-generator-cli -g
25+
run: npm install @openapitools/openapi-generator-cli@2.31.1 -g
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
@@ -32,29 +32,12 @@ jobs:
3232
- name: Check for changes
3333
id: check_changes
3434
run: |
35-
if git diff --quiet; then
35+
git add -A
36+
if git diff --cached --quiet; then
3637
echo "changes=false" >> $GITHUB_ENV
3738
else
3839
echo "changes=true" >> $GITHUB_ENV
3940
fi
40-
- name: Set up Git
41-
if: env.changes == 'true'
42-
run: |
43-
git config user.name "github-actions[bot]"
44-
git config user.email "github-actions[bot]@users.noreply.github.com"
45-
- name: Commit changes
46-
if: env.changes == 'true'
47-
run: |
48-
BRANCH_NAME="auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')"
49-
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
50-
git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME
51-
git add .
52-
git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
53-
- name: Push changes
54-
if: env.changes == 'true'
55-
env:
56-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57-
run: git push --force --set-upstream origin $BRANCH_NAME
5841
- name: Install GitHub CLI
5942
if: env.changes == 'true'
6043
run: |
@@ -66,13 +49,32 @@ jobs:
6649
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6750
id: check_pr
6851
run: |
69-
PR_EXISTS=$(gh pr list --search "Auto-update SDK" --base main --state open --json number -q '.[0].number')
52+
PR_EXISTS=$(gh pr list --search "Auto-update SDK" --base main --state open --json number,headRefName -q '.[0].number')
7053
if [[ -n "$PR_EXISTS" ]]; then
71-
echo "pr_exists=true" >> $GITHUB_ENV
72-
echo "PR_NUMBER=$PR_EXISTS" >> $GITHUB_ENV
54+
echo "pr_exists=true" >> $GITHUB_ENV
55+
echo "PR_NUMBER=$PR_EXISTS" >> $GITHUB_ENV
56+
EXISTING_BRANCH=$(gh pr list --search "Auto-update SDK" --base main --state open --json number,headRefName -q '.[0].headRefName')
57+
echo "BRANCH_NAME=$EXISTING_BRANCH" >> $GITHUB_ENV
7358
else
74-
echo "pr_exists=false" >> $GITHUB_ENV
59+
echo "pr_exists=false" >> $GITHUB_ENV
60+
echo "BRANCH_NAME=auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')" >> $GITHUB_ENV
7561
fi
62+
- name: Set up Git
63+
if: env.changes == 'true'
64+
run: |
65+
git config user.name "github-actions[bot]"
66+
git config user.email "github-actions[bot]@users.noreply.github.com"
67+
- name: Commit changes
68+
if: env.changes == 'true'
69+
run: |
70+
git fetch origin || true
71+
git checkout -B $BRANCH_NAME origin/$BRANCH_NAME 2>/dev/null || git checkout -B $BRANCH_NAME
72+
git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
73+
- name: Push changes
74+
if: env.changes == 'true'
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
run: git push --force --set-upstream origin $BRANCH_NAME
7678
- name: Create a pull request
7779
if: env.changes == 'true' && env.pr_exists == 'false'
7880
env:
@@ -81,12 +83,9 @@ jobs:
8183
PR_TITLE="Auto-update SDK on $(date +'%Y-%m-%d')"
8284
PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK with the latest remote OpenAPI specification."
8385
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base main
84-
- name: Update existing pull request
86+
- name: Comment on existing pull request
8587
if: env.changes == 'true' && env.pr_exists == 'true'
8688
env:
8789
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8890
run: |
89-
echo "An existing pull request titled 'Auto-update SDK' is already open. Updating it with the latest changes."
90-
git push --set-upstream origin $BRANCH_NAME --force
9191
gh pr comment $PR_NUMBER --body "This pull request has been updated with the latest changes from the automated SDK update process on $(date +'%Y-%m-%d %H:%M:%S')."
92-

openapitools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
33
"spaces": 2,
44
"generator-cli": {
5-
"version": "7.10.0"
5+
"version": "7.19.0"
66
}
77
}

0 commit comments

Comments
 (0)