-
Notifications
You must be signed in to change notification settings - Fork 16
136 lines (102 loc) · 3.82 KB
/
hn.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
name: "fetch hackernews items"
defaults:
run:
working-directory: ./all/hackernews
push:
branches:
# - main
jobs:
cron:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# actions are not compatible with working-directory
#
# - uses: francois2metz/setup-steampipe@v1
# with:
# steampipe-version: 'latest'
# steampipe-plugins: |
# {
# "hackernews": {}
# }
#
# so install steampipe this way
- name: echo ~
run: echo ~
- name: ls ~
run: ls ~
- name: pwd
run: pwd
- name: ls
run: ls
- name: clock1
run: echo `date`
- name: clock2
run: echo `date` >> ./times.txt
- name: install steampipe
run: sudo /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/turbot/steampipe/main/install.sh)"
- name: install hackernews
run: steampipe plugin install hackernews
- name: install csv
run: steampipe plugin install csv
- name: install github
run: steampipe plugin install github
- name: install net
run: steampipe plugin install net
- name: configure csv
run: cp ./csv.spc ~/.steampipe/config/csv.spc
- name: check config
run: more ~/.steampipe/config/csv.spc
- name: capture hourly snapshot
run: STEAMPIPE_LOG=trace steampipe query "select * from hackernews_new where time > now() - interval '1 hour'" --output csv >> ./csv/hn_`date +%s`.csv
- name: combine files
run: |
cat hn_header.txt > hn.csv
for file in ./csv/hn_*.csv; do
tail -n +2 $file >> hn.csv
done
- name: create hn_items_all
run: |
steampipe query "create table hn_items_tmp as select * from csv.hn"
steampipe query "select count(*) from csv.hn"
steampipe query "create table hn_items_all as select distinct on (id) * from hn_items_tmp"
steampipe query "delete from hn_items_all where substring(time from 1 for 10) < to_char(now() - interval '31 day' , 'YYYY-MM-DD')"
steampipe query "update hn_items_all set score = 0::text where score = '<null>'"
steampipe query "update hn_items_all set descendants = 0::text where descendants = '<null>' or descendants = ''"
steampipe query "select count(*) from hn_items_all"
- name: create hn_scores_and_comments
run: steampipe query query.create_scores_and_comments
- name: check hn_scores_and_comments
run: steampipe query "select sum(descendants::bigint) as descendants from hn_scores_and_comments"
- name: create new_sc
run: steampipe query query.new_scores_and_comments
- name: check new_sc
run: steampipe query "select sum(descendants::bigint) as descendants from new_sc"
- name: save new_sc
run: steampipe query "select * from new_sc" --output csv > ./new_sc.csv
- name: update hn_items_all from new_sc
run: steampipe query query.update_scores_and_comments
- name: save hn_items_all
run: |
steampipe query "alter table hn_items_all drop column _ctx"
steampipe query "update hn_items_all set score = 0::text where score = '<null>'"
steampipe query "update hn_items_all set descendants = 0::text where descendants = '<null>'"
steampipe query "select * from hn_items_all" --output csv > ./hn_items_all.csv
- name: setup git
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
- name: add
run: |
git add ./csv
cp ~/.steampipe/logs/p*.log ./logs
git add ./csv ./logs
- name: commit
run:
git commit -m "update hn" ./csv ./logs ./times.txt ./new_sc.csv ./hn_items_all.csv
- name: push
run:
git push origin main
- name: Exit
if: ${{ steps.checks.outcome == 'failure' }}
run: exit 1