CI #1300
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
paths-ignore: | |
- '.github/**' | |
- '*.md' | |
- '.gitignore' | |
- 'roles/settings/**' | |
pull_request: | |
paths-ignore: | |
- '*.md' | |
- '.gitignore' | |
- 'roles/settings/**' | |
workflow_dispatch: | |
jobs: | |
ansible-lint: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install packages | |
run: pip install "ansible>=9.0.0,<10.0.0" ansible-lint==6.22.2 jmespath | |
- name: Run ansible linter | |
run: ansible-lint | |
- name: Run salty linter | |
run: python3 ./scripts/salty-linter.py ./roles | |
check-entries: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check Missing Entries | |
run: ./scripts/check_missing_entries.sh | |
add-contributors: | |
runs-on: ubuntu-22.04 | |
if: github.ref == 'refs/heads/master' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: BobAnkh/add-contributors@master | |
with: | |
REPO_NAME: 'saltyorg/Sandbox' | |
CONTRIBUTOR: '### Contributors' | |
COLUMN_PER_ROW: '6' | |
ACCESS_TOKEN: ${{ secrets.GH_TOKEN }} | |
IMG_WIDTH: '100' | |
FONT_SIZE: '14' | |
PATH: '/README.md' | |
COMMIT_MESSAGE: 'docs(README): update contributors' | |
AVATAR_SHAPE: 'square' | |
find-roles: | |
runs-on: ubuntu-22.04 | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: set-matrix | |
run: echo "matrix={\"roles\":[$(awk '/# Apps Start/{flag=1;next}/# Apps End/{flag=0}flag' sandbox.yml | awk '!/#/' | awk -F'[][]' '{print $2}' | tr '\n' ',' | sed 's/,*$//' | awk -F',' '{ for( i=1; i<=NF; i++ ) print $i }' | awk '{ gsub(/ /,""); print }'| sort -u | awk -vORS=, '{ print $1 }' | sed 's/,$/\n/')]}" >> $GITHUB_OUTPUT | |
install: | |
name: '${{ matrix.roles }}' | |
needs: [ansible-lint, check-entries, find-roles] | |
runs-on: ubuntu-22.04 | |
strategy: | |
matrix: ${{ fromJson(needs.find-roles.outputs.matrix) }} | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Dependencies | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 10 | |
max_attempts: 3 | |
shell: bash | |
command: curl https://raw.githubusercontent.com/saltyorg/sb/master/sb_install.sh --output sb_install.sh && sudo bash sb_install.sh -v && ansible --version | |
- name: Chown /srv/git | |
run: sudo chown -R runner:runner /srv/git | |
- name: Edit accounts.yml | |
run: cd /srv/git/saltbox && sed -i 's/seed/runner/g' accounts.yml | |
- name: Create, chown and chmod /tmp/ansible | |
run: sudo mkdir /tmp/ansible && sudo chown -R runner:runner /tmp/ansible && chmod 0777 /tmp/ansible | |
- name: Syntax Check | |
run: cd /srv/git/saltbox && sudo ansible-playbook saltbox.yml --syntax-check | |
- name: Install Saltbox Core | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 30 | |
max_attempts: 3 | |
shell: bash | |
command: cd /srv/git/saltbox && sudo ansible-playbook saltbox.yml --tags "core" --skip-tags "settings" --extra-vars '{"continuous_integration":true}' | |
- name: Copy default configuration | |
run: cp -n defaults/ansible.cfg.default ansible.cfg && cp -n defaults/settings.yml.default settings.yml | |
- name: Install ${{ matrix.roles }} | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 30 | |
max_attempts: 3 | |
shell: bash | |
command: sudo ansible-playbook sandbox.yml --tags "${{ matrix.roles }}" --skip-tags "settings" --extra-vars '{"continuous_integration":true}' | |
webhook: | |
name: 'webhook' | |
runs-on: self-hosted | |
needs: install | |
if: always() && github.event_name != 'pull_request' && github.event.repository.fork == false | |
steps: | |
- name: Determine Workflow Conclusion | |
run: | | |
max_attempts=5 | |
page=1 | |
declare -A conclusion_counts | |
for status in success failure cancelled skipped; do | |
conclusion_counts[$status]=0 | |
done | |
while :; do | |
success=false | |
for attempt in $(seq 1 $max_attempts); do | |
echo "Attempt $attempt of $max_attempts for page $page" | |
# Additional diagnostics | |
echo "Fetching job conclusions for page: $page" | |
response_with_headers=$(curl -sS -I -H "Authorization: token ${{ secrets.GH_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs?page=$page&per_page=100") | |
link_header=$(echo "$response_with_headers" | grep -i '^Link:' | tr -d '\r') | |
echo "Link header: $link_header" # Diagnostic output | |
if [ -z "$link_header" ] && [ $page -eq 1 ]; then | |
echo "No Link header found, possibly only a single page of results." | |
fi | |
response=$(curl -sS -H "Authorization: token ${{ secrets.GH_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs?page=$page&per_page=100") | |
if [ $? -eq 0 ]; then | |
echo "API Request successful." | |
else | |
echo "API Request failed, retrying..." | |
sleep $((attempt * 2)) | |
continue | |
fi | |
echo "Processing job conclusions..." | |
processed_conclusions=$(echo "$response" | jq -r '.jobs[].conclusion' || echo "jq command failed") | |
if [ "$processed_conclusions" = "jq command failed" ]; then | |
echo "Failed to process job conclusions with jq." | |
exit 1 | |
fi | |
while read -r line; do | |
((conclusion_counts[$line]++)) | |
done <<< "$processed_conclusions" | |
success=true | |
break # Successful fetch, proceed to next page | |
done | |
if [ "$success" = false ]; then | |
echo "Failed to fetch job conclusions after $max_attempts attempts." | |
exit 1 | |
fi | |
# Diagnostic output for checking next page logic | |
if echo "$link_header" | grep -q 'rel="next"'; then | |
echo "Found next page, proceeding..." | |
page=$((page + 1)) | |
else | |
echo "No more pages to fetch, finalizing..." | |
break | |
fi | |
done | |
echo "Processing workflow conclusion based on job statuses..." | |
# Determine overall workflow conclusion | |
if [ ${conclusion_counts[cancelled]} -gt 0 ]; then | |
echo "Some jobs were cancelled." | |
WORKFLOW_CONCLUSION="cancelled" | |
elif [ ${conclusion_counts[failure]} -gt 0 ]; then | |
echo "Some jobs failed." | |
WORKFLOW_CONCLUSION="failure" | |
elif [ ${conclusion_counts[success]} -gt 0 ]; then | |
echo "All jobs succeeded." | |
WORKFLOW_CONCLUSION="success" | |
else | |
echo "Defaulting to failure due to uncertain job conclusions." | |
WORKFLOW_CONCLUSION="failure" | |
fi | |
echo "WORKFLOW_CONCLUSION=$WORKFLOW_CONCLUSION" >> $GITHUB_ENV | |
- uses: sarisia/actions-status-discord@v1 | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
status: ${{ env.WORKFLOW_CONCLUSION }} |