-
Notifications
You must be signed in to change notification settings - Fork 4
85 lines (71 loc) · 3.74 KB
/
dockerfile_version_check.yaml
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
name: Dockerfile Version Check
on:
pull_request:
paths:
- "docker/Dockerfile.*"
- "docker/docker-compose.yaml"
jobs:
check-docker-version:
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
# Fetch base branch (e.g., 'main') for comparison
- name: Fetch base branch for comparison
run: |
git fetch origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
# Define a function to check version increment for a given image_name
- name: Check Dockerfile changes and version increment for each image_name
run: |
# List the image_names and their corresponding Dockerfiles
cd docker/
declare -A image_name_to_dockerfile
image_name_to_dockerfile=(
["isaac-sim_ros-humble"]="Dockerfile.isaac-ros"
["airstack-dev"]="Dockerfile.airstack-dev"
# Add more mappings here
)
# Compare the current branch with the base branch
changes=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
# Loop through each image_name and its Dockerfile
for image_name in "${!image_name_to_dockerfile[@]}"; do
dockerfile="${image_name_to_dockerfile[$image_name]}"
# If the Dockerfile for this image_name has been changed
if echo "$changes" | grep -q "$dockerfile"; then
echo "Dockerfile for $image_name has changed."
# Check if the docker-compose.yaml contains an image version for this image_name (vX.Y.Z)
if grep -qE "image: .*/$image_name:.*v[0-9]+\.[0-9]+\.[0-9]+" docker-compose.yaml; then
# Extract the full version (vX.Y.Z)
current_version=$(grep -oP "image: .*/$image_name:v\K[0-9]+\.[0-9]+\.[0-9]+" docker-compose.yaml)
echo "current_version=$current_version"
# Split current version into major, minor, patch
IFS='.' read -r current_major current_minor current_patch <<< "$current_version"
# Check if the image version for this image_name has been incremented in this PR
new_version=$(git diff origin/${{ github.base_ref }}...HEAD -- docker-compose.yaml | grep -oP "image: .*/$image_name:v\K[0-9]+\.[0-9]+\.[0-9]+")
echo "new_version=$new_version"
if [ -z "$new_version" ]; then
echo "::error::Dockerfile for $image_name was modified but image version in docker-compose.yaml was not updated."
exit 1
fi
# Split new version into major, minor, patch
IFS='.' read -r new_major new_minor new_patch <<< "$new_version"
# Check if the new version is higher than the current one
if [ "$new_major" -gt "$current_major" ] || \
([ "$new_major" -eq "$current_major" ] && [ "$new_minor" -gt "$current_minor" ]) || \
([ "$new_major" -eq "$current_major" ] && [ "$new_minor" -eq "$current_minor" ] && [ "$new_patch" -gt "$current_patch" ]); then
echo "Image version for $image_name has been incremented in docker-compose.yaml."
else
echo "::error::Dockerfile for $image_name was modified but the image version in docker-compose.yaml was not correctly incremented."
exit 1
fi
else
echo "::error::No valid image version (vX.Y.Z) found in docker-compose.yaml for $image_name."
exit 1
fi
else
echo "No changes to Dockerfile for $image_name."
fi
done