Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions contrib/ms-teams-workflows.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php
/*
## Installing

Microsoft is retiring the legacy "Incoming Webhook" connector. New
integrations must use the **Workflows** app (Power Automate). This
recipe targets the Workflows "Post to a channel when a webhook request
is received" template.

Setup:
1. Open MS Teams
2. Navigate to Teams section
3. Select existing or create new team
4. Select existing or create new channel
5. Click the three dots on the channel, choose "Workflows"
6. Pick the template **Post to a channel when a webhook request is received**
7. Follow the wizard, then copy the generated HTTPS POST URL
8. Setup deploy.php
Add in header:
```php
require 'contrib/ms-teams-workflows.php';
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
```
Add in content:
```php
before('deploy', 'teams-workflows:notify');
after('deploy:success', 'teams-workflows:notify:success');
after('deploy:failed', 'teams-workflows:notify:failure');
```
9.) Sip your coffee

## Configuration

- `teams_workflows_webhook` – workflow HTTPS POST URL, **required**
```
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
```
- `teams_workflows_title` – the title of application, default `{{application}}`
- `teams_workflows_text` – notification message template
```
set('teams_workflows_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
```
- `teams_workflows_success_text` – success template, default:
```
set('teams_workflows_success_text', 'Deploy to *{{where}}* successful');
```
- `teams_workflows_failure_text` – failure template, default:
```
set('teams_workflows_failure_text', 'Deploy to *{{where}}* failed');
```
- `teams_workflows_failure_continue` – if `true`, errors talking to the
workflow endpoint are downgraded to warnings instead of aborting the
deploy. Default `false`.

## Usage

If you want to notify only about beginning of deployment add this line only:

```php
before('deploy', 'teams-workflows:notify');
```

If you want to notify about successful end of deployment add this too:

```php
after('deploy:success', 'teams-workflows:notify:success');
```

If you want to notify about failed deployment add this too:

```php
after('deploy:failed', 'teams-workflows:notify:failure');
```
*/

namespace Deployer;

use Deployer\Utility\Httpie;

// Title of project
set('teams_workflows_title', function () {
return get('application', 'Project');
});

// Allow Continue on Failure
set('teams_workflows_failure_continue', false);

// Deploy message
set('teams_workflows_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
set('teams_workflows_success_text', 'Deploy to *{{where}}* successful');
set('teams_workflows_failure_text', 'Deploy to *{{where}}* failed');

desc('Notifies Teams (Workflows)');
task('teams-workflows:notify', function () {
if (!get('teams_workflows_webhook', false)) {
warning('No MS Teams Workflows webhook configured');
return;
}

try {
Httpie::post(get('teams_workflows_webhook'))->jsonBody([
'text' => get('teams_workflows_text'),
])->send();
} catch (\Exception $e) {
if (get('teams_workflows_failure_continue', false)) {
warning('Error sending Teams Workflows Notification: ' . $e->getMessage());
} else {
throw $e;
}
}
})
->once()
->hidden();

desc('Notifies Teams (Workflows) about deploy finish');
task('teams-workflows:notify:success', function () {
if (!get('teams_workflows_webhook', false)) {
warning('No MS Teams Workflows webhook configured');
return;
}

try {
Httpie::post(get('teams_workflows_webhook'))->jsonBody([
'text' => get('teams_workflows_success_text'),
])->send();
} catch (\Exception $e) {
if (get('teams_workflows_failure_continue', false)) {
warning('Error sending Teams Workflows Notification: ' . $e->getMessage());
} else {
throw $e;
}
}
})
->once()
->hidden();

desc('Notifies Teams (Workflows) about deploy failure');
task('teams-workflows:notify:failure', function () {
if (!get('teams_workflows_webhook', false)) {
warning('No MS Teams Workflows webhook configured');
return;
}

try {
Httpie::post(get('teams_workflows_webhook'))->jsonBody([
'text' => get('teams_workflows_failure_text'),
])->send();
} catch (\Exception $e) {
if (get('teams_workflows_failure_continue', false)) {
warning('Error sending Teams Workflows Notification: ' . $e->getMessage());
} else {
throw $e;
}
}
})
->once()
->hidden();
1 change: 1 addition & 0 deletions docs/contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Ispmanager Recipe](/docs/contrib/ispmanager.md)
* [Mattermost Recipe](/docs/contrib/mattermost.md)
* [Ms-teams Recipe](/docs/contrib/ms-teams.md)
* [Ms-teams-workflows Recipe](/docs/contrib/ms-teams-workflows.md)
* [Newrelic Recipe](/docs/contrib/newrelic.md)
* [Npm Recipe](/docs/contrib/npm.md)
* [Ntfy Recipe](/docs/contrib/ntfy.md)
Expand Down
154 changes: 154 additions & 0 deletions docs/contrib/ms-teams-workflows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<!-- DO NOT EDIT THIS FILE! -->
<!-- Instead edit contrib/ms-teams-workflows.php -->
<!-- Then run bin/docgen -->

# Ms-teams-workflows Recipe

```php
require 'contrib/ms-teams-workflows.php';
```

[Source](/contrib/ms-teams-workflows.php)



## Installing
Microsoft is retiring the legacy "Incoming Webhook" connector. New
integrations must use the **Workflows** app (Power Automate). This
recipe targets the Workflows "Post to a channel when a webhook request
is received" template.
Setup:
1. Open MS Teams
2. Navigate to Teams section
3. Select existing or create new team
4. Select existing or create new channel
5. Click the three dots on the channel, choose "Workflows"
6. Pick the template **Post to a channel when a webhook request is received**
7. Follow the wizard, then copy the generated HTTPS POST URL
8. Setup deploy.php
Add in header:
```php
require 'contrib/ms-teams-workflows.php';
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
```
Add in content:
```php
before('deploy', 'teams-workflows:notify');
after('deploy:success', 'teams-workflows:notify:success');
after('deploy:failed', 'teams-workflows:notify:failure');
```
9.) Sip your coffee
## Configuration
- `teams_workflows_webhook` – workflow HTTPS POST URL, **required**
```
set('teams_workflows_webhook', 'https://prod-XX.westeurope.logic.azure.com:443/workflows/...');
```
- `teams_workflows_title` – the title of application, default `{{application}}`
- `teams_workflows_text` – notification message template
```
set('teams_workflows_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
```
- `teams_workflows_success_text` – success template, default:
```
set('teams_workflows_success_text', 'Deploy to *{{where}}* successful');
```
- `teams_workflows_failure_text` – failure template, default:
```
set('teams_workflows_failure_text', 'Deploy to *{{where}}* failed');
```
- `teams_workflows_failure_continue` – if `true`, errors talking to the
workflow endpoint are downgraded to warnings instead of aborting the
deploy. Default `false`.
## Usage
If you want to notify only about beginning of deployment add this line only:
```php
before('deploy', 'teams-workflows:notify');
```
If you want to notify about successful end of deployment add this too:
```php
after('deploy:success', 'teams-workflows:notify:success');
```
If you want to notify about failed deployment add this too:
```php
after('deploy:failed', 'teams-workflows:notify:failure');
```


## Configuration
### teams_workflows_title
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L81)

Title of project

```php title="Default value"
return get('application', 'Project');
```


### teams_workflows_failure_continue
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L86)

Allow Continue on Failure

```php title="Default value"
false
```


### teams_workflows_text
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L89)

Deploy message

```php title="Default value"
'_{{user}}_ deploying `{{what}}` to *{{where}}*'
```


### teams_workflows_success_text
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L90)



```php title="Default value"
'Deploy to *{{where}}* successful'
```


### teams_workflows_failure_text
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L91)



```php title="Default value"
'Deploy to *{{where}}* failed'
```



## Tasks

### teams-workflows\:notify {#teams-workflows-notify}
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L94)

Notifies Teams (Workflows).




### teams-workflows\:notify\:success {#teams-workflows-notify-success}
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L116)

Notifies Teams (Workflows) about deploy finish.




### teams-workflows\:notify\:failure {#teams-workflows-notify-failure}
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams-workflows.php#L138)

Notifies Teams (Workflows) about deploy failure.