Skip to content

Commit

Permalink
Documentation update (#11)
Browse files Browse the repository at this point in the history
* Documentation update

* Correcting test and docs
  • Loading branch information
bbaga authored May 1, 2020
1 parent cc3ba7a commit b8768ec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
55 changes: 50 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
![](https://shepherd.dev/github/bbaga/buildkite-php/coverage.svg)
![](https://codecov.io/gh/bbaga/buildkite-php/branch/master/graph/badge.svg)

**Documentations is work in progress.**

## Installation
```shell script
composer require bbaga/buildkite-php
Expand All @@ -15,7 +13,8 @@ composer require bbaga/buildkite-php

* [Interacting with Buildkite's REST API](#interacting-with-buildkites-rest-api)
* [Example of traversing through resources](#example-of-traversing-through-resources)
* [Getting straight to the point](#getting-straight-to-the-point)
* [Accessing resources without traversing](#accessing-resources-without-traversing)
* [Creating a new pipeline](#Creating-a-new-pipeline)
* [Direct API calls](#direct-api-calls)
* [Organizations API](#organizations-api)
* [List the ](#list-the-organizations)
Expand Down Expand Up @@ -94,7 +93,7 @@ $emojis = $organizations[0]->getEmojis();
$agents = $organizations[0]->getAgents();
```

#### Getting straight to the point
#### Accessing resources without traversing

Fetching data for a specific build without traversing through the hierarchy.

Expand All @@ -120,6 +119,50 @@ $build = new Fluent\Build($api, $organization, ['number' => $buildNumber, 'pipel
$build->fetch()->getJobs();
```

#### Creating a new pipeline

```php
use bbaga\BuildkiteApi\Api\GuzzleClient;
use bbaga\BuildkiteApi\Api\Rest\Fluent;
use bbaga\BuildkiteApi\Api\RestApi;

$client = new GuzzleClient();
$api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN');

$organization = new Fluent\Organization($api, ['slug' => 'my-org']);
$pipeline = $organization->createPipeline(
[
'name' => 'my-pipeline',
'repository' => '[email protected]:some/repo.git',
'steps' => [
[
'type' => 'script',
'name' => 'upload artifact',
'command' => 'echo "Hello" > artifact.txt \
&& buildkite-agent artifact upload artifact.txt \
&& cat artifact.txt | buildkite-agent annotate --style "success" --context "junit"',
],
[
'type' => 'manual',
'name' => 'Needs to be unblocked',
'command' => 'echo "Unblocked!"',
],
]
]
);

/**
* Pipeline is ready, we can kick off the first build
*/
$buildSettings = [
'commit' => 'HEAD',
'branch' => 'master',
'message' => 'Testing all the things :rocket:',
];

$pipeline->createBuild($buildSettings);
```

### Direct API calls

### Organizations API
Expand Down Expand Up @@ -292,12 +335,13 @@ make test
```

### Integration testing
A Buildkite account is required for integration testing and the following environment variables must be set.
A Buildkite account and a running agent is required for integration testing and the following environment variables must be set.

* `BK_TEST_TOKEN`
* `BK_TEST_ORG`
* `BK_TEST_PREFIX`
* `GITHUB_REF`
* `GITHUB_REPOSITORY`

These can be set in the `phpunit.xml` by making a copy of `phpunit.xml.dist` and extending it with the following snippet
```xml
Expand All @@ -306,6 +350,7 @@ These can be set in the `phpunit.xml` by making a copy of `phpunit.xml.dist` and
<env name="BK_TEST_ORG" value="my-organization-slug"/>
<env name="BK_TEST_PREFIX" value="something-uniqe"/>
<env name="GITHUB_REF" value="refs/heads/master"/>
<env name="GITHUB_REPOSITORY" value="your-name/buildkite-php"/>
</php>
```

Expand Down
4 changes: 1 addition & 3 deletions tests/Integration/Api/Rest/Fluent/BuildRelatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ public function testBuildRelatedFunctions(): void
[
'type' => 'manual',
'name' => 'Needs to be unblocked',
'command' => 'echo "Hello" > artifact.txt \
&& buildkite-agent artifact upload artifact.txt \
&& cat artifact.txt | buildkite-agent annotate --style "success" --context "junit"',
'command' => 'echo "Unblocked"',
],
]
]
Expand Down

0 comments on commit b8768ec

Please sign in to comment.