Skip to content

Commit 6cdd6e5

Browse files
committed
enhancement: Create the action to report the status of workflows of repositories
1 parent 61abc8b commit 6cdd6e5

File tree

456 files changed

+158868
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

456 files changed

+158868
-8
lines changed

Diff for: .github/workflows/dispatch_responder.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ on: [repository_dispatch]
44

55
jobs:
66
write-results:
7-
runs-on: ubuntu-latest
7+
runs-on: Ubuntu-20.04
88
steps:
99
- name: Checkout
1010
uses: actions/checkout@v2
11-
- name: LS
12-
run: ls
13-
- name: pwd
14-
run: pwd
1511
- name: Event Information
1612
run: |
1713
echo "Event '${{ github.event.action }}' received from '${{ github.event.client_payload.repository }}'"
18-
- name: Event Information
14+
- name: Store Event Info
1915
run: |
2016
mkdir -p repositories/${{ github.event.client_payload.repository }}
21-
echo "${{ github.event.client_payload.result }}" > repositories/${{ github.event.client_payload.repository }}/${{ github.event.client_payload.workflow }}
17+
printf "${{ github.event.client_payload.result }}" > repositories/${{ github.event.client_payload.repository }}/${{ github.event.client_payload.workflow }}
2218
- uses: stefanzweifel/git-auto-commit-action@v4
2319
with:
2420
commit_message: Update ${{ github.event.client_payload.repository }} with status ${{ github.event.client_payload.result }}

Diff for: .github/workflows/report_failures.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Report failures to Slack
2+
3+
on:
4+
schedule:
5+
# * is a special character in YAML so you have to quote this string
6+
- cron: "* * * * *"
7+
8+
jobs:
9+
write-results:
10+
runs-on: Ubuntu-20.04
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
- name: Report to Slack
15+
uses: ./
16+
with:
17+
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
18+
workflow-results: "success,failed"
19+
owner-name: dwardu89

Diff for: action.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Report workflows to slack"
2+
description: "Greet someone and record the time"
3+
inputs:
4+
slack-webhook:
5+
description: "The Slack webhook to post to."
6+
required: true
7+
workflow-results:
8+
description: "Comma separated workflow results to report to the Slack webhook."
9+
required: true
10+
default: "failed"
11+
owner-name:
12+
description: "The owner of the repositories to look at the workflow results."
13+
required: true
14+
default: "dwardu89"
15+
runs:
16+
using: "node12"
17+
main: "index.js"

Diff for: index.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const core = require('@actions/core');
2+
const github = require('@actions/github');
3+
const fs = require('fs');
4+
const { IncomingWebhook } = require('@slack/webhook');
5+
6+
const gitKeepFile = ".gitkeep"
7+
8+
const statusMapEmoji = {
9+
"success": ":white_check_mark:",
10+
"failed": ":fire:"
11+
}
12+
13+
try {
14+
const slackWebhookUrl = core.getInput('slack-webhook');
15+
const workflowResults = core.getInput('workflow-results');
16+
const ownerName = core.getInput('owner-name');
17+
18+
const statusesToReport = workflowResults.split(',');
19+
20+
const repositoryOwnerPath = "repositories/" + ownerName;
21+
const repositories = fs.readdirSync(repositoryOwnerPath);
22+
23+
let slackReport = "";
24+
25+
// Build a string to generate a report for slack.
26+
repositories.forEach(repository => {
27+
if (repository !== gitKeepFile) {
28+
const repositoryPath = repositoryOwnerPath + "/" + repository;
29+
const workflows = fs.readdirSync(repositoryPath);
30+
31+
const workflowMap = new Map();
32+
workflows.forEach(workflow => {
33+
const workflowStatus = fs.readFileSync(repositoryPath + "/" + workflow).toString();
34+
if (statusesToReport.includes(workflowStatus)) {
35+
slackReport += `${statusMapEmoji[workflowStatus]} \`${workflow}\` Status [${workflowStatus}]\n`;
36+
}
37+
});
38+
}
39+
});
40+
41+
const webhook = new IncomingWebhook(slackWebhookUrl);
42+
43+
(async () => {
44+
await webhook.send({
45+
text: slackReport,
46+
icon_emoji: ":fire:"
47+
});
48+
})();
49+
} catch (error) {
50+
core.setFailed(error.message);
51+
}

Diff for: node_modules/@actions/core/LICENSE.md

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/@actions/core/README.md

+147
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/@actions/core/lib/command.d.ts

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/@actions/core/lib/command.js

+79
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/@actions/core/lib/command.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)