-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (70 loc) · 2.7 KB
/
backend-update.yml
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
name: Backend Update Workflow
on:
workflow_dispatch:
repository_dispatch:
types: [backend-update]
jobs:
update-client:
runs-on: ubuntu-latest
steps:
- name: Determine Branch and SHA for Update
id: set_branch_and_sha
run: |
echo "branch=$(echo ${{ github.event.client_payload.ref }} | awk -F'/' '{print $NF}' || 'develop')" >> $GITHUB_ENV
echo "BACKEND_SHA=$(echo ${{ github.event.client_payload.sha }} || 'MANUAL_RUN')" >> $GITHUB_ENV
- name: Checkout Client Repository
uses: actions/checkout@v2
with:
ref: ${{ env.branch }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install Dependencies
run: npm install
- name: Run Update Script
run: |
if [[ ${{ env.branch }} == 'main' ]]; then
npm run update-swagger:main
if ! cmp --silent ./swagger-main.json ./swagger.json; then
mv ./swagger-main.json ./swagger.json
echo "Files differ, running npm run gen"
echo "NEEDS_GEN=true" >> $GITHUB_ENV
else
echo "Files are identical, no need to run npm run gen"
echo "NEEDS_GEN=false" >> $GITHUB_ENV
fi
elif [[ ${{ env.branch }} == 'develop' ]]; then
npm run update-swagger:dev
if ! cmp --silent ./swagger-develop.json ./swagger.json; then
mv ./swagger-develop.json ./swagger.json
echo "Files differ, running npm run gen"
echo "NEEDS_GEN=true" >> $GITHUB_ENV
else
echo "Files are identical, no need to run npm run gen"
echo "NEEDS_GEN=false" >> $GITHUB_ENV
fi
fi
- name: Generate Client Code
if: env.NEEDS_GEN == 'true'
run: npm run genbuild
- name: Configure Git
if: env.NEEDS_GEN == 'true'
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Push Changes to New Branch
if: env.NEEDS_GEN == 'true'
run: |
git checkout -b Update/${{ env.branch }}-${{ env.BACKEND_SHA }}
git add .
git commit -m "Update from backend ${{env.BACKEND_SHA}}" --author="GitHub Actions Bot <[email protected]>"
git push origin Update/${{ env.branch }}-${{ env.BACKEND_SHA }}
- name: Create Pull Request
uses: repo-sync/pull-request@v2
if: env.NEEDS_GEN == 'true'
with:
pr_title: "Update from Backend"
pr_body: "Automated PR to update client after backend changes."
source_branch: "Update/${{ env.branch }}-${{ env.BACKEND_SHA }}"
destination_branch: ${{ env.branch }}