forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 2
280 lines (248 loc) · 11.7 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
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
name: OTP CI Build
on:
push:
pull_request:
branches:
- ibi-dev
- ibi-dev-2.x
jobs:
build-linux:
env:
MAVEN_OPTS: -Xmx2g
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,unit-tests -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
## IBI start
# So that the branch name can be reference via $GITHUB_REF_SLUG.
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
# Define AWS profile credentials for use by subsequent steps.
- name: Add profile credentials to ~/.aws/credentials
if: github.event_name == 'push'
run: ./scripts/add-aws-credentials.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
# Only prepare deploy files on push events to avoid duplicate pushes to s3 when a commit is
# pushed to a branch with an open pull request.
- name: Prepare build files for deployment to s3
if: github.event_name == 'push'
run: ./scripts/prep-build-for-deploy-from-github-actions.sh
# Copy build files to AWS.
- name: Copy build files to the otp-repo bucket
if: github.event_name == 'push'
run: |
aws s3 cp ./deploy s3://otp-repo --recursive --acl public-read
# Install mkdocs using pip for use by subsequent steps.
- name: Install mkdocs
if: github.event_name == 'push' && env.GITHUB_REF_SLUG == 'ibi-dev-2.x'
run: |
pip install mkdocs
# Using mkdocs produce docs for deployment.
# FIXME: there is an error while trying to run enunciate to generate the docs
# - name: Prepare doc files for deployment to s3
# if: github.event_name == 'push' && env.GITHUB_REF_SLUG == 'ibi-dev-2.x'
# run: ./scripts/prep-docs-for-deploy-from-github-actions.sh
# # If on ibi-dev branch, then upload docs to IBI s3 buckets & cloudfront.
# FIXME: figure out whether the same bucket should be used, or a different one should be used for 2.x docs
# - name: Upload docs to IBI s3 buckets & cloudfront
# if: github.event_name == 'push' && env.GITHUB_REF_SLUG == 'ibi-dev-2.x'
# run: |
# aws s3 cp ./target/mkdocs s3://otp-docs.ibi-transit.com --recursive --acl public-read
# Push notification to Teams.
- name: Notify us of the build status on MS Teams
# Release https://github.com/toko-bifrost/ms-teams-deploy-card/releases/tag/3.1.2 this matches
# the full length commit SHA below. This must not be changed without first reviewing the code of the newer
# version for potential security risks.
uses: toko-bifrost/ms-teams-deploy-card@dcc94e4ce4088b1e6b6de5c9a3cda4ddcbe97d2e
if: always()
with:
github-token: ${{ github.token }}
webhook-uri: ${{ secrets.MSTEAMS_WEBHOOK }}
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 --break-system-packages -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-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
mvn --batch-mode -P prettierSkip compile com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,$image_version