From 7b445ae3cee8b9ded08983b9df586373f76da29f Mon Sep 17 00:00:00 2001 From: saimedhi Date: Wed, 10 Jul 2024 03:00:35 -0700 Subject: [PATCH] Add Automated API Update Workflow Signed-off-by: saimedhi --- .github/workflows/update_api.yml | 56 ++++++++++++++++++++++++++++++++ util/ClientEndpoint.php | 4 +-- util/NamespaceEndpoint.php | 4 +-- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/update_api.yml diff --git a/.github/workflows/update_api.yml b/.github/workflows/update_api.yml new file mode 100644 index 00000000..a12e22f9 --- /dev/null +++ b/.github/workflows/update_api.yml @@ -0,0 +1,56 @@ +name: Update API +on: + workflow_dispatch: + schedule: + - cron: "30 3 * * *" +jobs: + update-api: + if: ${{ github.repository == 'opensearch-project/opensearch-php' }} + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + - name: Config git to rebase + run: git config --global pull.rebase true + - name: Set up PHP 8.3 + uses: shivammathur/setup-php@v2 + with: + php-version: 8.3 + extensions: yaml, zip, curl + tools: composer:v2.7.2 + - name: Install dependencies + run: composer install --prefer-dist + - name: Generate API + run: php util/GenerateEndpoints.php + - name: Format generated code + run: composer run php-cs + - name: Get current date + id: date + run: echo "::set-output name=date::$(date +'%Y-%m-%d')" + - name: GitHub App token + id: github_app_token + uses: tibdex/github-app-token@v1.5.0 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + installation_id: 22958780 + - name: Create pull request + id: cpr + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ steps.github_app_token.outputs.token }} + commit-message: Updated opensearch-php to reflect the latest OpenSearch API spec (${{ steps.date.outputs.date }}) + title: Updated opensearch-php to reflect the latest OpenSearch API spec + body: | + Updated [opensearch-php](https://github.com/opensearch-project/opensearch-php) to reflect the latest [OpenSearch API spec](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml) + Date: ${{ steps.date.outputs.date }} + branch: automated-api-update + base: main + signoff: true + labels: | + autocut diff --git a/util/ClientEndpoint.php b/util/ClientEndpoint.php index 0eeffbbf..1acec505 100644 --- a/util/ClientEndpoint.php +++ b/util/ClientEndpoint.php @@ -94,12 +94,12 @@ public function renderClass(): string $endpoints = ''; foreach ($this->endpoints as $endpoint) { $endpointName = $this->getEndpointName($endpoint->name); - $proxyFilePath = 'util/endpointproxies/' . $this->name . '/' . $endpointName . 'Proxy.php'; + $proxyFilePath = __DIR__ . '/EndpointProxies/' . $this->name . '/' . $endpointName . 'Proxy.php'; if (!file_exists($proxyFilePath)) { $endpoints .= $this->renderEndpoint($endpoint); } } - $proxyFolder = 'util/endpointproxies/'; + $proxyFolder = __DIR__. '/EndpointProxies/'; if (is_dir($proxyFolder)) { $proxyFiles = glob($proxyFolder . '/*.php'); foreach ($proxyFiles as $file) { diff --git a/util/NamespaceEndpoint.php b/util/NamespaceEndpoint.php index 976f42e5..b8c7dfb4 100644 --- a/util/NamespaceEndpoint.php +++ b/util/NamespaceEndpoint.php @@ -69,13 +69,13 @@ public function renderClass(): string $endpoints = ''; foreach ($this->endpoints as $endpoint) { $endpointName = $this->getEndpointName($endpoint->name); - $proxyFilePath = 'util/endpointproxies/' . $this->name . '/' . $endpointName . 'Proxy.php'; + $proxyFilePath = __DIR__ . '/EndpointProxies/' . $this->name . '/' . $endpointName . 'Proxy.php'; if (!file_exists($proxyFilePath)) { $endpoints .= $this->renderEndpoint($endpoint); } } - $proxyFolder = 'util/endpointproxies/' . $this->name; + $proxyFolder = __DIR__ . '/EndpointProxies/' . $this->name; if (is_dir($proxyFolder)) { foreach (glob($proxyFolder . '/*Proxy.php') as $file) { $endpoints .= require $file;