-
Notifications
You must be signed in to change notification settings - Fork 324
fix(ci): cleanup PLAN files in a separate PR, add to comment, not description #7029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3e1c4ab
4f8dc03
51dffde
a8a0121
6051145
a509926
6dfe676
c9cfb85
5ee6e0c
cb8803f
28fc7e4
c50c199
dcedad0
a68313d
0ef346a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,17 @@ | ||||||
| # Cleanup Ephemeral Planning Documents | ||||||
| # | ||||||
| # This workflow automatically removes PLAN.md and other ephemeral planning | ||||||
| # documents when a PR is merged. This serves as a safety net in case the | ||||||
| # documents from the main branch. It serves as a safety net in case the | ||||||
| # /finish skill wasn't used before merging. | ||||||
| # | ||||||
| # Triggers: | ||||||
| # 1. pull_request_target (closed+merged) - catches files merged via PR | ||||||
| # 2. push to main branches - catches files pushed directly or via squash | ||||||
| # merge (path-filtered to only run when ephemeral files are present) | ||||||
| # | ||||||
| # Strategy: Creates a cleanup PR instead of pushing directly to the | ||||||
| # protected main branch, since branch protection rules block direct pushes. | ||||||
| # | ||||||
| # Ephemeral documents are temporary files used during development that | ||||||
| # shouldn't persist on the main branch: | ||||||
| # - PLAN.md: Planning and task tracking | ||||||
|
|
@@ -12,16 +20,14 @@ | |||||
| # These files are tracked on feature branches but should be deleted before | ||||||
| # merge. If they slip through, this action cleans them up. | ||||||
| # | ||||||
| # The "Preserve plan details" step only runs for PR merges (not direct | ||||||
| # pushes) since there's no source PR to comment on for direct pushes. | ||||||
| # | ||||||
| # Security Note: Uses pull_request_target to ensure write permissions for | ||||||
| # PRs from forks. This is safe because: | ||||||
| # 1. The workflow only checks out the base branch (not PR code) | ||||||
| # 2. File paths are validated (hardcoded list of allowed files) | ||||||
| # 3. No PR-controlled code is executed | ||||||
| # | ||||||
| # To use in your repo: | ||||||
| # 1. Copy this file to .github/workflows/cleanup-ephemeral-docs.yml | ||||||
| # 2. Update the 'branches' list to match your main branch (master or main) | ||||||
| # 3. Commit and push | ||||||
|
|
||||||
| name: Cleanup ephemeral docs | ||||||
|
|
||||||
|
|
@@ -31,11 +37,20 @@ on: | |||||
| branches: | ||||||
| - master | ||||||
| - main | ||||||
| push: | ||||||
| branches: | ||||||
| - master | ||||||
| - main | ||||||
| paths: | ||||||
| - 'PLAN.md' | ||||||
| - 'HANDOVER.md' | ||||||
|
|
||||||
| jobs: | ||||||
| cleanup: | ||||||
| # Only run when PR is actually merged (not just closed) | ||||||
| if: github.event.pull_request.merged == true | ||||||
| # Run when PR is merged OR when ephemeral files are pushed directly | ||||||
| if: >- | ||||||
| (github.event_name == 'push') || | ||||||
| (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| permissions: | ||||||
|
|
@@ -46,21 +61,24 @@ jobs: | |||||
| - name: Checkout repository | ||||||
| uses: actions/checkout@v4 | ||||||
| with: | ||||||
| ref: ${{ github.event.pull_request.base.ref }} | ||||||
| ref: ${{ github.event.pull_request.base.ref || github.ref }} | ||||||
| fetch-depth: 0 | ||||||
|
|
||||||
| - name: Check for ephemeral files | ||||||
| id: check | ||||||
| run: | | ||||||
| FILES_TO_REMOVE="" | ||||||
| FILE_LIST="" | ||||||
|
|
||||||
| if [ -f "PLAN.md" ]; then | ||||||
| FILES_TO_REMOVE="$FILES_TO_REMOVE PLAN.md" | ||||||
| FILE_LIST="${FILE_LIST:+$FILE_LIST, }PLAN.md" | ||||||
| echo "Found: PLAN.md" | ||||||
| fi | ||||||
|
|
||||||
| if [ -f "HANDOVER.md" ]; then | ||||||
| FILES_TO_REMOVE="$FILES_TO_REMOVE HANDOVER.md" | ||||||
| FILE_LIST="${FILE_LIST:+$FILE_LIST, }HANDOVER.md" | ||||||
| echo "Found: HANDOVER.md" | ||||||
| fi | ||||||
|
|
||||||
|
|
@@ -71,67 +89,84 @@ jobs: | |||||
| echo "Files to remove:$FILES_TO_REMOVE" | ||||||
| echo "has_files=true" >> $GITHUB_OUTPUT | ||||||
| echo "files=$FILES_TO_REMOVE" >> $GITHUB_OUTPUT | ||||||
| echo "file_list=$FILE_LIST" >> $GITHUB_OUTPUT | ||||||
| fi | ||||||
|
|
||||||
| - name: Preserve plan details on PR | ||||||
| if: steps.check.outputs.has_files == 'true' | ||||||
| - name: Preserve plan details on source PR | ||||||
| if: >- | ||||||
| steps.check.outputs.has_files == 'true' && | ||||||
| github.event_name == 'pull_request_target' | ||||||
| env: | ||||||
| GH_TOKEN: ${{ github.token }} | ||||||
| run: | | ||||||
| PR_NUMBER=${{ github.event.pull_request.number }} | ||||||
|
|
||||||
| # Post full PLAN.md contents as a PR comment before removing | ||||||
| if [ -f "PLAN.md" ]; then | ||||||
| PLAN_BODY="## Development Plan (preserved by cleanup workflow) | ||||||
| gh pr comment "$PR_NUMBER" --body "$(cat <<'EOFCOMMENT' | ||||||
| ## Development Plan (preserved by cleanup workflow) | ||||||
|
|
||||||
| Full plan details from \`PLAN.md\`, preserved before automated cleanup: | ||||||
| Full plan details from `PLAN.md`, preserved before automated cleanup: | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| $(cat PLAN.md)" | ||||||
| gh pr comment "$PR_NUMBER" --body "$PLAN_BODY" | ||||||
| EOFCOMMENT | ||||||
| cat PLAN.md)" | ||||||
| echo "Posted PLAN.md contents to PR #$PR_NUMBER" | ||||||
| fi | ||||||
|
|
||||||
| if [ -f "HANDOVER.md" ]; then | ||||||
| HANDOVER_BODY="## Handover Notes (preserved by cleanup workflow) | ||||||
| gh pr comment "$PR_NUMBER" --body "$(cat <<'EOFCOMMENT' | ||||||
| ## Handover Notes (preserved by cleanup workflow) | ||||||
|
|
||||||
| Full contents from \`HANDOVER.md\`, preserved before automated cleanup: | ||||||
| Full contents from `HANDOVER.md`, preserved before automated cleanup: | ||||||
|
|
||||||
| --- | ||||||
|
|
||||||
| $(cat HANDOVER.md)" | ||||||
| gh pr comment "$PR_NUMBER" --body "$HANDOVER_BODY" | ||||||
| EOFCOMMENT | ||||||
| cat HANDOVER.md)" | ||||||
|
Comment on lines
123
to
+126
|
||||||
| echo "Posted HANDOVER.md contents to PR #$PR_NUMBER" | ||||||
| fi | ||||||
|
|
||||||
| - name: Remove ephemeral files | ||||||
| - name: Create cleanup PR | ||||||
| if: steps.check.outputs.has_files == 'true' | ||||||
| env: | ||||||
| GH_TOKEN: ${{ github.token }} | ||||||
| run: | | ||||||
| TARGET_BRANCH="${{ github.event.pull_request.base.ref || github.ref_name }}" | ||||||
| CLEANUP_BRANCH="chore/cleanup-ephemeral-docs-$(date +%Y%m%d-%H%M%S)" | ||||||
|
||||||
| CLEANUP_BRANCH="chore/cleanup-ephemeral-docs-$(date +%Y%m%d-%H%M%S)" | |
| CLEANUP_BRANCH="chore/cleanup-ephemeral-docs-${{ github.run_id }}-${{ github.run_attempt }}-$(date +%Y%m%d-%H%M%S)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The heredoc used to build the PR comment body is indented, so the
EOFCOMMENTterminator won’t be recognized by bash (heredoc delimiters must start at column 1 unless using<<-with tabs). This will cause the step to hang or fail and prevent plan preservation. Consider left-aligning the terminator line (no leading whitespace) or avoid heredocs here (e.g., useprintf/catwithout heredoc).