improve workflow
Infrastructure / Check and run Ansbile playbooks (push) Has been skipped Details

This commit is contained in:
Gleb Koval 2023-09-02 21:35:37 +01:00
parent ab3d2b7ccb
commit f7be5be077
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 22 additions and 56 deletions

View File

@ -6,25 +6,23 @@ on:
push: push:
branches: branches:
- main - main
tags:
- infra/**
paths: paths:
- infra/**-playbook.yaml - infra/**-playbook.yaml
- .github/workflows/infra.yaml - .github/workflows/infra.yaml
env: env:
PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }} DEPLOY: ${{ github.ref == 'refs/heads/main' && ((startsWith(github.event.head_commit.message, '[deploy-all]') && 'all') || ('some')) || 'none' }}
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
jobs: jobs:
check: ansible-playbooks:
name: Check infrastructure definitions name: Check and run Ansbile playbooks
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main' if: github.ref != 'refs/heads/main'
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with:
fetch-depth: ${{ env.DEPLOY == 'some' && 2 || 1 }}
- name: Setup Python - name: Setup Python
uses: actions/setup-python@v4 uses: actions/setup-python@v4
@ -41,58 +39,26 @@ jobs:
for file in $(find . -wholename "*/infra/*-playbook.yaml" -type f); do for file in $(find . -wholename "*/infra/*-playbook.yaml" -type f); do
ansible-playbook --inventory ./inventory --check "$file" ansible-playbook --inventory ./inventory --check "$file"
done done
deploy:
name: Deploy modified infrastructure
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Setup Python - name: Get changed playbooks
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
- name: Get changed files
id: files id: files
if: env.DEPLOY == 'some'
uses: tj-actions/changed-files@v38 uses: tj-actions/changed-files@v38
with:
files: infra/**-playbook.yaml
- name: Run changed playbooks - name: Run changed playbooks
run: | if: env.DEPLOY == 'some'
for file in ${{ steps.files.outputs.all_changed_files }}; do env:
if [[ "$file" == *"-playbook.yaml" ]]; PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }}
then PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
ansible-playbook --inventory ./inventory "$file" PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
fi run: ansible-playbook --inventory ./inventory ${{ steps.files.outputs.all_changed_files }}
done
deploy-all:
name: Deploy all infrastructure
runs-on: ubuntu-latest
if: startsWith(github.event.head_commit.message, '[deploy-all]')
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python - name: Run all playbooks
uses: actions/setup-python@v4 if: env.DEPLOY == 'all'
with: env:
python-version: "3.11" PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }}
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
- name: Install dependencies PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
run: | run: ansible-playbook --inventory ./inventory $(find . -wholename "*/infra/*-playbook.yaml" -type f)
pip3 install -r requirements.txt
ansible-galaxy collection install community.general
- name: Run playbooks
run: |
for file in $(find . -wholename "*/infra/*-playbook.yaml" -type f); do
ansible-playbook --inventory ./inventory "$file"
done