generate-php #50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v3 | |
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@v3 | |
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@v3 | |
- id: setup-java | |
name: Setup Java | |
uses: actions/setup-java@v3 | |
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@v5 | |
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 }}" |