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