forked from steveworley/lagoon-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from uselagoon/feature/branding
First "Official" PR merge for `uselagoon/lagoon-php-sdk`! * Update README and composer.json to reflect new package information. * Removing lock file since this is a library. * Don't ignore all hidden files and folders. * Add a github workflow file to run automated tests on github actions infrastructure using multiple versions of PHP. * Add lagoon source to composer dev requirements so we can develop and test against a real API. * Adding a pseudopackage in tests folder so we can keep dev scripts separate. * Add `api-*` scripts to the development package to assist in launching and testing the API containers. * Create a simple working test script for end-to-end library-to-API tests. * Add a section to the README about how to develop the package.
- Loading branch information
Showing
16 changed files
with
275 additions
and
3,141 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Lagoon PHP SDK | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php-versions: | ||
- '7.1' | ||
- '7.2' | ||
- '7.3' | ||
- '7.4' | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
|
||
- name: Validate composer.json and composer.lock | ||
run: composer validate | ||
|
||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-php- | ||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" | ||
# Docs: https://getcomposer.org/doc/articles/scripts.md | ||
|
||
# - name: Run test suite | ||
# run: composer run-script test | ||
|
||
- name: Start Lagoon API | ||
run: bin/api-start | ||
|
||
- name: Docker Containers | ||
run: docker-compose --file vendor/uselagoon/lagoon/docker-compose.yaml ps --all | ||
|
||
- name: Test Lagoon API | ||
run: bin/api-test | ||
|
||
- name: Test Lagoon PHP SDK | ||
run: | | ||
echo "Waiting for test data to populate..." | ||
sleep 4 | ||
bin/lagoon-php-sdk-test |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,49 @@ | ||
# Lagoon PHP SDK | ||
|
||
[![CircleCI](https://circleci.com/gh/steveworley/lagoon-php-sdk.svg?style=svg&circle-token=0b96bf2aab7e227d9a6b528fe5dff25d4de6e537)](https://circleci.com/gh/steveworley/lagoon-php-sdk) | ||
|
||
The *Lagoon SDK for PHP* makes it easy for developers to connect their applications to the Lagoon GraphQL service in PHP Code. | ||
|
||
## Getting started | ||
|
||
Require the package using compsoer. | ||
Require the package using [Composer](https://getcomposer.org/): | ||
|
||
``` | ||
composer require steveworley/lagoon-php-sdk | ||
composer require uselagoon/lagoon-php-sdk | ||
``` | ||
|
||
Define the `$endpoint` and `$token` to create a new client instance. | ||
|
||
## Quick Examples | ||
|
||
### Fetch all projects | ||
|
||
``` php | ||
See [`tests/lagoon-php-sdk-test`](tests/lagoon-php-sdk-test) for a working example. This script is [tested on GitHub](https://github.com/uselagoon/lagoon-php-sdk/actions). | ||
|
||
```php | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
use Lagoon\LagoonClient; | ||
|
||
$client = new LagoonClient($endpoint, $token); | ||
$customers = $client->customer()->all()->execute(); | ||
// The container exposes port 3000 on the host by default. | ||
$endpoint = "http://localhost:3000/graphql"; | ||
|
||
// The development container uses this token for everyone. | ||
$token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiYWRtaW4iLCJpc3MiOiJhcGktZGF0YS13YXRjaGVyLXB1c2hlciIsImF1ZCI6ImFwaS5kZXYiLCJzdWIiOiJhcGktZGF0YS13YXRjaGVyLXB1c2hlciJ9.GiSJpvNXF2Yj9IXVCsp7KrxVp8N2gcp7-6qpyNOakVw"; | ||
|
||
try { | ||
$client = new LagoonClient($endpoint, $token); | ||
$response = $client->project()->all()->execute(); | ||
|
||
if ($response->hasErrors()) { | ||
throw new \Exception("There were errors returned from the GraphQL API: " . implode(PHP_EOL, $response->errors())); | ||
} | ||
else { | ||
$projects = $response->all(); | ||
print "Projects Found: " . count($projects); | ||
} | ||
} catch (\Exception $e) { | ||
print "ERROR: " . $e->getMessage(); | ||
exit(1); | ||
} | ||
``` | ||
|
||
### Fetch all project names | ||
|
@@ -35,7 +54,7 @@ $customers = $client->customer()->all()->execute(); | |
use Lagoon\LagoonClient; | ||
|
||
$client = new LagoonClient($endpoint, $token); | ||
$customers = $client->project()->all()->fields(['name'])->execute(); | ||
$projects = $client->project()->all()->fields(['name'])->execute(); | ||
``` | ||
|
||
### Add a project | ||
|
@@ -47,12 +66,46 @@ use Lagoon\LagoonClient; | |
|
||
$client = new LagoonClient($endpoint, $token); | ||
$project = [ | ||
'name' => 'my-proejct', | ||
'customer' => 1, | ||
'openshift' => 1, | ||
'gitUrl' => '[email protected]:test/test.git' | ||
'productEnvironment' => 'master', | ||
'branches' => 'master', | ||
'name' => $name, | ||
'gitUrl' => $gitUrl, | ||
'openshift' => 2, | ||
'productionEnvironment' => 'master', | ||
'branches' => 'true', | ||
]; | ||
$customers = $client->project()->add($project)->execute(); | ||
$response = $client->project()->add($project)->execute(); | ||
``` | ||
|
||
## Developing this Package | ||
|
||
This package interacts with the Lagoon Container Hosting System's API. | ||
|
||
You need to have a running Lagoon API instance to develop and test against. | ||
|
||
This package includes the Lagoon codebase using the `require-dev` section of composer.json in the [`/tests`](./tests) folder. | ||
|
||
### Launch Lagoon API Instance. | ||
|
||
Run the following commands to download Lagoon source to the `vendor/uselagoon/lagoon` folder. | ||
|
||
# Composer install with --dev dependencies. (default behavior) | ||
composer install | ||
|
||
# Composer install without --dev dependencies. | ||
# Do this to build and release your codebase to production. | ||
composer install --no-dev | ||
|
||
# Run bin/api-* scripts to start and test the API containers. | ||
bin/api-start | ||
bin/api-test | ||
|
||
### Tests | ||
|
||
The `bin/api-test` script will launch the containers and wait until the API container is available at https://localhost:3000. | ||
|
||
The `api-start` script is simply a wrapper for the `make api-development` command inside `uselagoon/lagoon`. This is the same command used by Lagoon developers to work on the API, so a full development environment is available. | ||
|
||
## About this Package | ||
|
||
|
||
This project was originally developed by @steveworley et al in the repo https://github.com/steveworley/lagoon-php-sdk. | ||
It is currently being improved upon to be released as officially supported by the Lagoon Team. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,33 @@ | ||
{ | ||
"name": "steveworley/lagoon-php-sdk", | ||
"description": "Lagoon GraphQL SDK for PHP", | ||
"keywords": [], | ||
"name": "uselagon/lagoon-php-sdk", | ||
"description": "PHP Library for interacting the the Lagoon API.", | ||
"keywords": ["hosting", "lagoon", "devops", "sdk", "api"], | ||
"type": "library", | ||
"license": "Apache-2.0", | ||
"authors": [ | ||
{ | ||
"name": "Steve Worley", | ||
"email": "[email protected]" | ||
"name": "Lagoon PHP SDK Team", | ||
"homepage": "https://github.com/steveworley/lagoon-php-sdk/graphs/contributors" | ||
} | ||
], | ||
"repositories": [ | ||
{ | ||
"type": "path", | ||
"url": "tests" | ||
}, | ||
{ | ||
"type": "package", | ||
"package": { | ||
"name": "uselagoon/lagoon", | ||
"description": "This pseudo-repository exists to make it simple to install Lagoon from source at a specific version.", | ||
"type": "lagoon-platform", | ||
"version": "v1.13.5", | ||
"source": { | ||
"url": "https://github.com/amazeeio/lagoon.git", | ||
"type": "git", | ||
"reference": "v1.13.5" | ||
} | ||
} | ||
} | ||
], | ||
"require": { | ||
|
@@ -16,7 +36,11 @@ | |
}, | ||
"require-dev": { | ||
"couscous/couscous": "^1.7", | ||
"phpunit/phpunit": "^7.5" | ||
"phpunit/phpunit": "^7.5", | ||
"uselagoon/lagoon-php-sdk-testing": "@dev" | ||
}, | ||
"config": { | ||
"bin-dir": "bin" | ||
}, | ||
"scripts": { | ||
"test": "phpunit" | ||
|
Oops, something went wrong.