Skip to content

Merge from mainline #1861

Merge from mainline

Merge from mainline #1861

---
name: CI Devel
on:
workflow_dispatch:
pull_request:
env:
NAMESPACE: cisco
COLLECTION_NAME: dnac
jobs:
sanity:
name: Sanity (Ⓐ${{ matrix.ansible }})
strategy:
matrix:
ansible:
- devel
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v4
with:
path: cisco-en-programmability/dnacenter-ansible
- name: Create directory
run: mkdir -p ./ansible_collections/${{env.NAMESPACE}}
- name: Move repository
run: mv ./cisco-en-programmability/dnacenter-ansible ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- name: Get changed files
id: changed_files
run: |
cd ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
git fetch origin main
git diff --name-only origin/main HEAD > changed_files.txt
echo "Changed files:"
cat changed_files.txt
- name: Run sanity tests
run: |
if [ ! -s changed_files.txt ]; then
echo "No changed files to test."
exit 0
fi
testable_files=""
file_count=0
while IFS= read -r file; do
if [ -f "$file" ]; then
testable_files="$testable_files $file"
file_count=$((file_count + 1))
fi
done < changed_files.txt
echo "Testable files: $file_count"
if [ "$file_count" -eq 0 ]; then
echo "No existing files to test."
exit 0
elif [ "$file_count" -le 50 ]; then
echo "Running targeted sanity tests on $file_count files..."
ansible-test sanity --docker -v --color yes $testable_files
else
echo "Large changeset ($file_count files). Running full sanity tests..."
while true; do echo "Sanity tests still running..."; sleep 60; done &
KEEPALIVE_PID=$!
timeout 55m ansible-test sanity --docker -v --color
EXIT_CODE=$?
kill $KEEPALIVE_PID 2>/dev/null
exit $EXIT_CODE
fi
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Install yamllint
run: pip install --user yamllint
- name: Run yamllint
run: |
if [ ! -s changed_files.txt ]; then
echo "No changed files to lint."
exit 0
fi
lintable_files=""
while IFS= read -r file; do
if [ -f "$file" ] && [[ "$file" == playbooks/*.yml || "$file" == playbooks/*.yaml ]]; then
lintable_files="$lintable_files $file"
fi
done < changed_files.txt
if [ -z "$lintable_files" ]; then
echo "No relevant playbook files to lint."
exit 0
fi
echo "Running yamllint on:$lintable_files"
yamllint -c .yamllint.yml $lintable_files
echo "Yamllint completed successfully."
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}