forked from xerial/sqlite-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
289 lines (252 loc) · 10.7 KB
/
update-from-upstream.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
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
name: Update From Upstream
on:
push:
branches:
- 'releases/**'
paths:
- '.fork-meta/upstream-version.txt'
jobs:
update-from-upstream:
runs-on: ubuntu-latest
outputs:
upstream_version: ${{ steps.add-upstream-and-update.outputs.upstream_version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
- run: git status
- name: Setup git config
run: |
# setup the username and email
git config user.name "Austin G. Arbor"
git config user.email "${{ vars.GIT_COMMIT_EMAIL }}"
- name: Add Upstream and Update
id: add-upstream-and-update
run: |
git remote add upstream https://github.com/xerial/sqlite-jdbc.git
git fetch upstream
upstream_version=$(cat .fork-meta/upstream-version.txt)
echo "upstream_version=${upstream_version}" >> "$GITHUB_OUTPUT"
# overwrite our pom.xml, Makefile, and README.adoc with the upstream version
git checkout "tags/${upstream_version}" -- pom.xml Makefile README.adoc
git commit -m "update pom.xml, Makefile, and README.adoc from ${upstream_version}"
# note: when rebasing, ours and theirs is flipped
git merge --strategy=ort --strategy-option=theirs "tags/${upstream_version}"
- name: Modify pom.xml
run: |
# set the distribution management url to ours
set -e
# update project url
yq -i -e '.project.url = "https://github.com/austinarbor/sqlite-jdbc"' pom.xml
# update groupId
yq -i -e '.project.groupId = "dev.aga.sqlite"' pom.xml
# update snapshot repository url
yq -i -e '.project.distributionManagement.snapshotRepository.url = "https://s01.oss.sonatype.org/content/repositories/snapshots"' pom.xml
# update connection
yq -i -e '.project.scm.connection = "scm:git:git://github.com/austinarbor/sqlite-jdbc.git"' pom.xml
# update developer connection
yq -i -e '.project.scm.developerConnection = "scm:git:[email protected]:austinarbor/sqlite-jdbc.git"' pom.xml
# update url
yq -i -e '.project.scm.url = "https://github.com/austinarbor/sqlite-jdbc"' pom.xml
# update nexus url
yq -i -e '(.project.build.plugins.plugin.[] | select(.artifactId == "nexus-staging-maven-plugin") | .configuration.nexusUrl) ="https://s01.oss.sonatype.org/"' pom.xml
# disable the auto release for now
yq -i -e '(.project.build.plugins.plugin.[] | select(.artifactId == "nexus-staging-maven-plugin") | .configuration.autoReleaseAfterClose) ="false"' pom.xml
# yq seems to maybe have a bug with this? not sure of a better way to insert the developer
yq -i '.project.developers += {"+developer" : {"id": "austinarbor", "name": "Austin G. Arbor", "email": "[email protected]"}}' pom.xml -p=xml -o=xml
# remove the + from the developer tag
sed -i 's/+developer/developer/g' pom.xml
- name: Download and Update decimal.c
run: |
maven_version=$(yq '.project.version' pom.xml)
if [[ "${{ steps.add-upstream-and-update.outputs.upstream_version }}" != "${maven_version}" ]]; then
echo "version mismatch detected"
echo "maven: ${maven_version}"
echo "upstream: ${upstream_version}"
exit 1
fi
IFS=. read major minor patch build <<<"${maven_version}"
sqlite_version=$(printf "%d.%02d.%02d" "${major}" "${minor}" "${patch}")
amalgamation_version=$(printf "%d%02d%02d00" "${major}" "${minor}" "${patch}")
echo "amalgamation version: ${amalgamation_version}"
file_name="sqlite-src-${amalgamation_version}.zip"
download_url="https://www.sqlite.org/2024/${file_name}"
wget "${download_url}"
unzip "${file_name}"
dir_name="${file_name//.zip/}"
cp "${dir_name}/ext/misc/decimal.c" src/main/ext/decimal.c
# remove the ifdef block(s)
perl -i -p0e 's/#ifdef _WIN32.*#endif//gms' src/main/ext/decimal.c
rm -rf "${file_name}/"
- name: Update Makefile
run: |
# disable exit on failure for the grep
set +e
grep SQLITE_EXTRA_INIT Makefile
if [[ "$?" == "0" ]]; then
echo "SQLITE_EXTRA_INIT found, failing"
exit 1
fi
set -e
# get the last line number that contains -DSQLITE_ , we will need to insert our custom line after
prev_line_num=$(awk '/-DSQLITE_/ {print FNR}' Makefile | tail -n 1)
line_num=$((prev_line_num+1))
# need \ to make the spacing work
new_line="\ -DSQLITE_EXTRA_INIT=core_init \\\\"
sed -i "${line_num}i ${new_line}" Makefile
- name: Update README.adoc
run: |
# insert our "header" into the readme
set +e
sed -i '1i == SQLite JDBC Driver Fork\n\nThis repo is a fork of https://github.com/xerial/sqlite-jdbc[xerial/sqlite-jdbc], the only difference being the inclusion of the `decimal.c` extension in the jar.\n\nimage:https://img.shields.io/maven-central/v/dev.aga.sqlite/sqlite-jdbc?color=g&label=maven%20central[Maven Central,link=https://central.sonatype.com/search?q=g%3Adev.aga.sqlite+a%3Asqlite-jdbc]\n\n_Everything below this line comes from the original repository._\n' README.adoc
- name: Create commit message
id: create-commit-message
run: |
message="update pom.xml, Makefile, decimal.c, and README.adoc for ${{ steps.add-upstream-and-update.outputs.upstream_version }}"
set +e
# if decimal.c wasn't updated, remove it from the commit message
git diff --exit-code src/main/ext/decimal.c
if [ $? -eq 0 ]; then
message="${message/decimal.c, /}"
fi
set -e
echo "commit_message=${message}" >> $GITHUB_OUTPUT
- name: Commit modified files
uses: EndBug/add-and-commit@v9
with:
add: '[ "pom.xml", "README.adoc", "Makefile", "src/main/ext/decimal.c" ]'
message: ${{ steps.create-commit-message.outputs.commit_message }}
author_name: 'Austin G. Arbor'
author_email: '${{ vars.GIT_COMMIT_EMAIL }}'
push: false
- name: Check for Modified Files
run: |
# if we still have unchanged files, something is wrong
if [[ -n "$(git status --porcelain)" ]]; then
echo "modified files leftover, exiting"
git status --porcelain
exit 1
fi
- name: Resolve Conflicts
run: |
git merge --strategy=ort --strategy-option=ours origin/master
- name: Push Changes
run: |
git push --force
matrix:
name: Build matrix
runs-on: ubuntu-latest
needs: [ update-from-upstream ]
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: Build matrix from Makefile
id: set-matrix
# parse the Makefile to retrieve the list of targets in 'native-all', without 'native'
run: |
matrix=$((
echo '{ "target" : ['
sed -n "/^native-all *: */ { s///; p }" Makefile | sed "s/^native\s//g" | sed 's/ /, /g' | xargs -n 1 echo | sed -r 's/^([^,]*)(,?)$/"\1"\2/'
echo " ]}"
) | jq -c .)
echo $matrix | jq .
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build:
name: Build native libraries
runs-on: ubuntu-latest
needs: [ matrix ]
strategy:
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
# Delete existing libs so we only upload the generated one into the artifact
- name: Delete existing native libs
run: rm -fr src/main/resources/org/sqlite/native
- name: Build native libraries
run: make ${{ matrix.target }}
env:
OCI_EXE: docker
- name: Upload native libraries
uses: actions/upload-artifact@v3
with:
name: native-libs
path: src/main/resources/org/sqlite/native/
test:
name: Test latest build
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
runs-on: ${{ matrix.os }}
needs: [ update-from-upstream, build ]
steps:
- name: setup java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
java-package: jdk
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git pull --rebase
- name: Download native libraries
uses: actions/download-artifact@v3
with:
name: native-libs
path: src/main/resources/org/sqlite/native/
- uses: actions/checkout@v3
with:
repository: austinarbor/sqlite-jdbc-decimal-test
path: sqlite-jdbc-decimal-test
- name: create packaged jar
run: mvn clean package -DskipTests
- name: copy jar into test project
run: |
cp "target/sqlite-jdbc-${{ needs.update-from-upstream.outputs.upstream_version }}.jar" sqlite-jdbc-decimal-test/libs/
- name: run tests
uses: gradle/gradle-build-action@v2
with:
arguments: test
build-root-directory: sqlite-jdbc-decimal-test
cache-read-only: ${{ github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/heads/releases/') }}
push:
name: Push new native libraries to branch
runs-on: ubuntu-latest
needs: [ test ]
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 0
- run: git pull --rebase
- name: Download native libraries
uses: actions/download-artifact@v3
with:
name: native-libs
path: src/main/resources/org/sqlite/native/
- run: git status
- name: Commit and push
uses: EndBug/add-and-commit@v9
with:
message: 'chore: update native libraries'
author_name: 'Austin G. Arbor'
author_email: '${{ vars.GIT_COMMIT_EMAIL }}'
open-pr:
name: Open PR
runs-on: ubuntu-latest
needs: [ update-from-upstream, push ]
steps:
- uses: actions/checkout@v3
- name: Open PR
run: |
upstream_version="${{ needs.update-from-upstream.outputs.upstream_version }}"
gh pr create \
--repo austinarbor/sqlite-jdbc \
--base master \
--title "Prepare ${upstream_version}" \
--body "Changes for ${upstream_version}" \
--no-maintainer-edit
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}