-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
163 lines (127 loc) · 4.5 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Slack analyzer
author: Benjamin Wuethrich
description: Analyze a Slack workspace over time
branding:
icon: list
color: orange
inputs:
name:
description: Name used in file headings
required: true
slack-bot-token:
description: Slack API bot token with users:read scope
required: true
slack-user-token:
description: Slack API user token with search:read scope
required: true
telegram-to:
description: Telegram channel ID
required: false
telegram-token:
description: Telegram authorization token
required: false
runs:
using: composite
steps:
- name: Update tenures via Slack API
shell: bash
env:
BOT_TOKEN: ${{ inputs.slack-bot-token }}
USER_TOKEN: ${{ inputs.slack-user-token }}
run: |
if [[ -r data/corrections.csv ]]; then
echo "Validating corrections file..." >&2
'${{ github.action_path }}/scripts/corrtool' check \
data/corrections.csv
fi
git config --global user.name 'github-actions'
git config --global user.email \
'41898282+github-actions[bot]@users.noreply.github.com'
echo "::group::Run slacktenure script"
'${{ github.action_path }}/scripts/slacktenure' '${{ inputs.name }}'
echo "::endgroup::"
files=(README.md tenuresduration.md)
if [[ -n $(git status --porcelain -- "${files[@]}") ]]; then
git add "${files[@]}"
git commit --message="Update README stats table and durations"
git push
fi
if [[ -z $(git status --porcelain) ]]; then
echo "No new tenure data found" >&2
exit 0
fi
git add data/tenures.tsv diffs *.md
git commit --message="Update tenures"
git push
echo "Building diff message..." >&2
shopt -s globstar
diffs=(diffs/**/*.diff)
diff=${diffs[-1]}
ref=${{ github.ref }}
ref=${ref##*/}
baseurl="https://github.com/${{ github.repository }}/blob/$ref"
links="[Diff]($baseurl/$diff)"
links+=" • [All tenures]($baseurl/tenures.md)"
links+=" • [Current tenures]($baseurl/tenurescurrent.md)"
links+=" • [By duration]($baseurl/tenuresduration.md)"
printf -v msg '%s\n' "$links" '' '```diff' "$(< "$diff")" '```'
escapedmsg=$(jq --raw-input --slurp '.' <<< "$msg")
printf '%s\n' "escapedmsg=$escapedmsg" 'continue=true' >> "$GITHUB_ENV"
- name: Update boxplot
shell: bash
run: |
echo "::group::Install gnuplot"
sudo apt-get --quiet update
sudo apt-get --quiet install gnuplot-nox
echo "::endgroup::"
echo "Updating boxplot..." >&2
source '${{ github.action_path }}/scripts/slacktenure'
prettyprintduration < data/tenures.tsv \
| cut --fields=6 \
| gnuplot '${{ github.action_path }}/scripts/durationboxplot.gpi'
if [[ -z $(git status --porcelain) ]]; then
echo "Boxplot hasn't changed" >&2
exit 0
fi
git add boxplot.svg
git commit --message="Update boxplot"
git push
- name: Update graph
if: env.continue
shell: bash
run: |
'${{ github.action_path }}/scripts/generateturnover' \
data/tenures.tsv > data/turnover.tsv
if [[ -z $(git status --porcelain) ]]; then
echo "Turnover data hasn't changed, not recreating graph" >&2
exit 0
fi
for type in svg png; do
gnuplot -c '${{ github.action_path }}/scripts/turnover.gpi' "$type"
done
git add data/turnover.tsv turnover.svg
git commit --message="Update graph"
git push
echo "graphpath=turnover.png" >> "$GITHUB_ENV"
- name: Send Telegram message for change
if: >-
env.escapedmsg != ''
&& inputs.telegram-to != ''
&& inputs.telegram-token != ''
uses: appleboy/[email protected]
with:
to: ${{ inputs.telegram-to }}
token: ${{ inputs.telegram-token }}
format: markdown
message: ${{ fromJSON(env.escapedmsg) }}
- name: Send Telegram message for graph
if: >-
env.graphpath != ''
&& inputs.telegram-to != ''
&& inputs.telegram-token != ''
uses: appleboy/[email protected]
with:
to: ${{ inputs.telegram-to }}
token: ${{ inputs.telegram-token }}
photo: ${{ env.graphpath }}
message: ' '