-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
101 lines (80 loc) · 2.8 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: docs-message-action
description: Comment build log and release link
inputs:
github-token:
required: true
project-link:
required: false
runs:
using: composite
steps:
- name: 'Download inputs'
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{ github.event.workflow_run.id }}
github_token: ${{ inputs.github-token }}
name: inputs
path: ./inputs
- name: 'Download build log'
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{ github.event.workflow_run.id }}
github_token: ${{ inputs.github-token }}
name: build-log-html
- name: Prepare message
run: |
ICON_OK=':white_check_mark:'
ICON_WARN='⚠️'
ICON_ERROR=':x:'
PROJECT_LINK=${{ inputs.project-link }}
REVISION=$(cat ./inputs/revision)
BUILD_LOG="./build-html.log"
MESSAGE=""
if [ "${{ github.event.workflow_run.conclusion }}" == "success" ]; then
MESSAGE+="\nRevision built successfully"
if [ -n "$PROJECT_LINK" ]; then
MESSAGE+="\nRevision preview [link]($PROJECT_LINK?revision=${REVISION})"
fi
CARD_ICON=$ICON_OK
else
MESSAGE+="\nRevision build failed"
CARD_ICON=$ICON_ERROR
fi
CARD="### $CARD_ICON Documentation build"
CARD+="$MESSAGE\n"
function log_section {
PICK="$(grep "^$3" "$2" | sort | uniq || echo "")"
if [[ -n $PICK ]]; then
MARK=$4
LOG_COUNT=$(grep --count "" <<<"$PICK")
PICK=$(head -n 15 <<<"$PICK")
TAB=$(echo "##### $1 ($LOG_COUNT) $PICK")
if [[ $LOG_COUNT -gt 15 ]]; then
TRIM_COUNT=$(($LOG_COUNT - 15))
TAB+="\n\nLog was truncated. ($TRIM_COUNT records)"
fi
TAB=${TAB//$3/"\n $MARK"}
echo "$TAB\n"
fi
}
ERROR_SEC=$(log_section Errors "$BUILD_LOG" "ERR" "$ICON_ERROR")
WARN_SEC=$(log_section Warnings "$BUILD_LOG" "WARN" "$ICON_WARN")
if [[ -n "$ERROR_SEC" || -n "$WARN_SEC" ]]; then
CARD+="\n#### Build logs\n$ERROR_SEC\n$WARN_SEC\n"
fi
echo -e "$CARD" >> card.txt
shell: bash
- name: 'Comment to PR'
uses: actions/github-script@v6
if: github.event.workflow_run
with:
script: |
const {readFileSync} = require('fs');
const issue_number = readFileSync('./inputs/pr-number', 'utf-8')
const body = readFileSync('./card.txt', 'utf-8')
github.rest.issues.createComment({
issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
})