Skip to content

Commit

Permalink
Add Automated API Update Workflow
Browse files Browse the repository at this point in the history
Signed-off-by: saimedhi <[email protected]>
  • Loading branch information
saimedhi committed Jul 10, 2024
1 parent e458c51 commit 7b445ae
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/update_api.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
4 changes: 2 additions & 2 deletions util/ClientEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions util/NamespaceEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7b445ae

Please sign in to comment.