Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/homelab-plan.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name: homelab-plan

# This check is REQUIRED by branch protection (see homelab/locals.tf —
# required_status_check_contexts = ["homelab-plan"]). It must therefore report
# a status on EVERY pull request, so the trigger is intentionally NOT
# path-filtered: a path-filtered workflow that doesn't trigger leaves the
# required check stuck on "Expected — Waiting for status to be reported"
# forever, blocking docs-only / cloudflare-only PRs that never touch homelab/.
# Instead we always run the job and gate the expensive tofu steps on a
# path-detection — a job whose steps are all skipped still reports success.

on:
pull_request:
paths:
- "homelab/**"
- ".github/workflows/homelab-plan.yml"

permissions:
contents: read
Expand Down Expand Up @@ -32,29 +38,47 @@ jobs:
steps:
- uses: actions/checkout@v4

# Decide whether this PR actually touches the homelab context. When it
# doesn't, every step below is skipped and the job reports a green
# homelab-plan, satisfying branch protection without running tofu.
- name: Detect homelab/ changes
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
homelab:
- 'homelab/**'
- '.github/workflows/homelab-plan.yml'

- name: Stage GitHub App PEM
if: steps.changes.outputs.homelab == 'true'
run: |
mkdir -p "$HOME/.config/github-app"
printf '%s' "${{ secrets.TF_GITHUB_APP_PRIVATE_KEY }}" > "$HOME/.config/github-app/opentofu.pem"
chmod 600 "$HOME/.config/github-app/opentofu.pem"
echo "TF_VAR_github_app_pem_file=$HOME/.config/github-app/opentofu.pem" >> "$GITHUB_ENV"

- uses: opentofu/setup-opentofu@v1
if: steps.changes.outputs.homelab == 'true'
with:
tofu_version: 1.10.0
tofu_wrapper: false

- name: tofu fmt -check
if: steps.changes.outputs.homelab == 'true'
run: tofu fmt -check -recursive

- name: tofu init
if: steps.changes.outputs.homelab == 'true'
run: tofu init -input=false

- name: tofu validate
if: steps.changes.outputs.homelab == 'true'
run: tofu validate

- name: tofu plan
id: plan
if: steps.changes.outputs.homelab == 'true'
run: |
set +e
tofu plan -input=false -no-color -out=tfplan 2>&1 | tee plan.txt
Expand All @@ -67,7 +91,7 @@ jobs:
exit $status

- name: Post plan to PR
if: always() && github.event_name == 'pull_request'
if: always() && steps.changes.outputs.homelab == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Loading