-
Notifications
You must be signed in to change notification settings - Fork 20
162 lines (143 loc) · 5.87 KB
/
update.yaml
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Updates SDK based on api-definitions
on:
workflow_dispatch:
inputs:
trigger-reason:
description: |
The comment that will be posted to the PR if any changes are added.
Used to provide context about the source of the update.
required: false
jobs:
generate-sdk:
runs-on: ubuntu-latest
steps:
- name: Checkout api-definitions repo
uses: actions/checkout@v4
with:
path: 'api-definitions'
repository: 'Rebilly/api-definitions'
- name: Checkout PHP SDK repo
uses: actions/checkout@v4
with:
path: 'sdk'
fetch-depth: 0
- name: Keep changesets
working-directory: ./sdk
run: |
mkdir ../existing-changesets
git checkout automations/update-sdk-from-api-definitions || true
ls -lAh .changeset
cp .changeset/* ../existing-changesets/
git checkout main || true
cp ../existing-changesets/* .changeset/
- name: Checkout generator repo
uses: actions/checkout@v4
with:
token: '${{ secrets.MACHINE_USER_PAT }}'
path: 'generator'
repository: 'Rebilly/rebilly'
sparse-checkout: |
backend/php-sdk-generator/remove-fqcns.php
backend/php-sdk-generator/remove-unused-models.php
sparse-checkout-cone-mode: true
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, intl, curl, json
tools: composer:v2
- name: Install api-definitions dependencies
working-directory: ./api-definitions
run: npm install
- name: Build api-definitions
working-directory: ./api-definitions
run: npx redocly bundle all@latest -o all.yaml
- name: Login to GitHub Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.MACHINE_USER_PAT }}
- name: Build SDK
run: |
mkdir /tmp/sdk
docker run --rm \
-u $(id -u ${USER}):$(id -g ${USER}) \
-v "/tmp/sdk:/out" \
-v "$(pwd)/api-definitions/catalog:/api-definitions" \
ghcr.io/rebilly/regenerator:latest generate \
-g rebilly-php \
-D /out/openapi.json \
-o /out \
-C '{"rootNameSpace": "Rebilly.Sdk", "customOperationGroupMapping": "/shared/custom-resource-names.json"}' \
"/api-definitions/all.yaml"
ls -lAh /tmp/ /tmp/sdk/
- name: Bundle SDK
run: |
rm -rf ./sdk/{src,composer.json,.php-cs-fixer.php,psalm.xml} && \
cp -r /tmp/sdk/{src,composer.json,.php-cs-fixer.php,psalm.xml} ./sdk/
cd ./sdk && node ./scripts/update-sdk-version.js
- name: Get composer cache directory
working-directory: /tmp/sdk
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Cache npm dependencies
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- name: Install composer dependencies
working-directory: ./sdk
run: composer install --prefer-dist
- name: CS fix SDK
working-directory: ./sdk
run: |
composer cs-fix
rm .php-cs-fixer.cache # Remove cache for the second run
composer cs-fix # Run twice to ensure all large files are fixed (required due to a bug in the php-cs-fixer, remove once resolved)
- name: Add changeset
id: changeset
if: github.event.inputs.trigger-reason != ''
working-directory: ./sdk
run: |
git add .
git status
if [[ `git status --porcelain` ]]; then
npm ci
export CHANGESET_ID=$(node ./scripts/add-changeset.js patch "${{ github.event.inputs.trigger-reason }}")
echo "Added a patch changeset '${CHANGESET_ID}': '${{ github.event.inputs.trigger-reason }}'"
echo "id=${CHANGESET_ID}" >> $GITHUB_OUTPUT
fi
- name: Create PR
id: cpr
uses: peter-evans/create-pull-request@v5
with:
# Path of the checked-out repo where we placed the generated resources
path: 'sdk'
token: ${{ secrets.MACHINE_USER_PAT }}
title: 'chore: update SDK from api-definitions'
commit-message: update SDK from api-definitions
branch: automations/update-sdk-from-api-definitions
base: main
# Delete the branch when closing PRs or merging
delete-branch: true
body: This PR is automatically generated and updates SDK based on a change in the API definitions
- name: Comment trigger reason
uses: marocchino/sticky-pull-request-comment@v2
if: |
(steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated') &&
github.event.inputs.trigger-reason != ''
with:
GITHUB_TOKEN: ${{ secrets.MACHINE_USER_PAT }}
append: true
number: ${{ steps.cpr.outputs.pull-request-number }}
message: |
- ${{ github.event.inputs.trigger-reason }} [edit changeset](https://github.com/Rebilly/rebilly-php/edit/automations/update-sdk-from-api-definitions/.changeset/${{ steps.changeset.outputs.id }}.md?pr=%2FRebilly%2Frebilly-php%2Fpull%2F${{ steps.cpr.outputs.pull-request-number }})