mirror of
https://github.com/ivuorinen/actions.git
synced 2026-03-02 04:53:44 +00:00
* fix(deps): replace step-security/retry with nick-fields/retry * chore(deps): update github action sha pins via pinact * refactor: remove common-retry references from tests and validators * chore: simplify description fallback and update action count * docs: remove hardcoded test counts from memory and docs Replace exact "769 tests" references with qualitative language so these files don't go stale as test count grows.
136 lines
4.3 KiB
YAML
136 lines
4.3 KiB
YAML
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
|
|
# permissions:
|
|
# - contents: write # Required for committing and pushing fixes
|
|
# - security-events: write # Required for uploading SARIF results
|
|
---
|
|
name: Ansible Lint and Fix
|
|
description: 'Lints and fixes Ansible playbooks, commits changes, and uploads SARIF report.'
|
|
author: 'Ismo Vuorinen'
|
|
|
|
branding:
|
|
icon: 'play'
|
|
color: 'green'
|
|
|
|
inputs:
|
|
token:
|
|
description: 'GitHub token for authentication'
|
|
required: false
|
|
default: ''
|
|
username:
|
|
description: 'GitHub username for commits'
|
|
required: false
|
|
default: 'github-actions'
|
|
email:
|
|
description: 'GitHub email for commits'
|
|
required: false
|
|
default: 'github-actions@github.com'
|
|
max-retries:
|
|
description: 'Maximum number of retry attempts for pip install operations'
|
|
required: false
|
|
default: '3'
|
|
|
|
outputs:
|
|
files_changed:
|
|
description: 'Number of files changed by linting'
|
|
value: ${{ steps.lint.outputs.files_changed }}
|
|
lint_status:
|
|
description: 'Linting status (success/failure)'
|
|
value: ${{ steps.lint.outputs.status }}
|
|
sarif_path:
|
|
description: 'Path to SARIF report file'
|
|
value: 'ansible-lint.sarif'
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Validate Inputs
|
|
id: validate
|
|
uses: ivuorinen/actions/validate-inputs@5cc7373a22402ee8985376bc713f00e09b5b2edb
|
|
with:
|
|
action-type: 'ansible-lint-fix'
|
|
token: ${{ inputs.token }}
|
|
email: ${{ inputs.email }}
|
|
username: ${{ inputs.username }}
|
|
max-retries: ${{ inputs.max-retries }}
|
|
|
|
- name: Check for Ansible Files
|
|
id: check-files
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
|
|
# Check for both .yml and .yaml files
|
|
if find . \( -name "*.yml" -o -name "*.yaml" \) -type f | grep -q .; then
|
|
echo "files_found=true" >> "$GITHUB_OUTPUT"
|
|
echo "Found Ansible files, proceeding with lint and fix."
|
|
else
|
|
echo "files_found=false" >> "$GITHUB_OUTPUT"
|
|
echo "No Ansible files found. Skipping lint and fix."
|
|
fi
|
|
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@71cf2267d89c5cb81562390fa70a37fa40b1305e # v6-beta
|
|
with:
|
|
token: ${{ inputs.token || github.token }}
|
|
|
|
- name: Setup Python
|
|
if: steps.check-files.outputs.files_found == 'true'
|
|
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
|
with:
|
|
python-version: '3.14'
|
|
cache: 'pip'
|
|
|
|
- name: Install ansible-lint
|
|
id: install-ansible-lint
|
|
if: steps.check-files.outputs.files_found == 'true'
|
|
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
|
|
with:
|
|
timeout_minutes: 5
|
|
max_attempts: ${{ inputs.max-retries }}
|
|
command: 'pip install ansible-lint==6.22.1'
|
|
|
|
- name: Run ansible-lint
|
|
if: steps.check-files.outputs.files_found == 'true'
|
|
id: lint
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
|
|
# Run ansible-lint and capture exit code
|
|
if ansible-lint --write --parseable-severity --format sarif > ansible-lint.sarif; then
|
|
lint_exit_code=0
|
|
else
|
|
lint_exit_code=$?
|
|
fi
|
|
|
|
# Count files changed by linting
|
|
files_changed=$(git diff --name-only | wc -l | tr -d '[:space:]')
|
|
|
|
# Determine lint status
|
|
if [ "$lint_exit_code" -eq 0 ]; then
|
|
lint_status="success"
|
|
else
|
|
lint_status="failure"
|
|
fi
|
|
|
|
# Write outputs to GITHUB_OUTPUT
|
|
printf 'files_changed=%s\n' "$files_changed" >> "$GITHUB_OUTPUT"
|
|
printf 'status=%s\n' "$lint_status" >> "$GITHUB_OUTPUT"
|
|
|
|
# Exit with the original ansible-lint exit code
|
|
exit "$lint_exit_code"
|
|
|
|
- name: Commit Fixes
|
|
if: steps.check-files.outputs.files_found == 'true'
|
|
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0
|
|
with:
|
|
commit_message: 'style: apply ansible lint fixes'
|
|
commit_user_name: ${{ inputs.username }}
|
|
commit_user_email: ${{ inputs.email }}
|
|
|
|
- name: Upload SARIF Report
|
|
if: steps.check-files.outputs.files_found == 'true'
|
|
uses: github/codeql-action/upload-sarif@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
|
|
with:
|
|
sarif_file: ansible-lint.sarif
|