-
Notifications
You must be signed in to change notification settings - Fork 1
190 lines (170 loc) · 8.67 KB
/
main.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Sync
on:
schedule:
- cron: '30/30 * * * *'
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: 'write'
id-token: 'write'
env:
BUCKET_NAME: linux-mirror-db
DB_NAME: mirror.sl3
DB_NAME_UBUNTU: ubuntu.sl3
URL_PREFIX: mirror-chunk-
URL_PREFIX_UBUNTU: mirror-ubuntu-chunk-
# 10MB = 10 * 1024 * 1024 = 10485760
SERVER_CHUNK_SIZE: 10485760
SUFFIX_LENGTH: 3
steps:
- uses: actions/checkout@v2
- name: Download CSVs
run: |
wget https://${BUCKET_NAME}.storage.googleapis.com/fixes.csv
wget https://${BUCKET_NAME}.storage.googleapis.com/reported_by.csv
wget https://${BUCKET_NAME}.storage.googleapis.com/tags.csv
wget https://${BUCKET_NAME}.storage.googleapis.com/upstream.csv
wget https://${BUCKET_NAME}.storage.googleapis.com/ubuntu_tags.csv
wget https://${BUCKET_NAME}.storage.googleapis.com/ubuntu_upstream.csv
wget https://${BUCKET_NAME}.storage.googleapis.com/cve.csv
wget https://${BUCKET_NAME}.storage.googleapis.com/syzkaller.csv
- name: Recreate SQLite3 DB
run: |
sudo apt update && sudo apt install sqlite3
rm -f mirror.sl3 ubuntu.sl3
sqlite3 mirror.sl3 '.mode csv' '.import fixes.csv fixes'
sqlite3 mirror.sl3 '.mode csv' '.import reported_by.csv reported_by'
sqlite3 mirror.sl3 '.mode csv' '.import tags.csv tags'
sqlite3 mirror.sl3 '.mode csv' '.import upstream.csv upstream'
sqlite3 mirror.sl3 '.mode csv' '.import cve.csv cve'
sqlite3 mirror.sl3 '.mode csv' '.import syzkaller.csv syzkaller'
sqlite3 mirror.sl3 'CREATE INDEX fixes_commit ON fixes (`commit`,`fixes`);'
sqlite3 mirror.sl3 'CREATE INDEX fixes_fixes ON fixes (`fixes`,`commit`);'
sqlite3 mirror.sl3 'CREATE INDEX reported_by_commit ON reported_by (`commit`,`reported_by`);'
sqlite3 mirror.sl3 'CREATE INDEX tags_commit ON tags (`commit`,`tags`);'
sqlite3 mirror.sl3 'CREATE INDEX upstream_commit ON upstream (`commit`,`upstream`);'
sqlite3 mirror.sl3 'CREATE INDEX upstream_upstream ON upstream (`upstream`,`commit`);'
sqlite3 mirror.sl3 'CREATE INDEX cve_commit ON cve (`commit`,`cve`);'
sqlite3 mirror.sl3 'CREATE INDEX cve_cve ON cve (`cve`,`commit`);'
sqlite3 mirror.sl3 'pragma journal_mode = delete; pragma page_size = 1024; vacuum;'
sqlite3 ubuntu.sl3 '.mode csv' '.import fixes.csv fixes'
sqlite3 ubuntu.sl3 '.mode csv' '.import reported_by.csv reported_by'
sqlite3 ubuntu.sl3 '.mode csv' '.import ubuntu_tags.csv tags'
sqlite3 ubuntu.sl3 '.mode csv' '.import ubuntu_upstream.csv upstream'
sqlite3 ubuntu.sl3 '.mode csv' '.import cve.csv cve'
sqlite3 ubuntu.sl3 '.mode csv' '.import syzkaller.csv syzkaller'
sqlite3 ubuntu.sl3 'CREATE INDEX fixes_commit ON fixes (`commit`,`fixes`);'
sqlite3 ubuntu.sl3 'CREATE INDEX fixes_fixes ON fixes (`fixes`,`commit`);'
sqlite3 ubuntu.sl3 'CREATE INDEX reported_by_commit ON reported_by (`commit`,`reported_by`);'
sqlite3 ubuntu.sl3 'CREATE INDEX tags_commit ON tags (`commit`,`tags`);'
sqlite3 ubuntu.sl3 'CREATE INDEX upstream_commit ON upstream (`commit`,`upstream`);'
sqlite3 ubuntu.sl3 'CREATE INDEX upstream_upstream ON upstream (`upstream`,`commit`);'
sqlite3 ubuntu.sl3 'CREATE INDEX cve_commit ON cve (`commit`,`cve`);'
sqlite3 ubuntu.sl3 'CREATE INDEX cve_cve ON cve (`cve`,`commit`);'
sqlite3 ubuntu.sl3 'pragma journal_mode = delete; pragma page_size = 1024; vacuum;'
echo "databaseChecksum=$(sha1sum mirror.sl3 | cut -f1 -d' ')" >> $GITHUB_OUTPUT
echo "databaseChecksumUbuntu=$(sha1sum ubuntu.sl3 | cut -f1 -d' ')" >> $GITHUB_OUTPUT
sha1sum mirror.sl3 ubuntu.sl3
- id: 'split-db'
run: |
databaseLengthBytes="$(stat --printf="%s" "${DB_NAME}")"
requestChunkSize="$(sqlite3 "${DB_NAME}" 'pragma page_size')"
rm -f ${URL_PREFIX}*
split "${DB_NAME}" --bytes=${SERVER_CHUNK_SIZE} --suffix-length=${SUFFIX_LENGTH} --numeric-suffixes ${URL_PREFIX}
databaseLengthBytesUbuntu="$(stat --printf="%s" "${DB_NAME_UBUNTU}")"
requestChunkSizeUbuntu="$(sqlite3 "${DB_NAME_UBUNTU}" 'pragma page_size')"
rm -f ${URL_PREFIX_UBUNTU}*
split "${DB_NAME_UBUNTU}" --bytes=${SERVER_CHUNK_SIZE} --suffix-length=${SUFFIX_LENGTH} --numeric-suffixes ${URL_PREFIX_UBUNTU}
echo "requestChunkSizeUbuntu=${requestChunkSizeUbuntu}" >> $GITHUB_OUTPUT
echo "databaseLengthBytesUbuntu=${databaseLengthBytesUbuntu}" >> $GITHUB_OUTPUT
echo "requestChunkSize=${requestChunkSize}" >> $GITHUB_OUTPUT
echo "databaseLengthBytes=${databaseLengthBytes}" >> $GITHUB_OUTPUT
ls
- uses: 'google-github-actions/auth@v0'
with:
workload_identity_provider: 'projects/799795028847/locations/global/workloadIdentityPools/github-pool/providers/github-provider-new'
service_account: '[email protected]'
- id: 'upload-db'
uses: 'google-github-actions/upload-cloud-storage@v0'
with:
parent: false
path: '${{ env.DB_NAME }}'
destination: '${{ env.BUCKET_NAME }}'
- id: 'upload-db-ubuntu'
uses: 'google-github-actions/upload-cloud-storage@v0'
with:
parent: false
path: '${{ env.DB_NAME_UBUNTU }}'
destination: '${{ env.BUCKET_NAME }}'
- id: 'upload-db-chunks'
uses: 'google-github-actions/upload-cloud-storage@v0'
with:
destination: '${{ env.BUCKET_NAME }}/'
glob: '${{ env.URL_PREFIX }}*'
path: ./
gzip: false
headers: |-
cache-control: max-age=30, must-revalidate
- id: 'upload-db-chunks-ubuntu'
uses: 'google-github-actions/upload-cloud-storage@v0'
with:
destination: '${{ env.BUCKET_NAME }}/'
glob: '${{ env.URL_PREFIX_UBUNTU }}*'
path: ./
gzip: false
headers: |-
cache-control: max-age=30, must-revalidate
- name: "Update config"
env:
requestChunkSize: '${{ steps.split-db.outputs.requestChunkSize }}'
databaseLengthBytes: '${{ steps.split-db.outputs.databaseLengthBytes }}'
databaseChecksum: '${{ steps.split-db.outputs.databaseChecksum }}'
uploadedPath: 'https://storage.googleapis.com/${{ env.BUCKET_NAME }}/${{ env.URL_PREFIX }}'
run: |
echo '{
"serverMode": "chunked",
"requestChunkSize": '${requestChunkSize}',
"databaseLengthBytes": '${databaseLengthBytes}',
"serverChunkSize": '${SERVER_CHUNK_SIZE}',
"urlPrefix": "'${uploadedPath}'",
"suffixLength": '${SUFFIX_LENGTH}'
}' | tee "config.json"
- name: "Update config ubuntu"
env:
requestChunkSize: '${{ steps.split-db.outputs.requestChunkSizeUbuntu }}'
databaseLengthBytes: '${{ steps.split-db.outputs.databaseLengthBytesUbuntu }}'
databaseChecksum: '${{ steps.split-db.outputs.databaseChecksumUbuntu }}'
uploadedPath: 'https://storage.googleapis.com/${{ env.BUCKET_NAME }}/${{ env.URL_PREFIX_UBUNTU }}'
run: |
echo '{
"serverMode": "chunked",
"requestChunkSize": '${requestChunkSize}',
"databaseLengthBytes": '${databaseLengthBytes}',
"serverChunkSize": '${SERVER_CHUNK_SIZE}',
"urlPrefix": "'${uploadedPath}'",
"suffixLength": '${SUFFIX_LENGTH}'
}' | tee "config-ubuntu.json"
- id: 'upload-config'
uses: 'google-github-actions/upload-cloud-storage@v0'
with:
parent: false
path: 'config.json'
destination: '${{ env.BUCKET_NAME }}'
headers: |-
cache-control: max-age=3, must-revalidate
- id: 'upload-config-ubuntu'
uses: 'google-github-actions/upload-cloud-storage@v0'
with:
parent: false
path: 'config-ubuntu.json'
destination: '${{ env.BUCKET_NAME }}'
headers: |-
cache-control: max-age=3, must-revalidate
- id: 'version-control-config'
run: |
git config --local user.name "GitHub Actions Bot"
git config --local user.email "[email protected]"
git add config.json config-ubuntu.json
(git commit -am 'update config.json ${{ steps.split-db.outputs.databaseChecksum }} ${{ steps.split-db.outputs.databaseChecksumUbuntu }}' && git push) || true