Skip to content

Commit

Permalink
Merge pull request #8 from toko-bifrost/release/v3
Browse files Browse the repository at this point in the history
Release/v3
  • Loading branch information
aldwyn-acn authored May 18, 2020
2 parents 95df913 + 2beafe1 commit b73a29e
Show file tree
Hide file tree
Showing 22 changed files with 516 additions and 236 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: MS Teams Deploy Card

on: [push, pull_request]
on: [push]

jobs:
build:
Expand All @@ -9,10 +9,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Notify dedicated teams channel
uses: ./
- uses: ./
with:
github-token: ${{ github.token }}
webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
environment: Development
timezone: Australia/Sydney
deploy-title: Github Actions CI
card-layout-start: cozy
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.DS_Store
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@

A comprehensive notification card in Microsoft Teams for your deployments.

![](screenshot.png)
### Layouts

#### Complete

![](screenshots/layout-complete.png)

#### Cozy

![](screenshots/layout-cozy.png)

#### Compact

![](screenshots/layout-compact.png)

### Usage

Expand All @@ -15,7 +27,7 @@ A comprehensive notification card in Microsoft Teams for your deployments.
```yaml
name: MS Teams Deploy Card

on: [push, pull_request]
on: [push]

jobs:
build:
Expand All @@ -24,22 +36,26 @@ jobs:
steps:
- uses: actions/checkout@v2
# this is the new step
- name: Notify dedicated teams channel
uses: toko-bifrost/ms-teams-deploy-card@master # or "./" if in a local set-up
- uses: toko-bifrost/ms-teams-deploy-card@master # or "./" if in a local set-up
with:
github-token: ${{ github.token }}
webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
```
3. Tweak the following configurations
- `github-token` - (required), this can be set to the following:
- `${{ github.token }}`
- `${{ secrets.GITHUB_TOKEN }}`
- a manually added secret with more Github API permissions, e.g. `${{ secrets.<custom secret here> }}`
- `webhook-uri` - (required), the value of `MS_TEAMS_WEBHOOK_URI`
- `deploy-title` - (optional, defaults to `Github Actions CI`),
- `allowed-file-len` - (optional, defaults to `7`), allowed number of changed files to display
- `timezone` - (optional, defaults to `UTC`), a [valid database timezone name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), e.g. "Australia/Sydney"
### Configurations
| Name | Required | Default | Description |
| ------------------- | -------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `github-token` | `true` | None | This can be set to the following:<br/>- `${{ github.token }}`<br/>- `${{ secrets.GITHUB_TOKEN }}`<br/>- `${{ secrets.CUSTOM_TOKEN }}` |
| `webhook-uri` | `true` | None | The value of `MS_TEAMS_WEBHOOK_URI` |
| `environment` | `false` | None | Name of the environment, e.g. `development`, `production` (won't be included in the card if none) |
| `timezone` | `false` | `UTC` | A [valid database timezone name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), e.g. `Australia/Sydney` |
| `card-layout-start` | `false` | `complete` | Card layout on **_start_** (i.e. `complete`, `cozy`, `compact`) |
| `card-layout-exit` | `false` | `compact` | Card layout on **_exit_** (i.e. `complete`, `cozy`, `compact`) |
| `show-on-start` | `false` | `true` | Show an MS Teams card upon **_starting_** this Github Actions job |
| `show-on-exit` | `false` | `true` | Show an MS Teams card upon **_exiting_** this Github Actions job |
| `include-files` | `false` | `true` | Include the list of files when `layout` is set to `complete` |
| `allowed-file-len` | `false` | `7` | Allowed number of changed files to display, when `include-files` is set to `true` |

### Local Set-up

Expand Down
37 changes: 29 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,40 @@ inputs:
github-token:
description: Github token
required: true
deploy-title:
description: Deployment title
environment:
description: Name of the environment (won't be included in the card if none)
required: false
default: Github Actions CI
default: null
timezone:
description: Timezone for notification
required: false
default: UTC
card-layout-start:
description: Card layout on start (i.e. "complete", "cozy", "compact")
required: false
default: complete
card-layout-exit:
description: Card layout on end (i.e. "complete", "cozy", "compact")
required: false
default: compact
show-on-start:
description: Show the MS Teams card upon starting this Github Actions job
required: false
default: true
show-on-exit:
description: Show the MS Teams card upon exiting this Github Actions job
required: false
default: true
include-files:
description: Only for complete layout; Set false to exclude list of files
required: false
default: true
allowed-file-len:
description: Allowed number of files to display
required: false
default: 7
timezone:
description: Timezone for notification timezone
required: false
default: UTC

runs:
using: node12
main: dist/index.js
main: dist/main/index.js
post: dist/post/index.js
1 change: 0 additions & 1 deletion dist/index.js

This file was deleted.

1 change: 1 addition & 0 deletions dist/main/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/post/index.js

Large diffs are not rendered by default.

146 changes: 0 additions & 146 deletions index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"typescript": "^3.7.5"
},
"scripts": {
"ncc": "ncc build index.ts -m"
"ncc": "ncc build src/index.ts -m -o dist/main && ncc build src/post.ts -m -o dist/post"
}
}
Binary file removed screenshot.png
Binary file not shown.
Binary file added screenshots/layout-compact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/layout-complete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/layout-cozy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const CONCLUSION_THEMES: any = {
neutral: "5DB1D1",
success: "90C978",
cancelled: "D99294",
timed_out: "FF756D",
failure: "C23B23",
};
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { setFailed } from "@actions/core";
import { formatAndNotify } from "./utils";

try {
formatAndNotify("start");
} catch (error) {
setFailed(error.message);
}
37 changes: 37 additions & 0 deletions src/layouts/compact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Octokit } from "@octokit/rest";
import { WebhookBody } from "../models";
import { getInput } from "@actions/core";
import { CONCLUSION_THEMES } from "../constants";

export function formatCompactLayout(
commit: Octokit.Response<Octokit.ReposGetCommitResponse>,
status: string,
elapsedSeconds?: number
) {
const author = commit.data.author;
const repoUrl = `https://github.com/${process.env.GITHUB_REPOSITORY}`;
const shortSha = process.env.GITHUB_SHA?.substr(0, 7);
const runLink = `${repoUrl}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const webhookBody = new WebhookBody();

// Set status and elapsedSeconds
let labels = `\`${status.toUpperCase()}\``;
if (elapsedSeconds) {
labels = `\`${status.toUpperCase()} [${elapsedSeconds}s]\``;
}

// Set environment name
const environment = getInput("environment");
if (environment) {
labels += ` \`ENV:${environment.toUpperCase()}\``;
}

// Set themeColor
webhookBody.themeColor = CONCLUSION_THEMES[status] || "957DAD";

webhookBody.text =
`${labels} &nbsp; CI [#${process.env.GITHUB_RUN_NUMBER}](${runLink}) ` +
`(commit [${shortSha}](${commit.data.html_url})) on [${process.env.GITHUB_REPOSITORY}](${repoUrl}) ` +
`by [@${author.login}](${author.html_url})`;
return webhookBody;
}
Loading

0 comments on commit b73a29e

Please sign in to comment.