-
-
Notifications
You must be signed in to change notification settings - Fork 100
352 lines (285 loc) · 10.8 KB
/
update-sqlite.yml
File metadata and controls
352 lines (285 loc) · 10.8 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
name: Update SQLite (Manual)
on:
workflow_dispatch:
inputs:
sqlite_version:
description: "SQLite version (e.g. 3.53.1)"
required: true
mode:
description: "Release mode"
required: true
type: choice
default: dry-run
options:
- sanity
- dry-run
- release
permissions:
contents: write
env:
CONFIG_FILE: config.json
SQLITE_PATH: sqlite3
ARCHIVES: archives
jobs:
generate:
runs-on: ubuntu-latest
env:
MODE: ${{ github.event.inputs.mode }}
steps:
# -------------------------------------------------
# Checkout repository
# -------------------------------------------------
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
# -------------------------------------------------
# Setup Python
# -------------------------------------------------
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
# -------------------------------------------------
# Update SQLite version number in configuration
# -------------------------------------------------
- name: Update config
shell: bash
run: |
set -euo pipefail
python scripts/update_config.py "${{ inputs.sqlite_version }}"
# -------------------------------------------------
# Create environment variables
# -------------------------------------------------
- name: Build context
shell: bash
run: |
set -euo pipefail
python scripts/build_context.py
# -------------------------------------------------
# Display environment variables
# -------------------------------------------------
- name: Show environment
shell: bash
run: |
set -euo pipefail
echo "SQLite Version: $SQLITE_VERSION"
echo "SQLite Version Raw: $SQLITE_VERSION_RAW"
echo "SQLite URL Official: $SQLITE_URL_OFFICIAL"
echo "SQLite URL GitHub: $SQLITE_URL_GITHUB"
# -------------------------------------------------
# Create directories for intermediate files
# -------------------------------------------------
- name: Create directories
shell: bash
run: |
set -euo pipefail
mkdir -p "$SQLITE_PATH"
mkdir -p "$ARCHIVES"
# -------------------------------------------------
# Download amalgamation of requested SQLite version
# -------------------------------------------------
- name: Download SQLite sources
shell: bash
run: |
set -euo pipefail
echo "Downloading from: $SQLITE_URL_OFFICIAL"
URL="${SQLITE_URL_OFFICIAL}sqlite-amalgamation-${SQLITE_VERSION_RAW}.zip"
echo "File: $URL"
curl -L "$URL" -o sqlite.zip
echo "Extracting..."
unzip -q sqlite.zip -d "$SQLITE_PATH"
rm sqlite.zip
echo "Done. Contents of $SQLITE_PATH:"
ls -la "$SQLITE_PATH"
# -------------------------------------------------
# Generate patched SQLite source files
# -------------------------------------------------
- name: Patch SQLite3 amalgamation
shell: bash
run: |
set -euo pipefail
sqlite3_h="${{ env.SQLITE_PATH }}/sqlite-amalgamation-${{ env.SQLITE_VERSION_RAW }}/sqlite3.h"
sqlite3ext_h="${{ env.SQLITE_PATH }}/sqlite-amalgamation-${{ env.SQLITE_VERSION_RAW }}/sqlite3ext.h"
sqlite_src="${{ env.SQLITE_PATH }}/sqlite-amalgamation-${{ env.SQLITE_VERSION_RAW }}/sqlite3.c"
shell_src="${{ env.SQLITE_PATH }}/sqlite-amalgamation-${{ env.SQLITE_VERSION_RAW }}/shell.c"
dest_sqlite="${{ env.SQLITE_PATH }}/sqlite3patched.c"
dest_shell="${{ env.SQLITE_PATH }}/shell.c"
dest_rekey="${{ env.SQLITE_PATH }}/rekeyvacuum.c"
# Make sure that scripts are executable
chmod +x scripts/patchsqlite3.sh
chmod +x scripts/patchshell.sh
chmod +x scripts/rekeyvacuum.sh
ls -l scripts/
bash scripts/patchsqlite3.sh $sqlite_src > $dest_sqlite
bash scripts/patchshell.sh $shell_src > $dest_shell
bash scripts/rekeyvacuum.sh $sqlite_src > $dest_rekey
cp "$sqlite_src" "$SQLITE_PATH/"
cp "$shell_src" "$SQLITE_PATH/shell-orig.c"
cp "$sqlite3_h" "$SQLITE_PATH/"
cp "$sqlite3ext_h" "$SQLITE_PATH/"
ls -l "${{ env.SQLITE_PATH }}"
# -------------------------------------------------
# Compare generated patched source files with previous version
# -------------------------------------------------
# Usually they will differ when updating to a new version.
# However, after a successful update, repeating the update process
# for the same version should result in identical files.
# -------------------------------------------------
- name: Comparing patched SQLite files
shell: bash
run: |
set -euo pipefail
FILES=(
"sqlite3patched.c"
"rekeyvacuum.c"
"shell.c"
)
echo "=== Patch comparison report ==="
CHANGED=0
for f in "${FILES[@]}"; do
echo ""
echo "Checking: $f"
if cmp -s "src/$f" "$SQLITE_PATH/$f"; then
echo "OK: identical"
else
echo "DIFF: changed"
CHANGED=1
echo "--- diff ($f) ---"
diff -u "src/$f" "$SQLITE_PATH/$f" || true
fi
done
echo ""
echo "=== Summary ==="
if [ "$CHANGED" -eq 0 ]; then
echo "All files identical"
else
echo "Some files differ (see above)"
fi
exit 0
# -------------------------------------------------
# Compare generated patched source files with originals
# -------------------------------------------------
# If the number of deviations doesn't correspond to the
# number of applied patch hunks, it will be required to
# inspect the files carefully, and to adjust the patches
# if necessary.
# -------------------------------------------------
- name: Per-file patch impact analysis
shell: bash
run: |
set -euo pipefail
COMPARE_PAIRS=(
"sqlite3.c:sqlite3patched.c"
"shell-orig.c:shell.c"
"../src/rekeyvacuum.c:rekeyvacuum.c"
)
for pair in "${COMPARE_PAIRS[@]}"; do
SRC="${pair%%:*}"
DST="${pair##*:}"
ORIGINAL="$SQLITE_PATH/$SRC"
PATCHED="$SQLITE_PATH/$DST"
echo ""
echo "Comparing:"
echo " original: $SRC"
echo " patched : $DST"
DIFF_BLOCKS=$(diff -u "$ORIGINAL" "$PATCHED" \
| grep -c '^@@' || true)
echo "Patch blocks: $DIFF_BLOCKS"
done
# -------------------------------------------------
# Create ZIP archive(s) for the updated and patched SQLite source files
# -------------------------------------------------
- name: Create ZIP archive for updated SQLite sources
shell: bash
run: |
set -euo pipefail
DESTPATH="$ARCHIVES"
(
SOURCEPATH="$SQLITE_PATH"
cd "$SOURCEPATH"
find . -maxdepth 1 -type f -print \
| zip "../$DESTPATH/sqlite3source.zip" -@
)
ls -l "$DESTPATH"
# -------------------------------------------------
# Upload ZIP archive
# -------------------------------------------------
- name: Upload ZIP archives
uses: actions/upload-artifact@v7
with:
name: sqlite-sources
path: |
${{ env.ARCHIVES }}/sqlite3source.zip
# -------------------------------------------------
# Replace original and patched SQLite sources
# -------------------------------------------------
- name: Copy original and patched files into src
shell: bash
run: |
set -euo pipefail
echo "Copying files into src/ ..."
for f in sqlite3.c sqlite3.h sqlite3ext.h sqlite3patched.c rekeyvacuum.c shell.c; do
echo "Copying $f"
cp -f "$SQLITE_PATH/$f" src/
done
echo "Done. Checking for changes..."
git status --porcelain
# -------------------------------------------------
# GIT + GPG SETUP (only non-sanity)
# -------------------------------------------------
- name: Configure Git
if: ${{ inputs.mode != 'sanity' }}
run: |
git config user.name "${{ vars.GIT_USER_NAME }}"
git config user.email "${{ vars.GIT_USER_EMAIL }}"
git config user.signingkey "${{ vars.GPG_KEY_ID }}"
git config commit.gpgsign true
# -------------------------------------------------
# Import GPG key (only non-sanity)
# -------------------------------------------------
- name: Import GPG key
if: ${{ inputs.mode != 'sanity' }}
run: |
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import
# -------------------------------------------------
# DRY RUN VALIDATION
# -------------------------------------------------
- name: Dry-run signing validation
if: ${{ inputs.mode == 'dry-run' }}
shell: bash
run: |
set -euo pipefail
echo "Testing GPG setup..."
gpg --list-secret-keys --keyid-format=long
echo "Testing commit signing..."
git commit --allow-empty -S -m "dry-run signing test"
echo "Verifying signature..."
git log -1 --show-signature
echo "Commit email:"
git log -1 --format='%ae'
echo "Commit signature:"
git log -1 --show-signature
echo "Verify commit:"
git verify-commit HEAD
# -------------------------------------------------
# Commit changed source files and configuration (only release)
# -------------------------------------------------
- name: Commit config and source changes
if: ${{ inputs.mode == 'release' }}
shell: bash
run: |
set -euo pipefail
git add config.json
git add src/sqlite3.c
git add src/sqlite3.h
git add src/sqlite3ext.h
git add src/sqlite3patched.c
git add src/shell.c
git add src/rekeyvacuum.c
if git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
git commit -m "Update SQLite version to ${{ inputs.sqlite_version }}"
git push