Develop - Build and Deploy Snapshot on develop #96
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
# This builds develop and deploys a snapshot to our repository. | |
# Will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | |
# Docker deployment is manual because that's quite a lot of computation time and we don't want to do it on every push. | |
name: Develop - Build and Deploy Snapshot | |
run-name: Develop - Build and Deploy Snapshot on ${{ github.ref_name }} | |
on: | |
push: | |
branches: [ develop ] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
MVNCMD: mvn -B -U -s ${{ github.workspace }}/.github/settings-istrepo.xml -Ddocker.skip=true | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITHUB_ACTOR: ${{ github.actor }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
cache: maven | |
maven-version: 3.8.7 | |
- name: Dump event context for debugging | |
continue-on-error: true # Debugging output only, and this annoyingly fails when the commit messge has a ( | |
run: | | |
echo '${{ github.event_name }} for ${{ github.ref_type }} ${{ github.ref_name }} or ${{ github.event.ref }}' | |
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push | |
echo 'github.event:' | |
echo '${{ toJSON(github.event) }}' | |
- name: Dump github context | |
continue-on-error: true # Debugging output only, and this annoyingly fails when the commit message has a ( | |
run: | | |
echo '${{ toJSON(github) }}' | |
- name: Set a master password | |
run: | | |
MASTERPWD=$(openssl rand -base64 25) | |
echo "<settingsSecurity> <master>$(mvn --encrypt-master-password "$MASTERPWD")</master></settingsSecurity>" > $HOME/.m2/settings-security.xml | |
# echo "MASTERPWD=\"$MASTERPWD\"" >> $GITHUB_ENV | |
# The master password isn't actually used, but the maven complains otherwise. | |
- name: Git & Maven Status | |
run: | | |
git status --untracked-files --ignored | |
git log -3 --no-color | |
$MVNCMD -version | |
git branch --show-current | |
- name: Mvn Effective POM | |
run: $MVNCMD -P $(git branch --show-current) -N help:effective-pom | |
- name: Mvn Effective Settings | |
run: $MVNCMD -P $(git branch --show-current) -N help:effective-settings | |
- name: Build with Maven | |
# When parent-2:1.7 is active, -P ensureSnapshots will do a sanity check of the version number | |
# We try several times since unfortunately there are sporadic startup problems in the integration tests :-( | |
run: | | |
PROFILES="ensureSnapshots,$(git branch --show-current)" | |
echo "profiles: $PROFILES" | |
( $MVNCMD -P $PROFILES install && echo 1st run success ) || \ | |
( $MVNCMD -P $PROFILES install && echo 2nd run install ) || \ | |
( $MVNCMD -P $PROFILES install && echo 3rd run install ) | |
- name: Sanitycheck version before deploying | |
run: | | |
echo "Version: " | |
$MVNCMD help:evaluate -Dexpression=project.version -q -DforceStdout | |
$MVNCMD help:evaluate -Dexpression=project.version -q -DforceStdout | egrep -- '-SNAPSHOT$' > /dev/null || exit 1 | |
# unfortunately, this would require a snapshot parent if just called from the command line, so we cannot use it: :-( | |
# mvn org.apache.maven.plugins:maven-enforcer-plugin:3.0.0:enforce -Drules=requireSnapshotVersion | |
- name: Deploy with Maven | |
env: | |
NEXUS_BUILD_USER: ${{ secrets.NEXUS_BUILD_USER }} | |
NEXUS_BUILD_PASSWD: ${{ secrets.NEXUS_BUILD_PASSWD }} | |
run: | | |
PROFILES="ensureSnapshots,$(git branch --show-current)" | |
$MVNCMD -P $PROFILES deploy |