Skip to content

Commit ead622e

Browse files
authored
Add debug logging; update readme (#5)
1 parent a8d6e16 commit ead622e

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
1-
# MS Team Github Actions integration
1+
# MS Team Github Actions integration
2+
3+
### Usage
4+
5+
1. Add `MS_TEAMS_WEBHOOK_URI` on your repository's configs on Settings > Secrets. It is the [webhook URI](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook) of the dedicated Microsoft Teams channel for notification.
6+
7+
2) Add a new `step` on your workflow code as last step of workflow job:
8+
9+
```yaml
10+
name: MS Teams Github Actions integration
11+
12+
on: [push]
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: opsless/ms-teams-github-actions@main
21+
if: always() # to let this step always run even if previous step failed
22+
with:
23+
github-token: ${{ github.token }}
24+
webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
25+
```
26+
27+
### Known Issues
28+
29+
- Always set this step with `if: always()` when there are steps between `actions/checkout@v2` and this step.
30+
31+
### Roadmap
32+
33+
- add error message if workflow failed
34+
- add files changed list
35+
- add workflow run duration
36+
37+
Feel free to create issue if you have an idea in mind

dist/main/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opsless/ms-teams-github-actions",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"description": "MS Teams Github Actions integration",
66
"main": "lib/main.js",

src/main.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,45 @@ function sleep(ms: number) {
1111
async function run() {
1212
try {
1313
const token = core.getInput("github-token");
14+
if (!token) {
15+
core.setFailed("'github-token' input can't be empty")
16+
return
17+
}
18+
1419
const webhookUri = core.getInput("webhook-uri")
20+
if (!webhookUri) {
21+
core.setFailed("'webhook-uri' input can't be empty")
22+
return
23+
}
1524
const ctx = github.context;
1625
const o = github.getOctokit(token);
1726

27+
core.debug(JSON.stringify(ctx))
28+
1829
await sleep(5000)
1930

2031
const jobList = await o.actions.listJobsForWorkflowRun({
2132
repo: ctx.repo.repo,
2233
owner: ctx.repo.owner,
2334
run_id: ctx.runId,
2435
});
25-
36+
2637
const jobs = jobList.data.jobs
38+
core.debug(JSON.stringify(jobs))
39+
2740
const job = jobs.find(job => job.name === ctx.job);
2841

2942
const stoppedStep = job?.steps.find(s => s.conclusion === "failure" || s.conclusion === "timed_out" || s.conclusion === "cancelled" || s.conclusion === "action_required")
3043
const lastStep = stoppedStep ? stoppedStep : job?.steps.reverse().find(s => s.status === "completed")
3144

32-
core.info(JSON.stringify(jobList))
33-
3445
const wr = await o.actions.getWorkflowRun({
3546
owner: ctx.repo.owner,
3647
repo: ctx.repo.repo,
3748
run_id: ctx.runId
3849
})
3950

51+
core.debug(JSON.stringify(wr.data))
52+
4053
const repository_url = ctx.payload.repository?.html_url
4154
const commit_author = ctx.actor
4255

@@ -59,7 +72,7 @@ async function run() {
5972
},
6073
{
6174
name: ctx.eventName === "pull_request" ? "Pull request" : "Branch",
62-
value: ctx.eventName === "pull_request" ? `[${ctx.payload.pull_request?.html_url}](${ctx.payload.pull_request?.html_url})` : `${ctx.payload.repository?.html_url}/tree/${ctx.ref}`
75+
value: ctx.eventName === "pull_request" ? `[${ctx.payload.pull_request?.html_url}](${ctx.payload.pull_request?.html_url})` : `[${ctx.payload.repository?.html_url}/tree/${ctx.ref}](${ctx.payload.repository?.html_url}/tree/${ctx.ref})`
6376
},
6477
{
6578
name: "Workflow run details",
@@ -71,6 +84,7 @@ async function run() {
7184
]
7285
}
7386
const response = await axios.default.post(webhookUri, webhookBody)
87+
core.debug(JSON.stringify(response.data))
7488
// TODO: check response status, if not succesful, mark workflow as failed
7589
} catch (error) {
7690
core.setFailed(error.message);

0 commit comments

Comments
 (0)