[pre-commit.ci] pre-commit autoupdate (#7) #93
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 | |
concurrency: | |
cancel-in-progress: ${{ ! startsWith(github.ref, 'refs/tags/v') }} | |
group: ci-${{ github.ref_name }}-${{ github.event_name }} | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "v*" | |
pull_request: | |
branches: | |
- main | |
env: | |
ANSIBLE_FORCE_COLOR: "1" | |
PY_COLORS: "1" | |
jobs: | |
trivy: | |
if: github.event_name == 'push' || github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
security-events: write | |
strategy: | |
fail-fast: false | |
matrix: | |
scan-type: | |
- fs | |
- config | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Cache trivy db | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/trivy | |
~/work/temp | |
key: ${{ runner.os }}-trivy-db-${{ hashFiles('**/trivy.yaml') }} | |
- name: Run Trivy vulnerability scanner in fs mode | |
uses: aquasecurity/trivy-action@master | |
with: | |
format: sarif | |
ignore-unfixed: true | |
output: trivy-results.sarif | |
scan-ref: . | |
scan-type: ${{ matrix.scan-type }} | |
severity: CRITICAL,HIGH | |
trivy-config: trivy.yaml | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: "trivy-results.sarif" | |
test: | |
if: github.event_name == 'push' || github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
services: | |
prometheus: | |
image: prom/prometheus:v2.54.1 | |
ports: | |
- 9090:9090 | |
loki: | |
image: grafana/loki:3.2.0 | |
ports: | |
- 3100:3100 | |
strategy: | |
fail-fast: false | |
matrix: | |
role: | |
- haproxy | |
- node_exporter | |
- vmagent | |
- promtail | |
env: | |
VMAGENT_REMOTE_WRITE_URL: http://localhost:9090/api/v1/write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Check ansible | |
run: ansible --version | |
- name: Cache Ansible collections | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.ansible/collections | |
~/.ansible/plugins | |
key: ${{ runner.os }}-ansible-${{ hashFiles('**/requirements.yml') }} | |
- name: Prepare localhost inventory | |
run: | | |
cat << 'EOF' > localhost.yml | |
all: | |
hosts: | |
localhost: | |
ansible_connection: local | |
EOF | |
- name: Install the dependencies | |
run: | | |
ansible-galaxy collection install -r requirements.yml | |
ansible-galaxy collection install ./ | |
- name: Ansible playbook | |
run: ansible-playbook playbook.yml -i localhost.yml -t ${{ matrix.role }} | |
publish: | |
needs: test | |
if: startsWith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Build collection | |
run: ansible-galaxy collection build | |
- id: publish | |
name: Publish to Ansible Galaxy | |
run: | | |
namespace=$(yq -r .namespace galaxy.yml) | |
name=$(yq -r .name galaxy.yml) | |
version=$(yq -r .version galaxy.yml) | |
if [ v"$version" != "${{ github.ref_name }}" ]; then | |
echo "Version in galaxy.yml ($version) does not match git tag (${{ github.ref_name }})" | |
exit 1 | |
fi | |
ansible-galaxy collection publish \ | |
$namespace-$name-$version.tar.gz \ | |
--token ${{ secrets.ANSIBLE_GALAXY_TOKEN }} | |
echo "asset=$namespace-$name-$version.tar.gz" >> $GITHUB_OUTPUT | |
- name: Generate a changelog | |
uses: orhun/git-cliff-action@v4 | |
id: git-cliff | |
with: | |
config: cliff.toml | |
args: --verbose --current | |
env: | |
OUTPUT: CHANGELOG.md | |
- name: Create github release | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh release create ${{ github.ref_name }} -t ${{ github.ref_name }} -F CHANGELOG.md | |
- name: Upload release asset | |
uses: softprops/action-gh-release@v2 | |
with: | |
fail_on_unmatched_files: true | |
files: | | |
${{ steps.publish.outputs.asset }} | |
ansible-lint: | |
if: github.event_name == 'push' || github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Run ansible-lint | |
uses: ansible/ansible-lint@main | |
with: | |
setup_python: "true" | |
requirements_file: requirements.yml | |
sonarcloud: | |
if: github.event_name == 'push' || github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: SonarCloud Scan | |
uses: SonarSource/sonarcloud-github-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |