Compare commits
19 commits
Author | SHA1 | Date | |
---|---|---|---|
Simon Vieille | 843bda6bcc | ||
Simon Vieille | c0b0973e04 | ||
Simon Vieille | 7fe9f79d0e | ||
Simon Vieille | 99d94eb54d | ||
Simon Vieille | 961034266b | ||
Simon Vieille | 3b643ccd64 | ||
Simon Vieille | 0c342094b6 | ||
Simon Vieille | f53ebebeb2 | ||
Simon Vieille | e1700c42b0 | ||
Simon Vieille | b371b48625 | ||
Simon Vieille | 2ecafbe733 | ||
Simon Vieille | 82cd91641e | ||
Simon Vieille | be806166b4 | ||
Simon Vieille | a291a03d89 | ||
Simon Vieille | 84a6fa518f | ||
Simon Vieille | 3fe8426262 | ||
667aa7a576 | |||
Simon Vieille | 20daf68990 | ||
Simon Vieille | 04f4d8badc |
|
@ -1,63 +1,27 @@
|
||||||
steps:
|
steps:
|
||||||
dep:
|
"Test docker build":
|
||||||
image: deblan/php:8.2
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
commands:
|
|
||||||
- composer install
|
|
||||||
when:
|
|
||||||
event: [push]
|
|
||||||
|
|
||||||
build_push_latest_gitnet:
|
|
||||||
image: plugins/docker
|
|
||||||
secrets: [registry_user, registry_password]
|
|
||||||
settings:
|
settings:
|
||||||
registry: gitnet.fr
|
repo: gitnet.fr/deblan/woodpecker-email
|
||||||
repo: gitnet.fr/${CI_REPO}
|
dry-run: true
|
||||||
tags: latest
|
|
||||||
username:
|
|
||||||
from_secret: registry_user
|
|
||||||
password:
|
|
||||||
from_secret: registry_password
|
|
||||||
when:
|
|
||||||
branch: [master]
|
|
||||||
event: [push]
|
|
||||||
|
|
||||||
build_push_tag_gitnet:
|
"Docker build and push":
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [registry_user, registry_password]
|
|
||||||
settings:
|
settings:
|
||||||
registry: gitnet.fr
|
repo: gitnet.fr/deblan/woodpecker-email,deblan/woodpecker-email
|
||||||
repo: gitnet.fr/${CI_REPO}
|
auto_tag: true
|
||||||
tags: ${CI_COMMIT_TAG}
|
logins:
|
||||||
username:
|
- registry: https://gitnet.fr
|
||||||
from_secret: registry_user
|
username:
|
||||||
password:
|
from_secret: registry_user
|
||||||
from_secret: registry_password
|
password:
|
||||||
|
from_secret: registry_password
|
||||||
|
- registry: https://index.docker.io/v1/
|
||||||
|
username:
|
||||||
|
from_secret: registry_user
|
||||||
|
password:
|
||||||
|
from_secret: registry_docker_password
|
||||||
when:
|
when:
|
||||||
event: [tag]
|
- branch: [master]
|
||||||
|
event: [push]
|
||||||
build_push_latest_dhub:
|
- event: [tag]
|
||||||
image: plugins/docker
|
|
||||||
secrets: [registry_user, registry_docker_password]
|
|
||||||
settings:
|
|
||||||
repo: ${CI_REPO}
|
|
||||||
tags: latest
|
|
||||||
username:
|
|
||||||
from_secret: registry_user
|
|
||||||
password:
|
|
||||||
from_secret: registry_docker_password
|
|
||||||
when:
|
|
||||||
branch: [master]
|
|
||||||
event: [push]
|
|
||||||
|
|
||||||
build_push_tag_dhub:
|
|
||||||
image: plugins/docker
|
|
||||||
secrets: [registry_user, registry_docker_password]
|
|
||||||
settings:
|
|
||||||
repo: ${CI_REPO}
|
|
||||||
tags: ${CI_COMMIT_TAG}
|
|
||||||
username:
|
|
||||||
from_secret: registry_user
|
|
||||||
password:
|
|
||||||
from_secret: registry_docker_password
|
|
||||||
when:
|
|
||||||
event: [tag]
|
|
||||||
|
|
15
DOCS.md
15
DOCS.md
|
@ -12,25 +12,23 @@ url: https://gitnet.fr/deblan/woodpecker-email
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
| Settings Name | Required | Type | Description | Documentation |
|
| Settings Name | Required | Type | Description | Documentation |
|
||||||
| --- | --- | --- | --- | --- |
|
| --------------- | -------- | ------------------ | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
||||||
| dsn | yes | `string` | Mail transport configuration | [Documentation](https://symfony.com/doc/current/mailer.html#tls-peer-verification) |
|
| dsn | yes | `string` | Mail transport configuration | [Documentation](https://symfony.com/doc/current/mailer.html#tls-peer-verification) |
|
||||||
| from.address | yes | `string` | Email address of the sender | |
|
| from.address | yes | `string` | Email address of the sender | |
|
||||||
| from.name | no | `0string` | Name of the sender | |
|
| from.name | no | `string` | Name of the sender | |
|
||||||
| recipients | no | `string` or `list` | List of recipients to send this mail to (besides the commit author) | YAML list or comma separated list |
|
| recipients | no | `string` or `list` | List of recipients to send this mail to (besides the commit author) | YAML list or comma separated list |
|
||||||
| recipients_only | no | `boolean` | Exclude the committer | |
|
| recipients_only | no | `boolean` | Exclude the committer | |
|
||||||
| content.subject | no | `string` | Define the email subject template | |
|
| content.subject | no | `string` | Define the email subject template | |
|
||||||
| content.body | no | `string` | Define the email body template | |
|
| content.body | no | `string` | Define the email body template | |
|
||||||
| attachments | no | `string` or `list` | List of files to attach | YAML list or comma separated list |
|
| attachments | no | `string` or `list` | List of files to attach | YAML list or comma separated list |
|
||||||
|
| debug | no | `boolean` | Debug mode (email are sent!) | |
|
||||||
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
steps:
|
steps:
|
||||||
mail:
|
mail:
|
||||||
image: deblan/woodpecker-email-php
|
image: deblan/woodpecker-email
|
||||||
settings:
|
settings:
|
||||||
dsn: "smtp://username:password@mail.example.com:587?verify_peer=1"
|
dsn: "smtp://username:password@mail.example.com:587?verify_peer=1"
|
||||||
from:
|
from:
|
||||||
|
@ -51,14 +49,12 @@ steps:
|
||||||
- log/*
|
- log/*
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Evaluation and content
|
### Evaluation and content
|
||||||
|
|
||||||
See the [Twig documentation](https://twig.symfony.com/doc/3.x/).
|
See the [Twig documentation](https://twig.symfony.com/doc/3.x/).
|
||||||
|
|
||||||
|
|
||||||
| Variable | Value |
|
| Variable | Value |
|
||||||
| --- | --- |
|
| ----------------------------- | -------------------------------- |
|
||||||
| `workspace` | `CI_WORKSPACE` |
|
| `workspace` | `CI_WORKSPACE` |
|
||||||
| `repo.full_name` | `CI_REPO` |
|
| `repo.full_name` | `CI_REPO` |
|
||||||
| `repo.owner` | `CI_REPO_OWNER` |
|
| `repo.owner` | `CI_REPO_OWNER` |
|
||||||
|
@ -76,6 +72,7 @@ See the [Twig documentation](https://twig.symfony.com/doc/3.x/).
|
||||||
| `commit.author` | `CI_COMMIT_AUTHOR` |
|
| `commit.author` | `CI_COMMIT_AUTHOR` |
|
||||||
| `commit.author_email` | `CI_COMMIT_AUTHOR_EMAIL` |
|
| `commit.author_email` | `CI_COMMIT_AUTHOR_EMAIL` |
|
||||||
| `commit.author_avatar` | `CI_COMMIT_AUTHOR_AVATAR` |
|
| `commit.author_avatar` | `CI_COMMIT_AUTHOR_AVATAR` |
|
||||||
|
| `commit.prerelease` | `CI_COMMIT_PRERELEASE` |
|
||||||
| `prev_commit.sha` | `CI_PREV_COMMIT_SHA` |
|
| `prev_commit.sha` | `CI_PREV_COMMIT_SHA` |
|
||||||
| `prev_commit.ref` | `CI_PREV_COMMIT_REF` |
|
| `prev_commit.ref` | `CI_PREV_COMMIT_REF` |
|
||||||
| `prev_commit.branch` | `CI_PREV_COMMIT_BRANCH` |
|
| `prev_commit.branch` | `CI_PREV_COMMIT_BRANCH` |
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM deblan/php:8.2
|
FROM deblan/php:8.3
|
||||||
|
|
||||||
WORKDIR /opt/app
|
WORKDIR /opt/app
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# woodpecker-email-php
|
# woodpecker-email
|
||||||
|
|
||||||
Woodpecker plugin to send build status notifications via Email. For the usage information and a listing of the available options please take a look at [the docs](DOCS.md).
|
Woodpecker plugin to send build status notifications via Email. For the usage information and a listing of the available options please take a look at [the docs](DOCS.md).
|
||||||
|
|
33
bin/console
33
bin/console
|
@ -9,6 +9,7 @@ use Plugin\Loader\EnvVarLoader;
|
||||||
use Plugin\Pipeline\Evaluation;
|
use Plugin\Pipeline\Evaluation;
|
||||||
use Symfony\Component\Mailer\Exception\TransportException;
|
use Symfony\Component\Mailer\Exception\TransportException;
|
||||||
use Twig\Error\SyntaxError;
|
use Twig\Error\SyntaxError;
|
||||||
|
use Symfony\Component\Mime\Exception\RfcComplianceException;
|
||||||
|
|
||||||
$build = EnvVarLoader::buildArray([
|
$build = EnvVarLoader::buildArray([
|
||||||
'workspace' => 'CI_WORKSPACE',
|
'workspace' => 'CI_WORKSPACE',
|
||||||
|
@ -32,6 +33,7 @@ $build = EnvVarLoader::buildArray([
|
||||||
'author' => 'CI_COMMIT_AUTHOR',
|
'author' => 'CI_COMMIT_AUTHOR',
|
||||||
'author_email' => 'CI_COMMIT_AUTHOR_EMAIL',
|
'author_email' => 'CI_COMMIT_AUTHOR_EMAIL',
|
||||||
'author_avatar' => 'CI_COMMIT_AUTHOR_AVATAR',
|
'author_avatar' => 'CI_COMMIT_AUTHOR_AVATAR',
|
||||||
|
'prerelease' => 'CI_COMMIT_PRERELEASE',
|
||||||
],
|
],
|
||||||
'prev_commit' => [
|
'prev_commit' => [
|
||||||
'sha' => 'CI_PREV_COMMIT_SHA',
|
'sha' => 'CI_PREV_COMMIT_SHA',
|
||||||
|
@ -88,8 +90,10 @@ $config = EnvVarLoader::buildArray([
|
||||||
'attachments' => 'PLUGIN_ATTACHMENTS',
|
'attachments' => 'PLUGIN_ATTACHMENTS',
|
||||||
'evaluate' => 'PLUGIN_EVALUATE',
|
'evaluate' => 'PLUGIN_EVALUATE',
|
||||||
'content' => 'PLUGIN_CONTENT',
|
'content' => 'PLUGIN_CONTENT',
|
||||||
|
'is_debug' => 'PLUGIN_DEBUG',
|
||||||
], [
|
], [
|
||||||
'PLUGIN_RECIPIENTS_ONLY' => true,
|
'PLUGIN_RECIPIENTS_ONLY' => true,
|
||||||
|
'PLUGIN_DEBUG' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function writeln(...$values)
|
function writeln(...$values)
|
||||||
|
@ -99,16 +103,35 @@ function writeln(...$values)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleError($section, Exception $e)
|
function handleError($section, Exception $e, bool $debug)
|
||||||
{
|
{
|
||||||
writeln(
|
writeln(
|
||||||
sprintf('ERROR - %s', $section),
|
sprintf('ERROR - %s', $section),
|
||||||
$e->getMessage()
|
$e->getMessage()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($debug) {
|
||||||
|
writeln(
|
||||||
|
"",
|
||||||
|
"Trace",
|
||||||
|
"=====",
|
||||||
|
json_encode($e->getTrace(), JSON_PRETTY_PRINT),
|
||||||
|
"=====",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($config['is_debug']) {
|
||||||
|
writeln(
|
||||||
|
'Debug',
|
||||||
|
'=====',
|
||||||
|
json_encode(['config' => $config, 'environment' => $_SERVER], JSON_PRETTY_PRINT),
|
||||||
|
'=====',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$twig = (new TwigFactory())->create();
|
$twig = (new TwigFactory())->create();
|
||||||
$emailFactory = new EmailFactory($twig, $config, $build);
|
$emailFactory = new EmailFactory($twig, $config, $build);
|
||||||
$evaluation = new Evaluation($twig);
|
$evaluation = new Evaluation($twig);
|
||||||
|
@ -125,9 +148,11 @@ try {
|
||||||
writeln('Email sent!');
|
writeln('Email sent!');
|
||||||
}
|
}
|
||||||
} catch (SyntaxError $e) {
|
} catch (SyntaxError $e) {
|
||||||
handleError('Syntax error', $e);
|
handleError('Syntax error', $e, $config['is_debug']);
|
||||||
} catch (TransportException $e) {
|
} catch (TransportException $e) {
|
||||||
handleError('Transport error', $e);
|
handleError('Transport error', $e, $config['is_debug']);
|
||||||
|
} catch (RfcComplianceException $e) {
|
||||||
|
handleError('RFC compliance error', $e, $config['is_debug']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
handleError('Generic error', $e);
|
handleError('Generic error', $e, $config['is_debug']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"symfony/mailer": "^7.0",
|
"symfony/mailer": "^7.0",
|
||||||
"twig/twig": "^3.8"
|
"twig/twig": "^3.8",
|
||||||
|
"symfony/google-mailer": "^7.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
renovate.json
Normal file
3
renovate.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ class EmailFactory
|
||||||
|
|
||||||
public function createMailer(): Mailer
|
public function createMailer(): Mailer
|
||||||
{
|
{
|
||||||
return new Mailer(Transport::fromDsn($this->config['dsn']));
|
return new Mailer(Transport::fromDsn((string) $this->config['dsn']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createEmail(): Email
|
public function createEmail(): Email
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
namespace Plugin\Factory;
|
namespace Plugin\Factory;
|
||||||
|
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Twig\Loader\FilesystemLoader;
|
|
||||||
use Twig\Extension\StringLoaderExtension;
|
|
||||||
use Twig\Extension\DebugExtension;
|
use Twig\Extension\DebugExtension;
|
||||||
|
use Twig\Extension\StringLoaderExtension;
|
||||||
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
|
||||||
class TwigFactory
|
class TwigFactory
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Plugin\Helper;
|
|
||||||
|
|
||||||
function loadEnVars(array $map, array $defaults = [])
|
|
||||||
{
|
|
||||||
$container = [];
|
|
||||||
|
|
||||||
foreach ($map as $key => $value) {
|
|
||||||
if (is_array($value)) {
|
|
||||||
$container[$key] = loadEnVars($value);
|
|
||||||
} else {
|
|
||||||
$data = getenv($value);
|
|
||||||
|
|
||||||
if ($data === false) {
|
|
||||||
$data = $defaults[$value] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str_ends_with($key, '_at') && ctype_digit($data)) {
|
|
||||||
$date = new \DateTime();
|
|
||||||
$date->setTimestamp((int) $data);
|
|
||||||
$data = $date;
|
|
||||||
} elseif (str_starts_with($key, 'is_')) {
|
|
||||||
if (in_array(strtolower($data), ['1', 'true', 'yes'])) {
|
|
||||||
$data = true;
|
|
||||||
} elseif (in_array(strtolower($data), ['0', 'false', 'no'])) {
|
|
||||||
$data = false;
|
|
||||||
} else {
|
|
||||||
$data = $defaults[$value] ?? false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$container[$key] = $data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $container;
|
|
||||||
}
|
|
Loading…
Reference in a new issue