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

Karimeldegwy/multi version support test 1 #8803

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Feel free to delete sections of the template which do not apply to your PR, or a
- [ ] All source files have up-to-date hashes in the `*.signatures.json` files
- [ ] `sudo make go-tidy-all` and `sudo make go-test-coverage` pass
- [ ] Documentation has been updated to match any changes to the build system
- [ ] If you are adding/removing a .spec file that has multiple-versions supported, please add [@microsoft/cbl-mariner-multi-package-reviewers](https://github.com/orgs/microsoft/teams/cbl-mariner-multi-package-reviewers) team as reviewer [(Eg. golang has 2 versions 1.18, 1.21+)](https://github.com/microsoft/azurelinux/tree/2.0/SPECS/golang)
- [ ] Ready to merge

---
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/check-multi-package-addition-removal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -o pipefail

# Initialize the variable
echo "MULTI_PACKAGE_ADD_REMOVE_DETECTED=false" >> $GITHUB_ENV

# Setup RPM tools
source "$(git rev-parse --show-toplevel)"/toolkit/scripts/rpmops.sh

# Define directories to watch
SPEC_DIRS=("SPECS" "SPECS-EXTENDED")

# Fetch the latest state of the base branch
git fetch origin $GITHUB_BASE_REF

# Function to check for duplicate package names in a directory
check_multi_package_add_remove() {
local DIR=$1
echo "Checking directory: $DIR for duplicates..."
# Array to hold package names
declare -A package_counts
# Loop through .spec files in the directory
for spec_file in "$DIR"/*.spec; do
if [ -e "$spec_file" ]; then # Check if the spec file exists
# Extract package name from the spec file
package_name=$(mariner_rpmspec -q --qf "%{NAME}\n" "$spec_file" 2>/dev/null)
# Increment package name count
((package_counts[$package_name]++))
fi
done
# Check for duplicates
for package in "${!package_counts[@]}"; do
if [ "${package_counts[$package]}" -gt 1 ]; then
echo "Multi-package add/remove of .spec file detected: $package in $DIR"
echo "MULTI_PACKAGE_ADD_REMOVE_DETECTED=true" >> $GITHUB_ENV
fi
done
}

# Loop through directories
for spec_dir in "${SPEC_DIRS[@]}"; do
# List of added or removed spec files in PR
CHANGED_FILES=$(git diff --name-only --diff-filter=AD "origin/$GITHUB_BASE_REF" "HEAD" -- "$GITHUB_WORKSPACE/$spec_dir" | grep '.spec$')

for file in $CHANGED_FILES; do
dir_path=$(dirname "$file")
# Check for duplicates in the directory
check_multi_package_add_remove "$dir_path"
done
done
40 changes: 40 additions & 0 deletions .github/workflows/check-multi-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

name: Check Multi-package

on:
pull_request:
branches:
- karimeldegwy/*
paths:
- 'SPECS/**'
- 'SPECS-EXTENDED/**'

permissions: 'write-all'

jobs:
detect-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0 # Ensures history for all branches is available

- name: Check Multi-package addition/removal
run: |
.github/workflows/check-multi-package-addition-removal.sh
env:
GITHUB_BASE_REF: ${{ github.base_ref }}
GITHUB_WORKSPACE: ${{ github.workspace }}

- name: Add Reviewer if Duplicates Found
if: env.MULTI_PACKAGE_ADD_REMOVE_DETECTED == 'true'
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/microsoft/azurelinux/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d '{"team_reviewers": ["cbl-mariner-multi-package-reviewers"]}'
Loading
Loading