-
Notifications
You must be signed in to change notification settings - Fork 3
217 lines (187 loc) · 7.18 KB
/
ci.yml
File metadata and controls
217 lines (187 loc) · 7.18 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
name: CI - Build and Test
# Trigger re-run to pick up deployed treebase-core JAR from gh-pages
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
workflow_dispatch:
jobs:
build-and-test:
name: Build and Test TreeBASE
runs-on: ubuntu-latest
permissions:
contents: write
checks: write
pull-requests: write
services:
postgres:
image: postgres:12
env:
POSTGRES_DB: treebasedb
POSTGRES_USER: treebase_user
POSTGRES_PASSWORD: treebase_pass
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Configure database properties for tests
run: |
mkdir -p /tmp/mesquite
cat > treebase-core/src/test/resources/jdbc.properties << EOF
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/treebasedb
jdbc.username=treebase_user
jdbc.password=treebase_pass
mesquite.folder_dir=/tmp/mesquite
EOF
cat > oai-pmh_data_provider/data_provider_web/src/test/resources/jdbc.properties << EOF
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/treebasedb
jdbc.username=treebase_user
jdbc.password=treebase_pass
mesquite.folder_dir=/tmp/mesquite
EOF
- name: Initialize database schema
run: |
# Install PostgreSQL client if not already available
sudo apt-get update
sudo apt-get install -y postgresql-client
# Initialize the database with schema and data
# The init_db_uptodate.pg script uses \i commands with relative paths,
# so we must run it from the schema directory
cd treebase-core/db/schema
PGPASSWORD=treebase_pass psql -h localhost -U treebase_user -d treebasedb -f init_db_uptodate.pg
- name: Build treebase-core
run: mvn -B clean compile -f treebase-core/pom.xml
- name: Run treebase-core tests
run: mvn -B test -f treebase-core/pom.xml
- name: Install treebase-core to local Maven repository
run: mvn -B install -DskipTests -f treebase-core/pom.xml
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
fetch-depth: 0
- name: Deploy parent POM and treebase-core JAR to Maven repository
run: |
# Set up Maven coordinates for parent POM
PARENT_GROUP_ID="org.cipres.treebase"
PARENT_ARTIFACT_ID="treebase"
VERSION="1.0-SNAPSHOT"
# Deploy parent POM
GROUP_PATH=$(echo $PARENT_GROUP_ID | tr '.' '/')
PARENT_REPO_PATH="gh-pages/repository/${GROUP_PATH}/${PARENT_ARTIFACT_ID}/${VERSION}"
mkdir -p "$PARENT_REPO_PATH"
# Copy parent POM file
cp pom.xml "$PARENT_REPO_PATH/${PARENT_ARTIFACT_ID}-${VERSION}.pom"
# Generate checksums for parent POM
cd "$PARENT_REPO_PATH"
for file in *.pom; do
if [ -f "$file" ]; then
sha1sum "$file" | awk '{print $1}' > "${file}.sha1"
md5sum "$file" | awk '{print $1}' > "${file}.md5"
fi
done
# Generate maven-metadata.xml for parent POM
cat > maven-metadata.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>${PARENT_GROUP_ID}</groupId>
<artifactId>${PARENT_ARTIFACT_ID}</artifactId>
<versioning>
<versions>
<version>${VERSION}</version>
</versions>
<lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated>
</versioning>
</metadata>
EOF
# Generate checksums for parent metadata
sha1sum maven-metadata.xml | awk '{print $1}' > maven-metadata.xml.sha1
md5sum maven-metadata.xml | awk '{print $1}' > maven-metadata.xml.md5
# Now deploy treebase-core JAR
cd -
ARTIFACT_ID="treebase-core"
REPO_PATH="gh-pages/repository/${GROUP_PATH}/${ARTIFACT_ID}/${VERSION}"
mkdir -p "$REPO_PATH"
# Verify JAR file exists
JAR_FILE="treebase-core/target/${ARTIFACT_ID}-${VERSION}.jar"
if [ ! -f "$JAR_FILE" ]; then
echo "Error: JAR file not found at $JAR_FILE"
exit 1
fi
# Copy JAR and POM files
cp "$JAR_FILE" "$REPO_PATH/"
cp treebase-core/pom.xml "$REPO_PATH/${ARTIFACT_ID}-${VERSION}.pom"
# Generate checksums for treebase-core
cd "$REPO_PATH"
for file in *.jar *.pom; do
if [ -f "$file" ]; then
sha1sum "$file" | awk '{print $1}' > "${file}.sha1"
md5sum "$file" | awk '{print $1}' > "${file}.md5"
fi
done
# Generate maven-metadata.xml for treebase-core
cat > maven-metadata.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>${PARENT_GROUP_ID}</groupId>
<artifactId>${ARTIFACT_ID}</artifactId>
<versioning>
<versions>
<version>${VERSION}</version>
</versions>
<lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated>
</versioning>
</metadata>
EOF
# Generate checksums for treebase-core metadata
sha1sum maven-metadata.xml | awk '{print $1}' > maven-metadata.xml.sha1
md5sum maven-metadata.xml | awk '{print $1}' > maven-metadata.xml.md5
- name: Commit and push to gh-pages
run: |
cd gh-pages
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add repository/
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Deploy treebase-core JAR from CI build (commit: ${{ github.sha }})"
# Pull with rebase to handle concurrent updates
git pull --rebase origin gh-pages || {
echo "Rebase failed, attempting force push"
git rebase --abort
git push --force
exit 0
}
git push
fi
- name: Build treebase-web
run: mvn -B clean compile -f treebase-web/pom.xml
- name: Build oai-pmh_data_provider
run: mvn -B clean compile -f oai-pmh_data_provider/pom.xml
- name: Run oai-pmh_data_provider tests
run: mvn -B test -f oai-pmh_data_provider/pom.xml
- name: Publish Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: JUnit Test Results
path: 'treebase-core/target/surefire-reports/*.xml,oai-pmh_data_provider/data_provider_web/target/surefire-reports/*.xml'
reporter: java-junit
fail-on-error: true