kovalhome/.github/workflows/infra.yaml

90 lines
2.3 KiB
YAML
Raw Normal View History

name: Infrastructure
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- infra/**
paths:
- infra/**-playbook.yaml
- .github/workflows/infra.yaml
jobs:
check:
name: Check infrastructure definitions
runs-on: ubuntu-latest
2023-09-02 18:12:34 +00:00
if: github.ref != 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v3
- 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: |
find . -wholename "*/infra/*-playbook.yaml" -type f -exec ansible-playbook --inventory ./inventory --check {} \;
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
id: files
uses: tj-actions/changed-files@v38
- name: Run changed playbooks
run: |
for file in ${{ steps.files.outputs.all_changed_files }}; do
2023-09-02 18:01:05 +00:00
if [[ "$file" == *"-playbook.yaml" ]];
then
ansible-playbook --inventory ./inventory "$file"
fi
done
2023-09-02 18:12:34 +00:00
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
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: |
find . -wholename "*/infra/*-playbook.yaml" -type f -exec ansible-playbook --inventory ./inventory {} \;