Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOSIP-29967] Added dev-check.yml #37

Merged
merged 19 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/dev-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# .github/workflows/dependency-check.yml

name: Dependency Check

on:
workflow_call:
inputs:
MESSAGE:
description: 'Triggered For Dependency Check'
required: false
type: string
default: 'dependency check'
SKIP_DEPENDENCIES:
description: 'List of dependencies to be skipped'
required: false
type: string
default: ''
DEPENDENCY_VERSIONS:
description: 'Specify versions for specific dependencies'
required: false
type: string
default: ''

secrets:
SLACK_WEBHOOK_URL:
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 xmlstarlet and xmllint
run: |
sudo apt-get update
sudo apt-get install xmlstarlet libxml2-utils

- name: Check if dependencies are marked outside the current development version in the POM file.
run: |
# Find all pom.xml files
pomfiles=$(find ./ -type f -name "*pom.xml")

skipped_dependencies=${{ inputs.SKIP_DEPENDENCIES }}
IFS=' ' read -ra dependency_versions <<< "$DEPENDENCY_VERSIONS"

# Function to resolve a version and check if it's marked outside the current development version
resolve_version() {
local version=$1
local pomfile=$2

if [[ " ${skipped_dependencies[@]} " =~ " $version " ]]; then
echo "Skipping VERSION $version based on user input (SKIP_DEPENDENCIES)"
else
output=$(grep -oPm1 "(?<=<${version}>)[^<]+" "$pomfile" || echo "ERROR")

if [[ $output == "ERROR" ]]; then
echo "VERSION $version not found; EXITING"
exit 1
elif [[ $output != *"-SNAPSHOT"* ]]; then
if [[ ${dependency_versions["$version"]} ]]; then
expected_version="${dependency_versions["$version"]}"
if [[ "$output" != *"$expected_version"* ]]; then
echo "Mismatch for VERSION $version; Expected: $expected_version, Actual: $output; EXITING"
exit 1
fi
else
echo "VERSION '$version' is marked outside the current development version; EXITING"
exit 1
fi
fi
fi
}

for pomfile in $pomfiles; do
echo "===================================== $pomfile =========================================="
# Use grep to extract dependency versions
for v in "${dependency_versions[@]}"; do
echo -e "\nv=$v"
resolve_version "$v" "$pomfile"
done
done

- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,author,commit,workflow,job # selectable (default: repo,message)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: failure() # Pick up events even if the job fails or is canceled.