-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44d4c13
commit 05519e0
Showing
1 changed file
with
189 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,192 @@ on: | |
- cron: '*/60 * * * *' | ||
|
||
jobs: | ||
check-deps: | ||
uses: mekomsolutions/shared-github-workflow/.github/workflows/maven-check-deps-build-publish.yml@main | ||
with: | ||
java-version: "8" | ||
maven-args: "-P prod -DskipTests=true" | ||
secrets: | ||
NEXUS_USERNAME: ${{ secrets.MEKOM_NEXUS_USERNAME }} | ||
NEXUS_PASSWORD: ${{ secrets.MEKOM_NEXUS_PASSWORD }} | ||
check-for-dependency-changes: | ||
outputs: | ||
hasChanged: ${{ steps.compareDependencyChanges.outputs.hasChanged }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 8 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 8 | ||
distribution: 'temurin' | ||
cache: 'maven' | ||
|
||
- name: Set settings.xml | ||
uses: s4u/[email protected] | ||
with: | ||
servers: | | ||
[{ | ||
"id": "mks-private-repo", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-private", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-public-snapshots", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-public-releases", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-private-snapshots", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-private-releases", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}] | ||
- name: Check for dependency changes | ||
id: compareDependencyChanges | ||
shell: bash | ||
run: | | ||
#!/usr/bin/env bash | ||
set -e | ||
# Download the remote dependency report | ||
remoteRepoUrl=https://nexus.mekomsolutions.net/repository/maven-public | ||
# Get the list of sub-modules | ||
modules=$(mvn -q -Pprod --also-make exec:exec -Dexec.executable="echo" -Dexec.args='${project.build.directory}') | ||
echo "Modules to check" | ||
echo "$modules" | ||
# Build the local dependency report | ||
echo "Compile a local dependency report..." | ||
mvn clean compile -P prod | ||
# Iterate over each module | ||
for module in $modules; do | ||
modulePath=$(echo $module | sed 's/\\/\//g') | ||
# Navigate to the module directory | ||
cd $(dirname $modulePath) | ||
# Get the groupId, artifactId, and version | ||
groupId=$(mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout) | ||
artifactId=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout) | ||
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | ||
classifier=$(mvn help:evaluate -Dexpression=dependencyReportClassifier -q -DforceStdout) | ||
artifact="${groupId}":"${artifactId}":"${version}":txt:"${classifier}" | ||
# Module details | ||
echo "Module: $module" | ||
echo "GroupId: $groupId" | ||
echo "ArtifactId: $artifactId" | ||
echo "Version: $version" | ||
echo "" | ||
filename=${artifactId}-${version}-${classifier}.txt | ||
absolutePath=/tmp/$filename | ||
# Remove previous file if any | ||
rm -f "${absolutePath}" | ||
# Fetch the remote dependency report | ||
echo "Fetch remote dependency report..." | ||
set +e | ||
mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.0:get -DremoteRepositories=${remoteRepoUrl} -Dartifact=${artifact} -Dtransitive=false | ||
mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.0:copy -Dartifact=${artifact} -DoutputDirectory=/tmp/ -Dmdep.useBaseVersion=true | ||
set -e | ||
# If no dependency report was fetched, create an empty one. | ||
if [ ! -f "$absolutePath" ]; then | ||
echo "Remote dependency file is not found at '${absolutePath}'. Creating an empty one and continue." | ||
touch "${absolutePath}" | ||
else | ||
echo "Remote dependency file saved at '${absolutePath}'." | ||
fi | ||
# Compare the 2 files. Will exit with 0 if no change, 1 if changes | ||
echo "Compare both dependency reports..." | ||
set +e | ||
if [ -f ./target/"${filename}" ]; then | ||
diff "${absolutePath}" ./target/"${filename}" | ||
diff_rc=$? | ||
if [ $diff_rc -eq 0 ]; then | ||
echo "No dependency change. Exit (0)" | ||
elif [ $diff_rc -eq 1 ]; then | ||
echo "One or more dependency has changed. Exit (1)" | ||
else | ||
echo "Unknown error occured." | ||
fi | ||
# Export result code to be used in later steps of the GitHub worklow. | ||
set +e | ||
echo ::set-env name=hasChanged::$diff_rc | ||
echo hasChanged=$diff_rc >> "$GITHUB_OUTPUT" | ||
set -e | ||
else | ||
echo "File ./target/${filename} does not exist." | ||
fi | ||
set -e | ||
# Navigate back to the parent directory | ||
cd - | ||
done | ||
exit 0 | ||
build: | ||
needs: check-for-dependency-changes | ||
if: ${{ needs.check-for-dependency-changes.outputs.hasChanged == '1' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK ${{ inputs.java-version }} | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: ${{ inputs.java-version }} | ||
distribution: ${{ inputs.java-distribution }} | ||
cache: 'maven' | ||
|
||
- name: Set settings.xml | ||
uses: s4u/[email protected] | ||
with: | ||
servers: | | ||
[{ | ||
"id": "mks-private-repo", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-public-snapshots", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-public-releases", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-private-snapshots", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}, | ||
{ | ||
"id": "mks-nexus-private-releases", | ||
"username": "${{ secrets.MEKOM_NEXUS_USERNAME }}", | ||
"password": "${{ secrets.MEKOM_NEXUS_PASSWORD }}" | ||
}] | ||
- name: Build | ||
run: "mvn --batch-mode clean package ${{ inputs.maven-args }}" |