255 lines
9.7 KiB
YAML
255 lines
9.7 KiB
YAML
name: Gitea Branch PR & Ansible Deployment
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
# workflow_run will be supported in Gitea 1.25.x
|
|
# workflow_run:
|
|
# workflows: [Home Assistant Config Check, Validate DAGs]
|
|
# types:
|
|
# - completed
|
|
# branches: main
|
|
push:
|
|
branches-ignore:
|
|
- "main"
|
|
paths:
|
|
- "app-configs/**"
|
|
- "!app-configs/rikku/homeassistant/**"
|
|
- "!app-configs/rinoa/dagu/dags/**"
|
|
- "collections/**"
|
|
- "group_vars/**"
|
|
- "host_vars/**"
|
|
- "inventory/**"
|
|
- "!renovate.json"
|
|
|
|
env:
|
|
TEA_VERSION: "0.10.1"
|
|
VAULT_ADDR: ${{ secrets.TREZ_VAULT_ADDR }}
|
|
VAULT_TOKEN: ${{ secrets.VAULT_GITEA_TOKEN }}
|
|
|
|
jobs:
|
|
check-and-create-pr:
|
|
if: github.ref != 'refs/heads/main'
|
|
name: Check and Create PR
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
|
with:
|
|
fetch-depth: 1
|
|
|
|
- name: Install tea CLI
|
|
uses: supplypike/setup-bin@8e3f88b4f143d9b5c3497f0fc12d45c83c123787 # v4.0.1
|
|
with:
|
|
uri: "https://gitea.com/gitea/tea/releases/download/v${{ env.TEA_VERSION }}/tea-${{ env.TEA_VERSION }}-linux-amd64"
|
|
name: "tea"
|
|
version: ${{ env.TEA_VERSION }}
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}"
|
|
gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}"
|
|
notification_title: "GITEA: PR Check"
|
|
notification_message: "Checking for existing PR... 🔍"
|
|
|
|
- name: Check if open PR exists
|
|
id: check-opened-pr-step
|
|
continue-on-error: true
|
|
run: |
|
|
tea login add --name gitea-rinoa --url "${{ secrets.TREZ_GITEA_URL }}" --user gitea-sonarqube-bot --password "${{ secrets.BOT_GITEA_PASSWORD }}" --token ${{ secrets.BOT_GITEA_TOKEN }}
|
|
pr_exists=$(tea pr list --repo ${{ github.repository }} --state open --fields index,title,head | egrep '\[ANSIBLE\].*${{ github.ref_name }}' | tail -1 | wc -l)
|
|
echo "exists=$pr_exists" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create PR
|
|
if: ${{ steps.check-opened-pr-step.outputs.exists == '0' }}
|
|
run: |
|
|
tea login default gitea-rinoa
|
|
pr_index_old=$(tea pr ls --repo ${{ github.repository }} --state all --fields index,title,head --output csv | sed -e 's|"||g' | egrep '^[0-9]' | head -1 | awk -F"," '{print $1}')
|
|
pr_index_new=$(expr ${pr_index_old} + 1)
|
|
tea pr c -r ${{ github.repository }} -t "[ANSIBLE] Automated PR for ${{ github.ref_name }} - #${pr_index_new}" -d "Automatically created PR for branch: ${{ github.ref_name }}" -a ${{ github.actor }} -L "Ansible Configs.j2"
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}"
|
|
gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}"
|
|
notification_title: "GITEA: PR Check"
|
|
notification_message: "PR Created 🎟️"
|
|
|
|
ansible-dry-run:
|
|
name: Ansible Dry Run
|
|
needs: [check-and-create-pr]
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
host: [rinoa, rikku, benedikta]
|
|
env:
|
|
VAULT_ADDR: ${{ secrets.TREZ_VAULT_ADDR }}
|
|
VAULT_TOKEN: ${{ secrets.VAULT_GITEA_TOKEN }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
|
|
|
- name: Cache Ansible Galaxy Collections
|
|
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
|
|
with:
|
|
path: collections
|
|
key: ${{ runner.os }}-ansible-${{ hashFiles('./collections/requirements.yml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-ansible-
|
|
|
|
- name: Install Ansible
|
|
uses: alex-oleshkevich/setup-ansible@f879ce3cf11a7315e130919a797526b0c6bfd272 # v1.0.1
|
|
with:
|
|
version: "11.4.0"
|
|
|
|
- name: Set up Vault CLI
|
|
uses: eLco/setup-vault@5d0ddffdfca9650484ae1378dafc376a9ebcd15e # v1.0.3
|
|
with:
|
|
vault_version: 1.18.0
|
|
|
|
- name: Cache pip
|
|
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
|
|
with:
|
|
path: ~/.cache/pip
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pip-
|
|
|
|
- name: Install Vault & hvac
|
|
run: pip install hvac
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}"
|
|
gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}"
|
|
notification_title: "GITEA: Ansible Dry Run"
|
|
notification_message: "Starting dry run for ${{ matrix.host }}..."
|
|
|
|
- name: Run Ansible Dry Run
|
|
uses: dawidd6/action-ansible-playbook@a4133a9690f77b38c8227021ed497fc1267635d5 # v3
|
|
with:
|
|
directory: .
|
|
playbook: tar-valon_config_deploy.yml
|
|
vault_password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
|
|
key: ${{ secrets.ANSIBLE_PRIVATE_KEY }}
|
|
requirements: collections/requirements.yml
|
|
options: |
|
|
--inventory inventory/hosts.yml
|
|
--limit ${{ matrix.host }}
|
|
--check
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}"
|
|
gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}"
|
|
notification_title: "GITEA: Ansible Dry Run"
|
|
notification_message: "Dry run for ${{ matrix.host }} completed."
|
|
|
|
pr-merge:
|
|
name: PR Merge
|
|
needs: [ansible-dry-run]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
|
|
|
- name: Install tea
|
|
uses: supplypike/setup-bin@8e3f88b4f143d9b5c3497f0fc12d45c83c123787 # v4.0.1
|
|
with:
|
|
uri: "https://gitea.com/gitea/tea/releases/download/v${{ env.TEA_VERSION }}/tea-${{ env.TEA_VERSION }}-linux-amd64"
|
|
name: "tea"
|
|
version: ${{ env.TEA_VERSION }}
|
|
|
|
- name: PR Merge
|
|
id: pr_merge
|
|
run: |
|
|
tea login add --name gitea-rinoa --url ${{ secrets.TREZ_GITEA_URL }} --user gitea-sonarqube-bot --password "${{ secrets.BOT_GITEA_PASSWORD }}" --token ${{ secrets.BOT_GITEA_TOKEN }}
|
|
tea login default gitea-rinoa
|
|
pr_index=$(tea pr ls --repo ${{ github.repository }} --state open --fields index,title,head,state --output csv | egrep ${{ github.ref_name }} | awk -F"," '{print $1}' | sed -e 's|"||g')
|
|
tea pr m --repo ${{ github.repository }} --title "Auto Merge of PR ${pr_index} - ${{ github.ref_name }}" --message "Merged by ${{ github.actor }}" ${pr_index}
|
|
echo "pr_index=${pr_index}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}"
|
|
gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}"
|
|
notification_title: "GITEA: PR Merge Successful"
|
|
notification_message: "PR #${{ steps.pr_merge.outputs.pr_index }} merged."
|
|
|
|
ansible-config-deploy:
|
|
name: Ansible Config Deployment
|
|
needs: [pr-merge]
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
host: [rinoa, rikku, benedikta]
|
|
env:
|
|
VAULT_ADDR: ${{ secrets.TREZ_VAULT_ADDR }}
|
|
VAULT_TOKEN: ${{ secrets.VAULT_GITEA_TOKEN }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
|
with:
|
|
ref: main
|
|
|
|
- name: Cache Ansible Galaxy Collections
|
|
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
|
|
with:
|
|
path: collections
|
|
key: ${{ runner.os }}-ansible-${{ hashFiles('./collections/requirements.yml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-ansible-
|
|
|
|
- name: Install Ansible
|
|
uses: alex-oleshkevich/setup-ansible@f879ce3cf11a7315e130919a797526b0c6bfd272 # v1.0.1
|
|
with:
|
|
version: "11.4.0"
|
|
|
|
- name: Set up Vault CLI
|
|
uses: eLco/setup-vault@5d0ddffdfca9650484ae1378dafc376a9ebcd15e # v1.0.3
|
|
with:
|
|
vault_version: 1.18.0
|
|
|
|
- name: Cache pip
|
|
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
|
|
with:
|
|
path: ~/.cache/pip
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pip-
|
|
|
|
- name: Install hvac
|
|
run: pip install hvac
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}"
|
|
gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}"
|
|
notification_title: "GITEA: Ansible Config Deployment"
|
|
notification_message: "Deploying configs to ${{ matrix.host }}..."
|
|
|
|
- name: Run Ansible Config Deployment
|
|
uses: dawidd6/action-ansible-playbook@a4133a9690f77b38c8227021ed497fc1267635d5 # v3
|
|
with:
|
|
directory: .
|
|
playbook: tar-valon_config_deploy.yml
|
|
vault_password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
|
|
key: ${{ secrets.ANSIBLE_PRIVATE_KEY }}
|
|
requirements: collections/requirements.yml
|
|
options: |
|
|
--inventory inventory/hosts.yml
|
|
--limit ${{ matrix.host }}
|
|
|
|
- name: Gotify Notification
|
|
uses: eikendev/gotify-action@master
|
|
with:
|
|
gotify_api_base: "${{ secrets.RUNNER_GOTIFY_URL }}"
|
|
gotify_app_token: "${{ secrets.RUNNER_GOTIFY_TOKEN }}"
|
|
notification_title: "GITEA: Deployment Completed"
|
|
notification_message: "Deployment to ${{ matrix.host }} completed successfully."
|