Merge pull request #6331 from entur/add_shaded_jar_artifact #12182
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
env: | |
# Since version 3.9.0 of Maven it will automatically understand this environment variable. | |
# However, as of 2024-11 the latest versions of Ubuntu and Debian were on 3.8.8 so it will take some | |
# time until we can remove the $MAVEN_ARGS below. | |
MAVEN_ARGS: "--no-transfer-progress -Dstyle.color=always" | |
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 $MAVEN_ARGS jacoco:prepare-agent test jacoco:report -P prettierCheck -Dprettier.nodePath=node -Dprettier.npmPath=npm | |
mvn $MAVEN_ARGS package -Dmaven.test.skip -P prettierSkip | |
- name: Send coverage data to codecov.io | |
if: github.repository_owner == 'opentripplanner' | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
verbose: true | |
- name: Upload test results to Codecov | |
# always upload test results, even when failed | |
if: ${{ !cancelled() }} | |
uses: codecov/test-results-action@v1 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: "*TEST-*.xml" | |
- 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 $MAVEN_ARGS 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 $MAVEN_ARGS 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 $MAVEN_ARGS 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 $MAVEN_ARGS $MAVEN_SKIP_ARGS package com.google.cloud.tools:jib-maven-plugin:build -Djib.to.tags=latest,$image_version |