Skip to content

Commit a52934c

Browse files
authored
Merge pull request #2 from mike-sheppard/master
Add git username, git commit link & simplify message
2 parents 23d1c9d + cdbf416 commit a52934c

File tree

5 files changed

+46
-31
lines changed

5 files changed

+46
-31
lines changed

README.md

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# trellis-slack-webhook-notify-during-deploy
1+
# Trellis Slack Webhook Depolyment Notifications
22

33
[![GitHub tag](https://img.shields.io/github/tag/ItinerisLtd/trellis-slack-webhook-notify-during-deploy.svg)](https://github.com/ItinerisLtd/trellis-slack-webhook-notify-during-deploy/tags)
44
[![license](https://img.shields.io/github/license/ItinerisLtd/trellis-slack-webhook-notify-during-deploy.svg)](https://github.com/ItinerisLtd/trellis-slack-webhook-notify-during-deploy/blob/master/LICENSE)
55

66

7-
Sends a deployment complete message to a Slack channel when [Trellis](https://github.com/roots/trellis) deploys [Bedrock](https://github.com/roots/bedrock).
7+
Sends an initial deployment started and a deployment successful message to a Slack channel when [Trellis](https://github.com/roots/trellis) deploys [Bedrock](https://github.com/roots/bedrock).
88

99
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1010
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -38,33 +38,47 @@ Sends a deployment complete message to a Slack channel when [Trellis](https://gi
3838

3939
## Installation
4040

41-
Add this role to `requirements.yml`:
41+
Add this role to `requirements.yml` or `galaxy.yml` in newer versions of Trellis:
4242
```yaml
43-
# requirements.yml
44-
- src: https://github.com/ItinerisLtd/trellis-slack-webhook-notify-during-deploy
45-
version: 0.1.0 # Check for latest version!
43+
# requirements.yml / galaxy.yml
44+
- name: slack-notify
45+
src: https://github.com/ItinerisLtd/trellis-slack-webhook-notify-during-deploy
46+
version: 0.3.0 # Check for latest version!
4647
```
4748
4849
Run the command:
4950
```bash
5051
➜ ansible-galaxy install -r requirements.yml --force
5152
```
5253

54+
With newer versions of Trellis, run:
55+
```bash
56+
➜ ansible-galaxy install -r galaxy.yml --force
57+
```
58+
59+
5360
## Role Variables
5461

55-
Add this role to the [`deploy_after` hook](https://roots.io/trellis/docs/deploys/#hooks):
62+
Add these roles`deploy_before` & `deploy_finalize_after` to the deploy [hooks](https://roots.io/trellis/docs/deploys/#hooks):
5663
```yaml
57-
# group_vars/all/deploy-hooks.yml
58-
# Learn more on https://roots.io/trellis/docs/deploys/#hooks
59-
deploy_after:
60-
- "{{ playbook_dir }}/vendor/roles/trellis-slack-webhook-notify-during-deploy/tasks/main.yml"
64+
# roles/deploy/defaults/main.yml
65+
deploy_before:
66+
- "{{ playbook_dir }}/vendor/roles/slack-notify/tasks/deploy_start.yml"
67+
68+
...
69+
70+
deploy_finalize_after:
71+
- "{{ playbook_dir }}/roles/deploy/hooks/finalize-after.yml"
72+
- "{{ playbook_dir }}/vendor/roles/slack-notify/tasks/deploy_success.yml"
6173
```
6274
63-
Add your Webhook token (end of the Webhook URL) and channel into `group_vars/all/main.yml`
75+
Add your Webhook token (end of the Webhook URL), channel and projects github repo into `group_vars/all/main.yml`
6476

6577
```yaml
78+
# group_vars/all/main.yml
6679
slack_webhook_token: XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX
6780
slack_webhook_channel: '#development-alerts'
81+
slack_git_repo_url: "https://github.com/username/repo-name"
6882
```
6983

7084
## Usage

deployment-screenshot.png

9.61 KB
Loading

tasks/deploy_start.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Send initial deployment notification to Slack
3+
slack:
4+
token: "{{ slack_webhook_token }}"
5+
channel: slack_webhook_channel
6+
attachments:
7+
- text: "*{{ lookup('pipe', 'git config user.name') }}* has started deploying {{ site }} to *<https://{{ project.site_hosts | map(attribute='canonical') | first }}|{{ env }}>*"
8+
color: warning
9+
when: slack_webhook_token is defined and slack_webhook_token != ""
10+
delegate_to: localhost

tasks/deploy_success.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Send successful deployment notification to Slack
3+
slack:
4+
token: "{{ slack_webhook_token }}"
5+
channel: slack_webhook_channel
6+
attachments:
7+
- text: "*{{ lookup('pipe', 'git config user.name') }}* successfully deployed {{ site }} to *<https://{{ project.site_hosts | map(attribute='canonical') | first }}|{{ env }}>* [<{{ slack_git_repo_url }}/commit/{{ git_clone.after }}|deployed commit>]"
8+
color: good
9+
when: slack_webhook_token is defined and slack_webhook_token != ""
10+
delegate_to: localhost

tasks/main.yml

-19
This file was deleted.

0 commit comments

Comments
 (0)