Files
algo/.github/workflows/lint.yml
T
ba7297268a Simplify codebase: modernize loops, split templates, improve CI (#14889)
* Simplify codebase: modernize loops, split templates, improve CI

This PR consolidates several simplification phases:

## Ansible Modernization
- Modernize `with_items` to `loop` across ~50 task files
- Add OS detection facts (is_ubuntu, os_family_lowercase)
- Condense inline YAML syntax where appropriate

## Template Splitting
- Split 568-line dnscrypt-proxy.toml.j2 into focused partials:
  - global.toml.j2 (core settings)
  - sources.toml.j2 (resolver sources)
  - filters.toml.j2 (blocking rules)
  - cache.toml.j2 (caching config)

## CI Workflow Improvements
- Create setup-algo composite action for shared CI setup
- Re-enable integration tests with health checks
- Fix smart-tests.yml silent lint failures (remove || true)
- Use env variables for GitHub SHAs (security)

## server.yml Async Simplification
- Reorganize VPN service configuration with clear sections
- Add performance_parallel_services toggle
- Simplify status display from json_query to inline conditionals
- Keep services explicit for readability

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix with_items to loop conversion: preserve list flattening

with_items automatically flattens nested lists, but loop does NOT.
The mechanical conversion broke iteration over list variables.

Wrong:
  loop:
    - "{{ users }}"  # ['alice', 'bob'] treated as ONE item

Fixed:
  loop: "{{ users }}"  # Iterates over alice, bob correctly

For combined lists (users + server):
  loop: "{{ users + [IP_subject_alt_name] }}"

Fixes IPsec certificate generation creating files named literally
'['alice', 'bob'].key' instead of separate alice.key and bob.key.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix integration test: use strongswan-starter service name on Ubuntu 20.04+

The StrongSwan service is named 'strongswan-starter' on Ubuntu 20.04+,
not 'strongswan'. The test was checking the wrong service name, causing
false failures even when StrongSwan was actually running.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix IPsec path issues: remove trailing slashes and fix test paths

1. Remove trailing slashes from ipsec_config_path and ipsec_pki_path
   in roles/strongswan/defaults/main.yml (causes double slashes)

2. Fix integration test to check correct subdirectories:
   - .p12 files are in ipsec/manual/
   - .mobileconfig files are in ipsec/apple/

3. Fix strongswan service name check (strongswan-starter on Ubuntu 20.04+)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-28 04:28:59 -05:00

128 lines
3.8 KiB
YAML

---
name: Lint
'on': [push, pull_request]
permissions:
contents: read
jobs:
ansible-lint:
name: Ansible linting
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@c2d88d3ecc89a9ef08eebf45d9637801dcee7eb5 # v5.0.1
with:
persist-credentials: false
- name: Setup Algo environment
uses: ./.github/actions/setup-algo
with:
install-ansible-collections: 'true'
- name: Run ansible-lint
run: |
uv run --with ansible-lint ansible-lint .
- name: Run playbook dry-run check (catch runtime issues)
run: |
# Test main playbook logic without making changes
# This catches filter warnings, collection issues, and runtime errors
uv run ansible-playbook main.yml --check --connection=local \
-e "server_ip=test" \
-e "server_name=ci-test" \
-e "IP_subject_alt_name=192.168.1.1" \
|| echo "Dry-run check completed with issues - review output above"
yaml-lint:
name: YAML linting
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@c2d88d3ecc89a9ef08eebf45d9637801dcee7eb5 # v5.0.1
with:
persist-credentials: false
- name: Setup uv environment
uses: ./.github/actions/setup-uv
- name: Run yamllint
run: uv run --with yamllint yamllint -c .yamllint .
python-lint:
name: Python linting
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@c2d88d3ecc89a9ef08eebf45d9637801dcee7eb5 # v5.0.1
with:
persist-credentials: false
- name: Setup Algo environment
uses: ./.github/actions/setup-algo
- name: Run ruff
run: |
# Fast Python linter
uv run --with ruff ruff check .
shellcheck:
name: Shell script linting
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@c2d88d3ecc89a9ef08eebf45d9637801dcee7eb5 # v5.0.1
with:
persist-credentials: false
- name: Setup Algo environment
uses: ./.github/actions/setup-algo
with:
install-shellcheck: 'true'
- name: Run shellcheck
run: |
# Check all shell scripts, not just algo and install.sh
find . -type f -name "*.sh" -not -path "./.git/*" -exec shellcheck {} \;
powershell-lint:
name: PowerShell script linting
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@c2d88d3ecc89a9ef08eebf45d9637801dcee7eb5 # v5.0.1
with:
persist-credentials: false
- name: Install PowerShell
run: |
# Install PowerShell Core
wget -q https://github.com/PowerShell/PowerShell/releases/download/v7.4.0/powershell_7.4.0-1.deb_amd64.deb
sudo dpkg -i powershell_7.4.0-1.deb_amd64.deb
sudo apt-get install -f
- name: Install PSScriptAnalyzer
run: |
pwsh -Command "Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser"
- name: Run PowerShell syntax check
run: |
# Check syntax by parsing the script
pwsh -NoProfile -NonInteractive -Command "
try {
\$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path './algo.ps1' -Raw), [ref]\$null)
Write-Host '✓ PowerShell syntax check passed'
} catch {
Write-Error 'PowerShell syntax error: ' + \$_.Exception.Message
exit 1
}
"
- name: Run PSScriptAnalyzer
run: |
pwsh -Command "
\$results = Invoke-ScriptAnalyzer -Path './algo.ps1' -Severity Warning,Error
if (\$results.Count -gt 0) {
\$results | Format-Table -AutoSize
exit 1
} else {
Write-Host '✓ PSScriptAnalyzer check passed'
}
"