-
Notifications
You must be signed in to change notification settings - Fork 6
166 lines (139 loc) · 5.74 KB
/
generate-php.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
163
164
165
166
name: Generate PHP SDK
on:
repository_dispatch:
types: [generate-php]
jobs:
generate-php-sdk:
runs-on: ubuntu-latest
env:
GIT_REPO_ID: fattureincloud-php-sdk
GIT_USER_ID: fattureincloud
steps:
- id: checkout
name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}
- id: checkout-php
name: Checkout PHP repo
env:
GIT_REPO_PATH: '${{ env.GIT_USER_ID }}/${{ env.GIT_REPO_ID }}'
uses: actions/checkout@v4
with:
path: ./generated/php
ref: master
repository: ${{ env.GIT_REPO_PATH }}
token: ${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}
- id: init-git
name: Init GIT
run: |
git config --global user.email "info@fattureincloud.it"
git config --global user.name "fattureincloud-bot"
- id: setup-node
name: Setup Node.js
uses: actions/setup-node@v4
- id: setup-java
name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '11'
- id: setup-php
name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
- id: setup-composer
name: Setup Composer
run: |
php -v
wget -O composer-setup.php https://getcomposer.org/installer
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- id: setup-libraries
name: Install libraries
run: |
npm install -g yarn
yarn global add @apidevtools/swagger-cli @openapitools/openapi-generator-cli standard-version
sudo add-apt-repository ppa:rmescandon/yq -y
sudo apt update
sudo apt install yq -y
cd ./scripts/
yarn
cd ../generated/php/scripts
yarn
- id: bump-php-sdk-version
name: Bump PHP SDK
env:
OPENAPI_VERSION: ${{ github.event.client_payload.version }}
run: |
echo "openapi_version=$OPENAPI_VERSION"
BUMP_TYPE=$(node ./scripts/sdk-version-checker.js ./generated/php/sdk-version.yaml $OPENAPI_VERSION)
cd ./generated/php
if [ "$BUMP_TYPE" == "patch" ];then
echo 'Bumping the SDK patch version...'
standard-version --skip.tag --skip.changelog --skip.commit --release-as patch
elif [ "$BUMP_TYPE" == "openapi" ];then
echo 'Using the openapi version...'
standard-version --skip.tag --skip.changelog --skip.commit --release-as $OPENAPI_VERSION
else
echo "Something bad happened - impossible to bump PHP SDK version. value=$BUMP_TYPE"
fi
SDK_VERSION=$(yq e '.info.version' ./sdk-version.yaml)
echo "sdk_version=$SDK_VERSION" >> $GITHUB_ENV
echo "openapi_version=$OPENAPI_VERSION" >> $GITHUB_ENV
- id: move-custom-files-to-backup
name: Move custom files to backup
run: |
mkdir -p ./backup/php/lib/Filter
mkdir -p ./backup/php/lib/OAuth2
mv ./generated/php/lib/Filter ./backup/php/lib/
mv ./generated/php/lib/OAuth2 ./backup/php/lib/
- id: delete-old-files
name: Delete old files
run: |
rm -rf ./generated/php/lib
rm -rf ./generated/php/docs
- id: generate-php-sdk
name: Generate PHP SDK
env:
PACKAGE_NAME: "\"FattureInCloud PHP SDK\""
INVOKER_PACKAGE: FattureInCloud
AUTHOR_NAME: "Fatture in Cloud API Team"
URL: "\"https://www.fattureincloud.it\""
COMPOSER_PACKAGE_NAME: "\"fattureincloud/fattureincloud-php-sdk\""
LICENSE: "MIT"
DEVELOPER_ORGANIZATION: "\"Fatture in Cloud API Team\""
run: |
SDK_VERSION=${{ env.sdk_version }}
echo "${{ env.sdk_version }}"
RELEASE_NOTE="\"bumping version to $SDK_VERSION\""
USER_AGENT="$INVOKER_PACKAGE/${{ env.sdk_version }}/PHP-SDK"
openapi-generator-cli generate -i ./openapi.yaml -g php -o ./generated/php/ -t ./templates/openapi-generator/php --package-name=${PACKAGE_NAME} --invoker-package=${INVOKER_PACKAGE} --git-repo-id=${GIT_REPO_ID} --git-user-id=${GIT_USER_ID} --release-note=${RELEASE_NOTE} --http-user-agent=${USER_AGENT} --additional-properties=composerPackageName=${COMPOSER_PACKAGE_NAME},artifactUrl=${URL},licenseName=${LICENSE},developerOrganization=${DEVELOPER_ORGANIZATION},developerOrganizationUrl=${URL}
node ./scripts/postprocess-php.js clean './generated/php/lib/' './generated/php/test/'
- id: move-custom-files-to-repo
name: Move custom files to repo
run: |
mv ./backup/php/lib/Filter ./generated/php/lib/Filter
mv ./backup/php/lib/OAuth2 ./generated/php/lib/OAuth2
- id: generate-additional-files
name: Generate Additional files
run: |
node ./scripts/generate-scopes.js php
- id: lint-code
name: Lint Code Base
run: |
cd ./generated/php/
composer install
./vendor/bin/php-cs-fixer fix ./ --allow-risky=yes
- id: create-pr
name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
path: ./generated/php
branch: "devel-${{ env.sdk_version }}"
token: "${{ secrets.FATTUREINCLOUD_BOT_TOKEN }}"
delete-branch: true
base: master
commit-message: "chore: bumping version to ${{ env.sdk_version }}"
title: "Updating SDK to ${{ env.sdk_version }}"
body: "New SDK verson ${{ env.sdk_version }} generated by Github Action from OpenAPI Spec ${{ env.openapi_version }}"