Files
rikku-home-assistant/.gitea/workflows/renovate-pr-deploy.yml
T
2025-09-22 17:21:08 -04:00

135 lines
4.9 KiB
YAML

name: Renovate PR Deployment
on:
workflow_dispatch:
pull_request:
types: [closed]
branches:
- main
paths:
- "**/docker-compose.yml"
env:
HC_VAULT_VERSION: "1.18.0"
jobs:
deploy:
if: |
github.event.pull_request.merged == true &&
github.event.pull_request.user.login == 'renovate-bot' &&
startsWith(github.event.pull_request.head.ref, 'renovate/docker-compose') ||
startsWith(github.event.pull_request.head.ref, 'renovate/pin-dependencies')
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
- name: Install Vault
uses: cpanato/vault-installer@main
with:
version: ${{ env.HC_VAULT_VERSION }}
- name: Detect Renovate update type
id: detect-update
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
echo "PR body: $PR_BODY"
if echo "$PR_BODY" | grep -qE 'Update Type: (patch|minor|major|digest)'; then
echo "update=true" >> $GITHUB_OUTPUT
else
echo "update=false" >> $GITHUB_OUTPUT
fi
- name: Stop if update not patch/minor/major/digest
if: steps.detect-update.outputs.update != 'true'
run: |
echo "::warning::This PR does not involve patch/minor/major/digest update. Skipping deployment."
exit 0
- name: Get changed services from docker-compose.yml
id: services
run: |
git fetch origin ${{ github.event.pull_request.base.ref }}
git show origin/main:docker-compose.yml > docker-compose-main.yml || touch docker-compose-main.yml
cp docker-compose.yml docker-compose-head.yml
echo "Getting services from main and ${{ github.ref_name }}"
yq '.services | keys | .[]' docker-compose-main.yml | sort > services_main.txt
yq '.services | keys | .[]' docker-compose-head.yml | sort > services_head.txt
echo "Creating list of modified services..."
touch service_changes.txt
comm -13 services_main.txt services_head.txt | while read service; do
echo "$service: added" >> service_changes.txt
done
comm -12 services_main.txt services_head.txt | while read service; do
yq ".services[\"$service\"]" docker-compose-main.yml > tmp_main.yml
yq ".services[\"$service\"]" docker-compose-head.yml > tmp_head.yml
if ! diff -q tmp_main.yml tmp_head.yml > /dev/null; then
echo "$service: modified" >> service_changes.txt
fi
done
echo "Detected service changes:"
cat service_changes.txt
mod_svcs=$(cut -d':' -f1 service_changes.txt | sort | uniq)
echo "docker_svc_list<<EOF" >> "$GITHUB_OUTPUT"
echo "$mod_svcs" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: List of Services for (Re)Deployment
run: |
echo -e "${{ steps.services.outputs.docker_svc_list }}"
- name: Generate .env file for Docker Compose
run: |
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
- name: Gotify Notification
uses: eikendev/gotify-action@master
with:
gotify_api_base: "${{ secrets.RIKKU_GOTIFY_URL }}"
gotify_app_token: "${{ secrets.RIKKU_RUNNER_GOTIFY_TOKEN }}"
notification_title: "GITEA: [RENOVATE] Docker Compose Deployment @ Rikku"
notification_message: "Starting Docker Compose run..."
- name: Docker Compose Deployment
uses: cssnr/stack-deploy-action@d58b92bcd776afc57ef12f55bafff71200fd218e # v1.4.0
with:
mode: compose
file: docker-compose.yml
name: "rikku"
host: 192.168.1.252
user: pi
ssh_key: ${{ secrets.RIKKU_SSH_PRIVATE_KEY }}
args: --remove-orphans -d ${{ needs.generate-service-list.outputs.svc_deploy_list }}
env_file: ".env"
registry_host: "ghcr.io"
registry_user: TrezOne
registry_pass: ${{ secrets.GHCR_LOGIN_TOKEN }}
summary: true
- name: Docker Compose Healthcheck
uses: jaracogmbh/docker-compose-health-check-action@973fbdccf7c8e396b652d3501984c8e530a9fa80 # v1.0.0
env:
DOCKER_HOST: tcp://192.168.1.252:2375
with:
max-retries: 30
retry-interval: 10
compose-file: "docker-compose.yml"
skip-exited: "true"
skip-no-healthcheck: "true"
- name: Gotify Notification
uses: eikendev/gotify-action@master
with:
gotify_api_base: "${{ secrets.RIKKU_GOTIFY_URL }}"
gotify_app_token: "${{ secrets.RIKKU_RUNNER_GOTIFY_TOKEN }}"
notification_title: "GITEA: [RENOVATE] Docker Compose Deployment @ Rikku"
notification_message: "Deployment completed successfully."