From 89ae41fdc389cac221c73046f37e5fcc2fd4c348 Mon Sep 17 00:00:00 2001 From: Andrew Jong Date: Thu, 19 Dec 2024 17:49:27 -0500 Subject: [PATCH] Updated ci workflow to check that PROJECT_VERSION has been incremented --- .../workflows/dockerfile_version_check.yaml | 96 ------------------- .github/workflows/main_version_increment.yaml | 42 ++++++++ 2 files changed, 42 insertions(+), 96 deletions(-) delete mode 100644 .github/workflows/dockerfile_version_check.yaml create mode 100644 .github/workflows/main_version_increment.yaml diff --git a/.github/workflows/dockerfile_version_check.yaml b/.github/workflows/dockerfile_version_check.yaml deleted file mode 100644 index eb828cf4..00000000 --- a/.github/workflows/dockerfile_version_check.yaml +++ /dev/null @@ -1,96 +0,0 @@ -name: Dockerfile Version Check - -on: - pull_request: - paths: - - "**/Dockerfile.*" - - "**/docker-compose.yaml" - -jobs: - check-docker-version: - runs-on: ubuntu-latest - - steps: - # Checkout the code - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - sparse-checkout: | - simulation/isaac-sim/docker - robot/docker - ground_control_station/docker - - # 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 - declare -A image_name_to_dockerfile - image_name_to_dockerfile=( - ["isaac-sim_ros-humble"]="simulation/isaac-sim/docker/Dockerfile.isaac-ros" - ["airstack-dev"]="robot/docker/Dockerfile.airstack-dev" - # Add more mappings here - ) - declare -A image_name_to_dockercompose - image_name_to_dockercompose=( - ["isaac-sim_ros-humble"]="simulation/isaac-sim/docker/docker-compose.yaml" - ["airstack-dev"]="robot/docker/docker-compose.yaml" - # 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]}" - dockercomposefile="${image_name_to_dockercompose[$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]+" $dockercomposefile; then - # Extract the full version (vX.Y.Z) - version_on_main=$(git show origin/${{ github.base_ref }}:$dockercomposefile | grep -oP "image: .*/$image_name:v\K[0-9]+\.[0-9]+\.[0-9]+") - echo "version_on_main=$version_on_main" - - # Split current version into major, minor, patch - IFS='.' read -r current_major current_minor current_patch <<< "$version_on_main" - - # Check if the image version for this image_name has been incremented in this PR - version_this_branch=$(grep -oP "image: .*/$image_name:v\K[0-9]+\.[0-9]+\.[0-9]+" $dockercomposefile) - - if [ -z "$version_this_branch" ]; then - echo "::error::Dockerfile for $image_name was modified but image version in $dockercomposefile was not updated." - exit 1 - fi - - echo "version_this_branch=$version_this_branch" - - # Split new version into major, minor, patch - IFS='.' read -r new_major new_minor new_patch <<< "$version_this_branch" - - # 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 $dockercomposefile." - else - echo "::error::Dockerfile for $image_name was modified but the image version in $dockercomposefile was not correctly incremented." - exit 1 - fi - else - echo "::error::No valid image version (vX.Y.Z) found in $dockercomposefile for $image_name." - exit 1 - fi - else - echo "No changes to Dockerfile for $image_name." - fi - done diff --git a/.github/workflows/main_version_increment.yaml b/.github/workflows/main_version_increment.yaml new file mode 100644 index 00000000..6440dbd8 --- /dev/null +++ b/.github/workflows/main_version_increment.yaml @@ -0,0 +1,42 @@ +name: Check Project Version Increment + +on: + pull_request: + branches: [main] + +jobs: + check_version: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Get Current Version from PR + run: | + PR_VERSION=$(grep 'PROJECT_VERSION=' .env | cut -d'=' -f2 | tr -d '"') + echo "PR_VERSION=$PR_VERSION" >> $GITHUB_ENV + + - name: Get Previous Version from Main + run: | + git fetch origin main + PREV_VERSION=$(git show origin/main:.env | grep 'PROJECT_VERSION=' | cut -d'=' -f2 | tr -d '"') + echo "PREV_VERSION=$PREV_VERSION" >> $GITHUB_ENV + + - name: Validate Version Increment + run: | + compare_versions() { + IFS='.' read -r -a CUR <<< "$PR_VERSION" + IFS='.' read -r -a PREV <<< "$PREV_VERSION" + + if (( CUR[0] > PREV[0] )); then exit 0; fi + if (( CUR[0] == PREV[0] && CUR[1] > PREV[1] )); then exit 0; fi + if (( CUR[0] == PREV[0] && CUR[1] == PREV[1] && CUR[2] > PREV[2] )); then exit 0; fi + echo "ERROR: PROJECT_VERSION must be incremented semantically. Current: $PR_VERSION, Previous: $PREV_VERSION" + exit 1 + } + compare_versions + + - name: Report Success + run: | + echo "PROJECT_VERSION successfully incremented: $PR_VERSION"