kovalhome/.github/workflows/infra.yaml

64 lines
1.9 KiB
YAML
Raw Normal View History

name: Infrastructure
on:
pull_request:
branches:
- main
push:
branches:
- main
paths:
- infra/**-playbook.yaml
- .github/workflows/infra.yaml
2023-09-02 19:18:21 +00:00
env:
2023-09-02 20:35:37 +00:00
DEPLOY: ${{ github.ref == 'refs/heads/main' && ((startsWith(github.event.head_commit.message, '[deploy-all]') && 'all') || ('some')) || 'none' }}
2023-09-02 19:18:21 +00:00
jobs:
2023-09-02 20:35:37 +00:00
ansible-playbooks:
name: Check and run Ansbile playbooks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
2023-09-02 20:35:37 +00:00
with:
fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
pip3 install -r requirements.txt
ansible-galaxy collection install community.general
2023-09-02 18:12:34 +00:00
- name: Check playbooks
run: |
2023-09-02 19:11:44 +00:00
for file in $(find . -wholename "*/infra/*-playbook.yaml" -type f); do
ansible-playbook --inventory ./inventory --check "$file"
done
2023-09-02 20:35:37 +00:00
- name: Get changed playbooks
id: files
2023-09-02 20:35:37 +00:00
if: env.DEPLOY == 'some'
uses: tj-actions/changed-files@v38
2023-09-02 18:12:34 +00:00
with:
2023-09-02 20:35:37 +00:00
files: infra/**-playbook.yaml
2023-09-02 18:12:34 +00:00
2023-09-02 20:35:37 +00:00
- name: Run changed playbooks
if: env.DEPLOY == 'some'
env:
PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }}
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
run: ansible-playbook --inventory ./inventory ${{ steps.files.outputs.all_changed_files }}
2023-09-02 18:12:34 +00:00
2023-09-02 20:35:37 +00:00
- name: Run all playbooks
if: env.DEPLOY == 'all'
env:
PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }}
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
run: ansible-playbook --inventory ./inventory $(find . -wholename "*/infra/*-playbook.yaml" -type f)