Skip to content

Commit 6922cdf

Browse files
committed
Client docs workflow
1 parent bdeddeb commit 6922cdf

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

.github/workflows/client-docs.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@ name: Update phplist-api-client OpenAPI
33
on:
44
push:
55
branches:
6-
- main
6+
- '**'
77
pull_request:
88

99
jobs:
1010
generate-openapi:
1111
runs-on: ubuntu-22.04
12+
outputs:
13+
source_branch: ${{ steps.branch.outputs.source_branch }}
1214
steps:
15+
- name: Determine source branch
16+
id: branch
17+
run: |
18+
if [ "${{ github.event_name }}" = "pull_request" ]; then
19+
echo "source_branch=${{ github.head_ref }}" >> "$GITHUB_OUTPUT"
20+
else
21+
echo "source_branch=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
22+
fi
23+
1324
- name: Checkout Source Repository
1425
uses: actions/checkout@v3
1526

@@ -42,6 +53,8 @@ jobs:
4253
update-phplist-api-client:
4354
runs-on: ubuntu-22.04
4455
needs: generate-openapi
56+
env:
57+
TARGET_BRANCH: ${{ needs.generate-openapi.outputs.source_branch }}
4558
steps:
4659
- name: Checkout phplist-api-client Repository
4760
uses: actions/checkout@v3
@@ -50,6 +63,17 @@ jobs:
5063
token: ${{ secrets.PUSH_API_CLIENT }}
5164
fetch-depth: 0
5265

66+
- name: Prepare target branch
67+
run: |
68+
git fetch origin
69+
70+
if git ls-remote --exit-code --heads origin "$TARGET_BRANCH" >/dev/null 2>&1; then
71+
git checkout "$TARGET_BRANCH"
72+
git pull --rebase origin "$TARGET_BRANCH"
73+
else
74+
git checkout -b "$TARGET_BRANCH"
75+
fi
76+
5377
- name: Download Generated OpenAPI JSON
5478
uses: actions/download-artifact@v4
5579
with:
@@ -63,13 +87,13 @@ jobs:
6387
if [ -f openapi.json ]; then
6488
diff openapi.json new-openapi/latest-restapi.json > openapi-diff.txt || true
6589
if [ -s openapi-diff.txt ]; then
66-
echo "diff=true" >> $GITHUB_OUTPUT
90+
echo "diff=true" >> "$GITHUB_OUTPUT"
6791
else
68-
echo "diff=false" >> $GITHUB_OUTPUT
92+
echo "diff=false" >> "$GITHUB_OUTPUT"
6993
fi
7094
else
7195
echo "No previous openapi.json, will add."
72-
echo "diff=true" >> $GITHUB_OUTPUT
96+
echo "diff=true" >> "$GITHUB_OUTPUT"
7397
fi
7498
7599
- name: Update and Commit OpenAPI File
@@ -79,8 +103,8 @@ jobs:
79103
git config user.name "github-actions"
80104
git config user.email "github-actions@phplist-api-client.workflow"
81105
git add openapi.json
82-
git commit -m "Update openapi.json from REST API workflow `date`"
83-
git push
106+
git commit -m "Update openapi.json from REST API workflow $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
107+
git push origin HEAD:"$TARGET_BRANCH"
84108
85109
- name: Skip Commit if No Changes
86110
if: steps.diff.outputs.diff == 'false'

0 commit comments

Comments
 (0)