Compare commits

...

19 commits

Author SHA1 Message Date
Simon Vieille 843bda6bcc
add autotag to ci
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-06-01 00:09:54 +02:00
Simon Vieille c0b0973e04
add symfony/google-mailer
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-05-31 23:57:22 +02:00
Simon Vieille 7fe9f79d0e
remove dead code
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-03-13 09:00:45 +01:00
Simon Vieille 99d94eb54d
fix image name in the example
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-03-12 23:00:41 +01:00
Simon Vieille 961034266b
add exception trace on debug mode 2024-02-21 19:29:02 +01:00
Simon Vieille 3b643ccd64
add handle for RfcComplianceException
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-21 19:12:05 +01:00
Simon Vieille 0c342094b6
apply php linter 2024-02-21 19:09:00 +01:00
Simon Vieille f53ebebeb2
prettify documentation 2024-02-21 19:08:10 +01:00
Simon Vieille e1700c42b0
use php 8.3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-21 18:56:35 +01:00
Simon Vieille b371b48625 Merge branch 'feature/ci' into develop 2024-02-21 18:54:47 +01:00
Simon Vieille 2ecafbe733
ci: refactor steps
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-21 18:54:00 +01:00
Simon Vieille 82cd91641e
ci: use woodpeckerci/plugin-docker-buildx
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-21 18:48:22 +01:00
Simon Vieille be806166b4
ci: use woodpeckerci/plugin-docker-buildx
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-21 18:45:28 +01:00
Simon Vieille a291a03d89 add setting "debug"
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-19 14:33:21 +01:00
Simon Vieille 84a6fa518f add commit.prerelease (CI_COMMIT_PRERELEASE) 2024-02-19 14:33:21 +01:00
Simon Vieille 3fe8426262 Merge pull request 'chore: Configure Renovate' (#3) from renovate/configure into develop
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #3
2024-01-28 00:02:48 +01:00
Renovate Bot 667aa7a576 chore(deps): add renovate.json
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful
2024-01-27 23:01:21 +00:00
Simon Vieille 20daf68990
update readme
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-15 14:38:09 +01:00
Simon Vieille 04f4d8badc
update readme
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-15 13:59:04 +01:00
10 changed files with 67 additions and 115 deletions

View file

@ -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
View file

@ -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` |

View file

@ -1,4 +1,4 @@
FROM deblan/php:8.2 FROM deblan/php:8.3
WORKDIR /opt/app WORKDIR /opt/app

View file

@ -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).

View file

@ -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']);
} }

View file

@ -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
View file

@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

View file

@ -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

View file

@ -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
{ {

View file

@ -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;
}