-
Notifications
You must be signed in to change notification settings - Fork 14
131 lines (116 loc) · 4.1 KB
/
Copy pathfront-docs.yml
File metadata and controls
131 lines (116 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Update phplist-web-frontend OpenAPI
permissions:
contents: write # Required to push to web-frontend repo
actions: read # Required to download artifacts
on:
push:
branches:
- dev
- main
pull_request:
branches:
- main
jobs:
generate-openapi:
runs-on: ubuntu-22.04
outputs:
source_branch: ${{ steps.branch.outputs.source_branch }}
steps:
- name: Determine source branch
env:
EVENT_NAME: ${{ github.event_name }}
HEAD_REF: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
id: branch
run: |
if [ "$EVENT_NAME" = "pull_request" ]; then
echo "source_branch=$HEAD_REF" >> "$GITHUB_OUTPUT"
else
echo "source_branch=$REF_NAME" >> "$GITHUB_OUTPUT"
fi
- name: Checkout Source Repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup PHP with Composer and Extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: mbstring, dom, fileinfo, mysql
- name: Cache Composer Dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: composer install --no-interaction --prefer-dist
- name: Generate OpenAPI Specification JSON
run: vendor/bin/openapi -o docs/latest-restapi.json --format json src
- name: Upload OpenAPI Artifact
uses: actions/upload-artifact@v4
with:
name: openapi-json
path: docs/latest-restapi.json
update-web-frontend:
runs-on: ubuntu-22.04
needs: generate-openapi
env:
TARGET_BRANCH: ${{ needs.generate-openapi.outputs.source_branch }}
steps:
- name: Checkout phpList-web-frontend Repository
uses: actions/checkout@v3
with:
repository: phpList/web-frontend
token: ${{ secrets.PUSH_WEB_FRONTEND }}
fetch-depth: 0
persist-credentials: false
- name: Prepare target branch
run: |
git fetch origin
if git ls-remote --exit-code --heads origin "$TARGET_BRANCH" >/dev/null 2>&1; then
git checkout "$TARGET_BRANCH"
git pull --rebase origin "$TARGET_BRANCH"
else
git checkout -b "$TARGET_BRANCH"
fi
- name: Download Generated OpenAPI JSON
uses: actions/download-artifact@v4
with:
name: openapi-json
path: ./new-openapi
- name: Compare and Check for Differences
id: diff
run: |
# Compare the openapi files if old exists, else always deploy
if [ -f openapi.json ]; then
diff openapi.json new-openapi/latest-restapi.json > openapi-diff.txt || true
if [ -s openapi-diff.txt ]; then
echo "diff=true" >> "$GITHUB_OUTPUT"
else
echo "diff=false" >> "$GITHUB_OUTPUT"
fi
else
echo "No previous openapi.json, will add."
echo "diff=true" >> "$GITHUB_OUTPUT"
fi
- name: Update and Commit OpenAPI File
if: steps.diff.outputs.diff == 'true'
run: |
set -euo pipefail
cp new-openapi/latest-restapi.json openapi.json
git config user.name "github-actions"
git config user.email "github-actions@web-frontend.workflow"
git add openapi.json
if git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Update openapi.json from web frontend workflow $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
git fetch origin "$TARGET_BRANCH"
git rebase "origin/$TARGET_BRANCH"
git push origin HEAD:"$TARGET_BRANCH"
- name: Skip Commit if No Changes
if: steps.diff.outputs.diff == 'false'
run: echo "No changes to openapi.json, skipping commit."