kovalhome/.github/workflows/infra.yaml

83 lines
2.8 KiB
YAML
Raw Normal View History

name: Infrastructure
on:
pull_request:
branches:
- main
paths:
- infra/**playbook.yaml
- .github/workflows/infra.yaml
2023-09-03 00:13:27 +00:00
push:
branches:
- main
2023-09-02 19:18:21 +00:00
env:
DEPLOY: ${{ github.ref == 'refs/heads/main' && ((startsWith(github.event.head_commit.message, '[deploy-all]') && 'all') || ('some')) || 'none' }}
# DEPLOY: all
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: Install dependencies
run: |
apt update
apt install -y python3-pip
pip3 install -r requirements.txt
2024-01-30 17:50:13 +00:00
ansible-galaxy collection install -r requirements.yml --force
2024-01-30 17:31:29 +00:00
- name: Run ansible-lint
uses: ansible/ansible-lint@v6
2024-01-30 12:42:41 +00:00
2023-09-02 18:12:34 +00:00
- name: Check playbooks
run: |
2024-01-30 12:42:41 +00:00
ansible-playbook --inventory ./inventory --syntax-check infra/**/*playbook.yaml
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:
files: infra/**/*playbook.yaml
2023-09-02 18:12:34 +00:00
2023-09-02 21:40:18 +00:00
- name: Get playbooks
id: playbooks
if: env.DEPLOY != 'none'
run: |
if [[ "${{ env.DEPLOY }}" == "some" ]]; then
export TO_RUN="${{ steps.files.outputs.all_changed_files }}"
else
export TO_RUN="$(find . -wholename './infra/*playbook.yaml' -type f)"
2023-09-02 21:40:18 +00:00
fi
2023-09-02 23:52:40 +00:00
export TO_RUN="$( echo -n $TO_RUN | tr ' ' '\n' | sort | tr '\n' ' ' )" # run things in order :)
2023-09-02 21:40:18 +00:00
echo "will run playbooks: $TO_RUN"
echo "to_run=$TO_RUN" >> "$GITHUB_OUTPUT"
- name: Setup environment
if: env.DEPLOY != 'none' && steps.playbooks.outputs.to_run != ''
run: |
mkdir -p -m 700 ~/.ssh
echo "${{ secrets.SSH_PRIVATE }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
2023-09-02 21:43:46 +00:00
- name: Run playbooks
2023-09-02 21:56:50 +00:00
if: env.DEPLOY != 'none' && steps.playbooks.outputs.to_run != ''
2023-09-02 21:43:46 +00:00
env:
PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }}
2023-09-03 00:01:05 +00:00
PROXMOX_USER: ${{ secrets.PROXMOX_USER }}
2023-09-02 21:43:46 +00:00
PROXMOX_TOKEN_ID: ${{ secrets.PROXMOX_TOKEN_ID }}
PROXMOX_TOKEN_SECRET: ${{ secrets.PROXMOX_TOKEN_SECRET }}
SSH_PUBLIC: ${{ secrets.SSH_PUBLIC }}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
INFISICAL_ENCRYPTION_KEY: ${{ secrets.INFISICAL_ENCRYPTION_KEY }}
INFISICAL_AUTH_SECRET: ${{ secrets.INFISICAL_AUTH_SECRET }}
INFISICAL_MONGO_PASSWORD: ${{ secrets.INFISICAL_MONGO_PASSWORD }}
INFISICAL_TOKEN: ${{ secrets.INFISICAL_TOKEN }}
INFISICAL_URL: https://secrets.koval.net
run: ansible-playbook --inventory ./inventory ${{ steps.playbooks.outputs.to_run }} -vv