Skip to content

Commit fd75ae5

Browse files
authored
Merge pull request #25 from weaverryan/github-auto-release
GitHub auto release
2 parents ea9f139 + cbe535d commit fd75ae5

File tree

12 files changed

+587
-5
lines changed

12 files changed

+587
-5
lines changed

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GITHUB_API_TOKEN=

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/tests/_cache
44
/var/
55
/docs.phar
6+
/.env

bin/create_release

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__.'/../vendor/autoload.php';
5+
6+
use SymfonyDocsBuilder\Phar\Compiler;
7+
use SymfonyDocsBuilder\Release\Exception\ReleaseFailed;
8+
use SymfonyDocsBuilder\Release\GithubApiHttpClientFactory;
9+
use SymfonyDocsBuilder\Release\Releaser;
10+
11+
error_reporting(-1);
12+
ini_set('display_errors', 1);
13+
14+
try {
15+
$releaser = new Releaser((new GithubApiHttpClientFactory())->createHttpClient(), new Compiler());
16+
17+
if ($argc === 1) {
18+
throw new RuntimeException('Not enough arguments. usage: "./bin/release tag [release_name [release_description]]"');
19+
}
20+
21+
array_shift($argv);
22+
23+
$releaser->createRelease(...$argv);
24+
} catch (Exception $e) {
25+
if ($e instanceof ReleaseFailed) {
26+
echo $e->toString();
27+
} else {
28+
echo 'Failed to create a new release: ['.get_class($e).'] '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine()."\n";
29+
}
30+
31+
exit(1);
32+
}

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
"symfony/dom-crawler": "^4.1",
2020
"symfony/css-selector": "^4.1",
2121
"symfony/console": "^4.1",
22-
"twig/twig": "^2.7.3"
22+
"twig/twig": "^2.7.3",
23+
"symfony/http-client": "^4.3"
2324
},
2425
"require-dev": {
2526
"gajus/dindent": "^2.0",
2627
"symfony/phpunit-bridge": "^4.1",
27-
"symfony/process": "^4.2"
28+
"symfony/process": "^4.2",
29+
"symfony/dotenv": "^4.3"
2830
}
2931
}

composer.lock

Lines changed: 225 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Input\InputOption;
88
use SymfonyDocsBuilder\Command\BuildDocsCommand;
99
use SymfonyDocsBuilder\Command\CheckUrlsCommand;
10+
use SymfonyDocsBuilder\Command\GithubReleaseCommand;
1011

1112
class Application
1213
{
@@ -41,6 +42,7 @@ public function run(InputInterface $input): int
4142
);
4243
$this->application->getDefinition()->addOption($inputOption);
4344
$this->application->add(new BuildDocsCommand($this->buildContext));
45+
$this->application->add(new GithubReleaseCommand());
4446

4547
return $this->application->run($input);
4648
}

src/Phar/Compiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function compile($pharFile = 'docs.phar')
5959
$finder->files()
6060
->ignoreVCS(true)
6161
->name('*.php')
62-
->notName('Compiler.php')
62+
->exclude(['Release', 'Phar'])
6363
->in(__DIR__.'/..')
6464
;
6565
foreach ($finder as $file) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SymfonyDocsBuilder\Release\Exception;
4+
5+
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
6+
7+
class DeleteReleaseFailed extends ReleaseFailed
8+
{
9+
private $originException;
10+
11+
public function __construct(ReleaseFailed $originException, HttpExceptionInterface $previous)
12+
{
13+
$this->originException = $originException;
14+
15+
parent::__construct('Error while deleting release.', 0, $previous);
16+
}
17+
18+
public function toString(): string
19+
{
20+
return sprintf(
21+
"%s\n\nOriginal exception was: [%s]\n\t\"%s\"\n\tat %s:%s\n",
22+
parent::toString(),
23+
get_class($this->originException),
24+
$this->originException->getMessage(),
25+
$this->originException->getFile(),
26+
$this->originException->getLine()
27+
);
28+
}
29+
}

0 commit comments

Comments
 (0)