-
Notifications
You must be signed in to change notification settings - Fork 1k
240 lines (209 loc) · 9.5 KB
/
cibuild.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
name: OTP CI Build
# On [push, pull_request] causes double-builds when creating PRs.
# But triggering on push only will miss pull requests from outside authors.
# The push event's ref is the name of the pushed branch;
# The pull_request event's branch name is the merge target branch.
on:
push:
branches:
- master
- dev-1.x
- dev-2.x
pull_request:
branches:
- master
- dev-1.x
- dev-2.x
jobs:
build-linux:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
# Starting in v2.2 checkout action fetches all tags when fetch-depth=0, for auto-versioning.
- uses: actions/checkout@v4
with:
fetch-depth: 0
# nodejs is needed because the dynamic download of it via the prettier maven plugin often
# times out
# Example: https://github.com/opentripplanner/OpenTripPlanner/actions/runs/4490450225/jobs/7897533439
- uses: actions/setup-node@v4
with:
node-version: 18
# Java setup step completes very fast, no need to run in a preconfigured docker container
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven
- name: Prepare coverage agent, build and test
# these are split into two steps because otherwise maven keeps long-running HTTP connections
# to Maven Central open which then hang during the package phase because the Azure (Github Actions)
# NAT drops them
# https://github.com/actions/runner-images/issues/1499
# we set nodePath and npmPath to skip downloading the node binary, which frequently times out
run: |
mvn --batch-mode jacoco:prepare-agent test jacoco:report -P prettierCheck -Dprettier.nodePath=node -Dprettier.npmPath=npm
mvn --batch-mode package -Dmaven.test.skip -P prettierSkip
- name: Send coverage data to codecov.io
if: github.repository_owner == 'opentripplanner'
uses: codecov/codecov-action@v4
with:
files: target/site/jacoco/jacoco.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
- name: Deploy to Github Package Registry
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev-1.x' || github.ref == 'refs/heads/dev-2.x')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn --batch-mode deploy --settings maven-settings.xml -DskipTests -DGITHUB_REPOSITORY=$GITHUB_REPOSITORY -P prettierSkip -P deployGitHub
build-windows:
timeout-minutes: 20
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven
# on windows there are frequent failures caused by page files being too small
# https://github.com/actions/virtual-environments/issues/785
- name: Configure Windows Pagefile
uses: al-cheb/[email protected]
- name: Run tests
run: mvn --batch-mode test -P prettierSkip
docs:
if: github.repository_owner == 'opentripplanner'
runs-on: ubuntu-latest
env:
REMOTE: docs
LOCAL_BRANCH: local-pages
REMOTE_BRANCH: main
TOKEN: ${{ secrets.CHANGELOG_TOKEN }}
MASTER_BRANCH_VERSION: 2.6.0
steps:
- uses: actions/checkout@v4
# this is necessary so that the correct credentials are put into the git configuration
# when we push to dev-2.x and push the HTML to the git repo
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev-2.x' || github.ref == 'refs/heads/master')
with:
token: ${{ secrets.CHANGELOG_TOKEN }}
# fetch a large-ish number of commits so that we can check when the GraphQL schema file
# was modified last
fetch-depth: 1000
- uses: actions/checkout@v4
# for a simple PR where we don't push, we don't need any credentials
if: github.event_name == 'pull_request'
- name: Install Python dependencies
run: pip install -r doc/user/requirements.txt
- name: Build main documentation
if: github.event_name == 'pull_request'
run: mkdocs build
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Build GTFS GraphQL API documentation
run: |
npm install -g @magidoc/[email protected]
magidoc generate --stacktrace
- name: Deploy compiled HTML to Github pages
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev-2.x' || github.ref == 'refs/heads/master')
run: |
git config --global user.name 'OTP Bot'
git config --global user.email '[email protected]'
# mike, the versioning plugin for mkdocs, expects there to be a local branch to push to so
# we are cloning one here and commit to it
# mike has support for specifing the origin but then it tries to rebase the _local_ gh-pages
# branch onto the remote which fails. that's the reason for this git hackery.
git remote add $REMOTE https://[email protected]/opentripplanner/docs.git
git fetch $REMOTE $REMOTE_BRANCH:$LOCAL_BRANCH
# prefix is the root folder where to deploy the HTML, we use 'en' to emulate the URL
# structure of readthedocs
if [ ${{ github.ref }} = 'refs/heads/master' ];
then
mike deploy --branch $LOCAL_BRANCH --deploy-prefix en --title=$MASTER_BRANCH_VERSION --update-aliases v$MASTER_BRANCH_VERSION latest
else
mike deploy --branch $LOCAL_BRANCH --deploy-prefix en dev-2.x
fi
# commit and push the GraphQL documentation if the schema file is newer than the
# compiled output. it's necessary to have this check because the diffs of the magidoc tool
# this are quite large and unnecessarily increase the size of the docs repo even when the
# schema hasn't changed.
# example commit: https://github.com/opentripplanner/docs/commit/45e6ddf8e4a4
SCHEMA_FILE_MODIFIED=`git log -n 1 --pretty=format:%ct application/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls`
echo "schema modified at ${SCHEMA_FILE_MODIFIED}"
git checkout $LOCAL_BRANCH
DOCS_MODIFIED=`git log -n 1 --pretty=format:%ct api/dev-2.x/graphql-gtfs/introduction.html`
echo "docs modified at ${DOCS_MODIFIED}"
if [ "${SCHEMA_FILE_MODIFIED}" -gt "${DOCS_MODIFIED}" ]; then
echo "schema.graphqls has been modified, committing updated documentation"
mkdir -p api
rsync -r --delete target/magidoc/api/ api/dev-2.x/
git add api
git commit -am "Add Magidoc GraphQL documentation"
else
echo "schema.graphqls has not been modified, not committing documentation"
fi
git push $REMOTE $LOCAL_BRANCH:$REMOTE_BRANCH
graphql-code-generation:
if: github.repository_owner == 'opentripplanner'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Run code generator
working-directory: application/src/main/java/org/opentripplanner/apis/gtfs/generated
run: |
yarn install
yarn generate
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven
- name: Compile Java code
run: mvn --batch-mode compile -DskipTests -P prettierSkip
container-image:
if: github.repository_owner == 'opentripplanner' && github.event_name == 'push' && (github.ref == 'refs/heads/dev-2.x' || github.ref == 'refs/heads/master')
runs-on: ubuntu-latest
needs:
- build-windows
- build-linux
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Build container image with Jib, push to Dockerhub
env:
CONTAINER_REPO: docker.io/opentripplanner/opentripplanner
CONTAINER_REGISTRY_USER: otpbot
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
# we give the container two tags
# - "latest"
# - a string like "2.3_2022-12-12T21-38"
version_with_snapshot=`mvn -q help:evaluate -Dexpression=project.version -q -DforceStdout`
version=${version_with_snapshot/-SNAPSHOT/}
image_version=${version}
## if the Maven version contains SNAPSHOT, then add date to tag
if [[ $version_with_snapshot == *"SNAPSHOT"* ]]; then
image_date=`date +%Y-%m-%dT%H-%M`
image_version="${version}_${image_date}"
echo "Maven version ${version_with_snapshot} contains SNAPSHOT, adding date to container image tag"
fi
MAVEN_SKIP_ARGS="-P prettierSkip -Dmaven.test.skip=true -Dmaven.source.skip=true"
mvn --batch-mode $MAVEN_SKIP_ARGS package com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,$image_version