Skip to content

Enable branch-specific versions in internal maven repo (#44) #126

Enable branch-specific versions in internal maven repo (#44)

Enable branch-specific versions in internal maven repo (#44) #126

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: NetLicensing Client - CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
build:
runs-on: [self-hosted]
container: maven:3-amazoncorretto-17
env:
# This is needed, as java doesn't respect the environment variable $HOME, but gets the
# user home by other means from the system. The default user in the above container is
# 'root' with the home at '/root', while GitHub runner overrides $HOME to the mounted
# '/github/home'. As a result, maven uses the ~/.m2 at a different location than assumed
# by the standard GitHub actions like 'actions/setup-java', causing caching of the maven
# local repository not working.
# TODO(2K): This can be better solved by preparing a custom image for the container.
MAVEN_OPTS: -Duser.home=/github/home
strategy:
matrix:
java-version: [11, 17]
include:
- java-version: 11
mvn-goal: deploy
- java-version: 17
mvn-goal: verify
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
distribution: 'adopt'
cache: maven
- name: Prepare maven settings.xml
run: |
mkdir -p ~/.m2
cat << EOF >~/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nlic-snapshots</id>
<username>${{ secrets.SNAPSHOTS_USER }}</username>
<password>${{ secrets.SNAPSHOTS_PASS }}</password>
</server>
</servers>
</settings>
EOF
- name: Calculate branch suffix
run: |
if [ "$GITHUB_REF_NAME" = "master" ]
then
# No suffix when running against "master" branch
BRANCH_SUFFIX=
else
# When running from pull request, use "-pr-<N>" suffix, where <N> is a PR number
BRANCH_SUFFIX=-pr-${GITHUB_REF_NAME//\/merge/}
fi
echo "Branch suffix: '$BRANCH_SUFFIX'"
echo "BRANCH_SUFFIX=$BRANCH_SUFFIX" >> "$GITHUB_ENV"
- name: Build with Maven
run: mvn -B clean ${{ matrix.mvn-goal }} -Drepo.snapshots.url=${{ secrets.SNAPSHOTS_URL }} -Dsha1=$BRANCH_SUFFIX
- name: Run Demo App
run: |
ls -la NetLicensingClient-demo/target/
java -jar NetLicensingClient-demo/target/netlicensing-client-demo.jar -r CallEveryAPIMethod