Files
homelab/.gitea/workflows/deploy-preview.yaml
Julia McGhee 58cd9e21db
All checks were successful
CI / lint-and-test (push) Successful in 30s
Deploy Production / deploy (push) Successful in 34s
CI / build (push) Successful in 33s
Fix deploy: use if/then instead of && to avoid pipefail exit
The Dockerfile check in the while-read loop used `[ -f ... ] && echo`,
which exits non-zero for packages without Dockerfiles. With bash's
pipefail, this killed the entire step. Also remove unused GitHub
workflow copies since CI runs on Gitea only.
2026-03-21 21:26:23 +00:00

61 lines
2.4 KiB
YAML

name: Deploy Preview
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup and install
run: |
export COREPACK_HOME=/pnpm-store/.corepack
corepack enable && corepack prepare pnpm@latest --activate
export PNPM_STORE_DIR=/pnpm-store
pnpm install --frozen-lockfile
- name: Determine changed apps
id: changes
run: |
APPS=$(pnpm turbo build --filter='...[origin/main]' --dry-run=json | jq -r '[.packages[] | select(startswith("@homelab/")) | sub("@homelab/";"") ] | join(",")' | tr ',' '\n' | while read app; do if [ -f "apps/${app}/Dockerfile" ]; then echo "$app"; fi; done | paste -sd, -)
echo "apps=$APPS" >> "$GITHUB_OUTPUT"
- name: Build and push images
if: steps.changes.outputs.apps != ''
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login gitea.coreworlds.io -u lazorgurl --password-stdin
IFS=',' read -ra APPS <<< "${{ steps.changes.outputs.apps }}"
for app in "${APPS[@]}"; do
if [ -f "apps/${app}/.dockercontext" ]; then
CONTEXT="."
else
CONTEXT="apps/${app}"
fi
docker build \
-t gitea.coreworlds.io/lazorgurl/homelab-${app}:${{ gitea.sha }} \
-f apps/${app}/Dockerfile \
$CONTEXT
docker push gitea.coreworlds.io/lazorgurl/homelab-${app}:${{ gitea.sha }}
done
- name: Update image tags in preview overlay
if: steps.changes.outputs.apps != ''
run: |
IFS=',' read -ra APPS <<< "${{ steps.changes.outputs.apps }}"
for app in "${APPS[@]}"; do
cd apps/${app}/k8s/overlays/preview
kustomize edit set image gitea.coreworlds.io/lazorgurl/homelab-${app}=gitea.coreworlds.io/lazorgurl/homelab-${app}:${{ gitea.sha }}
cd -
done
- name: Comment preview URL
run: |
curl -s -X POST \
-H "Authorization: token ${{ gitea.token }}" \
-H "Content-Type: application/json" \
-d "{\"body\": \"## Preview Deploy\nNamespace: \`preview-${{ gitea.event.number }}\`\nArgoCD will sync automatically.\"}" \
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/issues/${{ gitea.event.number }}/comments"