Skip to content

feat(drift-detection): add scheduled example with sticky issue - #5

Merged
igorjs merged 2 commits into
mainfrom
feat/enterprise-hardening-s5-drift-detection
Sep 7, 2026
Merged

igorjs merged 2 commits into
mainfrom
feat/enterprise-hardening-s5-drift-detection

Conversation

@igorjs

@igorjs igorjs commented Sep 4, 2026

Copy link
Copy Markdown
Member

Summary

There's no way to catch changes that land outside this pipeline (a console edit, a manual terraform apply) until someone runs a plan by hand. This adds a scheduled example that runs a daily plan and reports drift through a single sticky Issue instead of paging anyone or filing a new Issue every day.

What Changed

  • New examples/drift-detection.yml: on: schedule plus workflow_dispatch for manual runs, calling the action with no command: override. The safer default from segment 1 already resolves to plan for any non push event, so a scheduled run never applies anything on its own.
  • When has-changes comes back 'true', a follow-up step opens or updates one Issue labeled drift-detection. It searches only issues with that label for a hidden marker in the body, so the lookup stays bounded instead of scanning every open issue. Same sticky pattern the PR comment step already uses, just for Issues instead of comments.
  • Fixed a crash found in review: a labeled issue with no body (GitHub allows this) made jq's startswith blow up and aborted the step under pipefail. The body lookup now falls back to an empty string before the check. Covered by a new test scenario and mutation-tested.
  • New tests/drift-issue.sh test harness. It extracts the real run: block straight out of the workflow file with PyYAML (same technique the self-lint check already uses for action.yml), so the test exercises the actual script, not a hand-copied stand-in. Runs it against a stubbed gh CLI across three scenarios: no existing issue, an existing issue to update, and the null-body case.
  • tests/drift-issue.sh was written but not wired into CI at first. Caught that in the same review pass and added it to ci.yml's test job, right after tests/action-logic.sh, with the pyyaml install step it needs.
  • README gets a new "Drift detection" section, and the "What this deliberately doesn't do" list drops its old "no drift detection" line since this example now covers it.

Notes for reviewers

@igorjs
igorjs force-pushed the feat/enterprise-hardening-s4-oidc branch 2 times, most recently from 73005b2 to 208fdf5 Compare September 7, 2026 04:18
Adds examples/drift-detection.yml, a scheduled (daily cron plus
workflow_dispatch) consumer workflow that calls the action with no
command override, relying on its existing plan-by-default behavior for
non-push events. When the plan reports changes, a bash step opens or
updates a single sticky Issue, scoped by the drift-detection label
(bounded search) and confirmed by a marker in the body.

Adds tests/drift-issue.sh, which extracts the real run: block from
that step via yaml.safe_load (same technique ci.yml's self-lint job
uses for action.yml) and executes it under a stubbed gh CLI on PATH
that logs every invocation and returns canned issue-list responses.
Covers the no-existing-issue (POST) and existing-issue (PATCH)
scenarios, plus a direct grep check that the step is gated on
has-changes == 'true'.

Verified empirically against the live GitHub API (scratch private
repo, deleted after) rather than assumed: the -F "labels[]=..." array
syntax works for issue creation, and GitHub auto-creates a label that
does not exist yet when an issue is created with it, so no separate
label-provisioning step is needed.

Signed-off-by: igorjs <2278164+igorjs@users.noreply.github.com>
@igorjs
igorjs force-pushed the feat/enterprise-hardening-s5-drift-detection branch from e2389b8 to b01dd29 Compare September 7, 2026 04:19
@igorjs
igorjs changed the base branch from feat/enterprise-hardening-s4-oidc to main September 7, 2026 04:19
- Guard the drift-issue search against a null response body.
- Capture -F/-f field values in the gh stub, not just verb+path.
- Assert the created issue carries the drift-detection label.
- Note the drift-issue step still inherits backend credentials via
  GITHUB_ENV persistence, harmless today but worth flagging.
- Scope Scenario 3's if: check to the whole step block via awk
  instead of a brittle adjacent-line grep.

Signed-off-by: igorjs <2278164+igorjs@users.noreply.github.com>
@igorjs
igorjs force-pushed the feat/enterprise-hardening-s5-drift-detection branch from b01dd29 to 2abfd46 Compare September 7, 2026 04:27
@igorjs
igorjs marked this pull request as ready for review September 7, 2026 04:27
@igorjs
igorjs merged commit c2b070a into main Sep 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant