From 26868a49765c9ca46d8e0f7a52b00d68ec182a1e Mon Sep 17 00:00:00 2001 From: traveler Date: Mon, 12 Jan 2026 20:41:54 -0600 Subject: [PATCH] new deploy --- .forgejo/workflows/deploy.yml | 66 +++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 66e614d..930660f 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -11,10 +11,13 @@ jobs: swarm_files: ${{ steps.changes.outputs.swarm_files }} compose_matrix: ${{ steps.changes.outputs.compose_matrix }} steps: - - name: Checkout - uses: https://data.forgejo.org/actions/checkout@v4 - with: - fetch-depth: 0 + - name: Checkout repository (no node) + shell: bash + run: | + set -euo pipefail + git config --global --add safe.directory "$PWD" + git fetch origin + git checkout "$GITHUB_REF_NAME" - name: Detect changed YAML files id: changes @@ -25,17 +28,28 @@ jobs: BASE="${{ github.event.before }}" HEAD="${{ github.sha }}" - if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ]; then + # Handle edge cases (new branch / forced push etc.) + if [ -z "${BASE}" ] || [ "${BASE}" = "0000000000000000000000000000000000000000" ]; then BASE="$(git rev-parse "${HEAD}~1" || true)" fi + if [ -z "${BASE}" ]; then + echo "No base commit found; deploying nothing." + echo "swarm_files=" >> "$GITHUB_OUTPUT" + echo 'compose_matrix={"include":[]}' >> "$GITHUB_OUTPUT" + exit 0 + fi + CHANGED="$(git diff --name-only "$BASE" "$HEAD" || true)" + echo "Changed files:" echo "$CHANGED" # -------------------- # Swarm stack YAMLs # -------------------- SWARM_FILES="$(echo "$CHANGED" | grep -E '^services/swarm/stacks/.*\.ya?ml$' || true)" + echo "Swarm stack files:" + echo "$SWARM_FILES" echo "swarm_files=$(echo "$SWARM_FILES" | xargs)" >> "$GITHUB_OUTPUT" # -------------------- @@ -43,7 +57,10 @@ jobs: # services/compose///.yml # -------------------- COMPOSE_FILES="$(echo "$CHANGED" | grep -E '^services/compose/[^/]+/[^/]+/.*\.ya?ml$' || true)" + echo "Compose files:" + echo "$COMPOSE_FILES" + # Build matrix items: {"host":"nas","file":"services/compose/nas/foo/comixed.yaml"} JSON='{"include":[' FIRST=1 while read -r FILE; do @@ -56,20 +73,28 @@ jobs: JSON+=']}' echo "compose_matrix=$JSON" >> "$GITHUB_OUTPUT" + echo "Compose matrix:" + echo "$JSON" deploy_swarm: needs: detect if: ${{ needs.detect.outputs.swarm_files != '' }} runs-on: docker2 steps: - - name: Checkout - uses: https://data.forgejo.org/actions/checkout@v4 + - name: Checkout repository (no node) + shell: bash + run: | + set -euo pipefail + git config --global --add safe.directory "$PWD" + git fetch origin + git checkout "$GITHUB_REF_NAME" - name: Validate swarm stacks shell: bash run: | set -euo pipefail for f in ${{ needs.detect.outputs.swarm_files }}; do + echo "Validating swarm stack file: $f" docker stack config -c "$f" >/dev/null done @@ -79,6 +104,7 @@ jobs: set -euo pipefail for f in ${{ needs.detect.outputs.swarm_files }}; do STACK="$(basename "$f" | sed 's/\.ya\?ml$//')" + echo "Deploying swarm stack: $STACK from $f" docker stack deploy -c "$f" "$STACK" done @@ -90,7 +116,27 @@ jobs: matrix: ${{ fromJSON(needs.detect.outputs.compose_matrix) }} runs-on: ${{ matrix.host }} steps: - - name: Checkout - uses: https://data.forgejo.org/actions/checkout@v4 + - name: Checkout repository (no node) + shell: bash + run: | + set -euo pipefail + git config --global --add safe.directory "$PWD" + git fetch origin + git checkout "$GITHUB_REF_NAME" - - name: Validate + - name: Validate compose file + shell: bash + run: | + set -euo pipefail + F="${{ matrix.file }}" + echo "Validating compose file: $F" + docker compose -f "$F" config -q + + - name: Deploy compose file + shell: bash + run: | + set -euo pipefail + F="${{ matrix.file }}" + echo "Deploying compose file: $F" + docker compose -f "$F" pull + docker compose -f "$F" up -d --remove-orphans