name: Infrastructure on: pull_request: branches: - main push: branches: - main paths: - infra/**-playbook.yaml - .github/workflows/infra.yaml env: DEPLOY: ${{ github.ref == 'refs/heads/main' && ((startsWith(github.event.head_commit.message, '[deploy-all]') && 'all') || ('some')) || 'none' }} jobs: 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 with: python-version: "3.11" - name: Install dependencies run: | pip3 install -r requirements.txt ansible-galaxy collection install community.general - name: Check playbooks run: | for file in $(find . -wholename "*/infra/*-playbook.yaml" -type f); do ansible-playbook --inventory ./inventory --check "$file" done - 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 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: 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)