-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rakshitha650 <[email protected]>
- Loading branch information
1 parent
c263025
commit b5246bd
Showing
1 changed file
with
68 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Manual Workflow To Check Dependencies | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
MESSAGE: | ||
description: 'Triggered For Dependency Check' | ||
required: false | ||
default: 'dependency check' | ||
SNAPSHOT_TAG: | ||
description: 'tag to be find' | ||
required: true | ||
|
||
jobs: | ||
check-dependencies: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '11' | ||
|
||
- name: Install xmlstartlet and xmllint | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install xmlstarlet libxml2-utils | ||
- name: Check if the *SNAPSHOT is present in the dependency section of the POM file. | ||
run: | | ||
# Find all pom.xml files | ||
pomfiles=$(find ./ -type f -name "*pom.xml") | ||
snapshot_dependencies=() | ||
# Function to resolve a version and add it to snapshot_dependencies if it's a SNAPSHOT | ||
resolve_version() { | ||
local version=$1 | ||
local pomfile=$2 | ||
output=$(mvn help:evaluate -Dexpression=$version -f $pomfile | grep -vE "INFO|WARNING") | ||
if [[ $output == *"ERROR"* ]]; then | ||
echo "VERSION $version not found; EXITING" | ||
exit 1 | ||
elif [[ $output == *"-SNAPSHOT"* ]]; then | ||
echo "Adding VERSION $version to snapshot_dependencies list" | ||
snapshot_dependencies+=("\n$pomfile: <$version>$output</$version>") | ||
fi | ||
} | ||
for pomfile in $pomfiles; do | ||
echo "===================================== $pomfile ==========================================" | ||
# Use xmlstarlet to extract dependency versions | ||
dv=$(xmlstarlet sel -N s="http://maven.apache.org/POM/4.0.0" -t -v "//s:project/s:dependencies/s:dependency/s:version" $pomfile | grep '[${}]' | sed 's/[${}]//g') | ||
echo "Dependency versions in $pomfile = $dv" | sed -z 's/\n/ /g' | ||
for v in $dv; do | ||
echo -e "\nv=$v" | ||
resolve_version "$v" "$pomfile" | ||
done | ||
done | ||
if [[ ${#snapshot_dependencies[@]} -gt 0 ]]; then | ||
echo -e "Snapshot dependencies found: ${snapshot_dependencies[*]}" | ||
exit 1 | ||
fi |