Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Nov 23, 2019
0 parents commit 8623b89
Show file tree
Hide file tree
Showing 18 changed files with 15,405 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: TS Lint Check

on:
push:
branches:
- master
paths:
- src/*
pull_request:
branches:
- master
paths:
- src/*

jobs:
lint:
name: Lint Check
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master

- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '10.x'

- name: Setup TS
run: npm install tslint typescript -g

- name: Lint check with tslint
run: tslint './src/*.ts'
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Prepare for release

on:
push:
tags:
- 'v*'

jobs:
release:
name: Build production
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1

- uses: actions/setup-node@v1
with:
node-version: '10.x'

- name: Create Release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: 'false'
prerelease: 'false'

- name: Rocket.Chat Notification
uses: RocketChat/Rocket.Chat.GitHub.Action.Notification@master
if: always()
with:
type: ${{ job.status }}
job_name: ':rocket: *Publish new release ${{ github.ref }}*'
channel: '#develop'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}
106 changes: 106 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Check notification

on: [pull_request, push]

jobs:
success:
name: Works properly
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master

- name: Rocket.Chat Notification
uses: ./
if: always()
with:
type: ${{ job.status }}
job_name: ':robot_face: *Success*'
mention: 'here'
mention_if: 'failure'
channel: '#develop'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}

success_no_mention:
name: Works properly without mention
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master

- name: Rocket.Chat Notification
uses: ./
if: always()
with:
type: ${{ job.status }}
job_name: ':robot_face: *Success no mention*'
channel: '#develop'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}

failure:
name: Works failed
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master

- name: Forced failure
run: exit 1

- name: Rocket.Chat Notification
uses: ./
if: failure()
with:
type: ${{ job.status }}
job_name: ':robot_face: *Failure*'
mention: 'here'
mention_if: 'failure'
channel: '#develop'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}

- name: Check if work properly
if: failure()
run: |
echo 'Rocket.Chat failure notification succeeded'
exit 0
cancel:
# You have to cancel this job
name: Works canceled
runs-on: ubuntu-18.04
needs: success
timeout-minutes: 1
steps:
- uses: actions/checkout@master

- name: Wait
run: sleep 70

- name: Rocket.Chat Notification
uses: ./
if: cancelled()
with:
type: ${{ job.status }}
job_name: ':robot_face: *Cancel*'
mention: 'here'
mention_if: 'always'
channel: '#develop'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}

- name: Check if work properly
if: cancelled()
run: |
echo 'Rocket.Chat cancelled notification succeeded'
exit 0
commit:
name: Include commit data
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master

- uses: ./
with:
type: ${{ job.status }}
job_name: ':robot_face: *Commit*'
channel: '#develop'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}
commit: 'true'
token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.node_repl_history
.config/
.npm/
node_modules/
package-lock.json
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 200,
"tabWidth": 4,
"useTabs": true,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2018 GitHub, Inc. and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Rocket.Chat.GitHub.Action.Notification

![](https://github.com/RocketChat/Rocket.Chat.GitHub.Action.Notification/workflows/TS%20Lint%20Check/badge.svg)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/RocketChat/Rocket.Chat.GitHub.Action.Notification?color=brightgreen)
![GitHub](https://img.shields.io/github/license/RocketChat/Rocket.Chat.GitHub.Action.Notification?color=brightgreen)

This is Rocket.Chat Notification for GitHub Actions.<br>
Generated from [actions/javascript-template](https://github.com/actions/javascript-template).

# Feature
- Notify the result of GitHub Actions
- Support three job status (reference: [job-context](https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#job-context))
- success
- failure
- cancelled
- Mention
- Notify message to channel members efficiently
- You can specify the condition to mention

# How to use
First of all, you need to set GitHub secrets for ROCKETCHAT_WEBHOOK that is Incoming Webhook URL.<br>
You can customize the following parameters:

|with parameter|required/optional|default|description|
|:--:|:--:|:--|:--|
|type|required|N/A|The result of GitHub Actions job<br>This parameter value must contain the following word:<br>- `success`<br>- `failure`<br>- `cancelled`<br>We recommend using ${{ job.status }}|
|job_name|required|N/A|Means rocket.chat notification title|
|url|required|N/A|Rocket.Chat Incoming Webhooks URL<br>Please specify this key or ROCKETCHAT_WEBHOOK environment variable<br>※ROCKETCHAT_WEBHOOK will be deprecated|
|mention|optional|N/A|Rocket.Chat message mention|
|mention_if|optional|N/A|The condition to mention<br>This parameter can contain the following word:<br>- `success`<br>- `failure`<br>- `cancelled`<br>- `always`|
|icon_emoji|optional|Use Rocket.Chat Incoming Webhook configuration|Rocket.Chat icon|
|username|optional|Use Rocket.Chat Incoming Webhook configuration|Rocket.Chat username|
|channel|optional|Use Rocket.Chat Incoming Webhook configuration|Rocket.Chat channel name|
|commit|optional|false|If true, Rocket.Chat notification includes the latest commit message and author.|
|token|case by case|N/A|This token is used to get commit data.<br>If commit parameter is true, this parameter is required.<br>${{ secrets.GITHUB_TOKEN }} is recommended.|

Please refer `action.yml` for more details.

## Examples

```..github/workflows/example1.yml
- name: Rocket.Chat Notification
uses: RocketChat/Rocket.Chat.GitHub.Action.Notification@master
if: always()
with:
type: ${{ job.status }}
job_name: '*Lint Check*'
mention: 'here'
mention_if: 'failure'
channel: '#random'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}
```

↓ Including the latest commit data

```..github/workflows/example2.yml
- name: Rocket.Chat Notification
uses: RocketChat/Rocket.Chat.GitHub.Action.Notification@master
if: always()
with:
type: ${{ job.status }}
job_name: '*Lint Check*'
mention: 'here'
mention_if: 'failure'
channel: '#random'
url: ${{ secrets.ROCKETCHAT_WEBHOOK }}
commit: true
token: ${{ secrets.GITHUB_TOKEN }}
```

# Rocket.Chat UI Example

<img src="./images/rocketchat.png" alt="Notification Preview" width="90%">

# Contribute
1. Fork this repository
2. Pull your repository in local machine
3. Update original repository
4. Checkout "master" branch based "remotes/origin/master" branch
5. Work on "master" branch
6. Push you changes to your repository
7. Create a new Pull Request

# LICENSE

[The MIT License (MIT)](https://github.com/RocketChat/Rocket.Chat.GitHub.Action.Notification/blob/master/LICENSE)
3 changes: 3 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('TODO - Add a test suite', () => {
it('TODO - Add a test', async () => {});
});
41 changes: 41 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'Rocket.Chat Notification'
description: 'Rocket.Chat Notification for GitHub Actions'
author: 'Rocket.Chat'
inputs:
type:
description: 'job status (success, failure or cancelled)'
required: true
job_name:
description: 'job name of workflow (format: markdown)'
required: true
mention:
description: 'rocket.chat mention'
required: false
mention_if:
description: 'the condition for mention'
required: false
username:
description: 'rocket.chat username'
required: false
icon_emoji:
description: 'rocket.chat icon emoji'
required: false
channel:
description: 'rocket.chat channel'
required: false
url:
description: 'rocket.chat incoming webhook url'
required: false
commit:
description: 'whether include commit data or not (true or false)'
required: false
default: 'false'
token:
description: 'need to get commit data'
required: false
runs:
using: 'node12'
main: 'dist/index.js'
branding:
icon: 'bell'
color: 'green'
Loading

0 comments on commit 8623b89

Please sign in to comment.