-
Notifications
You must be signed in to change notification settings - Fork 23
113 lines (99 loc) · 3.85 KB
/
dev-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# .github/workflows/dependency-check.yml
name: Dependency Check
on:
workflow_dispatch:
inputs:
REPO_URL:
description: '<github-account-name>/<repo-name>'
required: true
type: string
REPO_BRANCH:
required: true
type: string
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
with:
repository: ${{ inputs.REPO_URL }}
ref: ${{ inputs.REPO_BRANCH }}
- name: Setup branch and env
run: |
# Strip git ref prefix from version
echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
- 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: "${{ github.event_name != 'pull_request' && failure() }}" # Pick up events even if the job fails or is canceled.