Skip to content

Scaffold PDF preview and Copilot instructions in generated book projects - #72

Merged
demccormack merged 6 commits into
mainfrom
copilot/add-automation-tools
Sep 20, 2026
Merged

demccormack merged 6 commits into
mainfrom
copilot/add-automation-tools

Conversation

Copilot AI commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Generated book repositories were missing two pieces of repo automation expected by the issue: a PR PDF preview workflow and a repository-specific Copilot instructions file. This change extends write new so newly scaffolded projects include both, with title- and project-specific substitutions applied at generation time.

  • Scaffolded GitHub automation

    • Adds a generated /.github/workflows/pdf_preview.yml for book repos.
    • Preserves the repo’s existing PR preview behavior: build main.tex, upload a SHA-suffixed PDF artifact, and post/update a PR comment with the preview link.
    • Substitutes the generated project slug into artifact naming so each book repo gets correctly named preview output.
  • Generated Copilot instructions

    • Adds /.github/copilot-instructions.md to generated projects.
    • Templates the book title and author into the instructions body so the generated repo starts with repository-specific guidance rather than a generic placeholder.
  • Consistent template substitution

    • Moves generated author usage onto the same template replacement path as title substitution.
    • Applies the author value consistently in main.tex, book.toml, and the new Copilot instructions file.
  • Scaffold contract updates

    • Updates the generated project tree snapshot and focused scaffold tests to cover the new files and substitutions.
    • Refreshes the README’s auto-generated structure block to reflect the expanded scaffold.

Example of the new generated workflow naming:

- name: Rename PDF with commit SHA
  run: mv main.pdf the-verse-awakens-${GITHUB_SHA}.pdf

- name: Upload PDF artifact
  with:
    name: 'the-verse-awakens-${{ github.sha }}.pdf'
    path: 'the-verse-awakens-${{ github.sha }}.pdf'

Copilot AI and others added 3 commits September 20, 2026 11:26
Co-authored-by: demccormack <52194107+demccormack@users.noreply.github.com>
Co-authored-by: demccormack <52194107+demccormack@users.noreply.github.com>
Co-authored-by: demccormack <52194107+demccormack@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automation tools to generated projects Scaffold PDF preview and Copilot instructions in generated book projects Sep 20, 2026
Copilot AI requested a review from demccormack September 20, 2026 11:29
@demccormack
demccormack marked this pull request as ready for review September 20, 2026 11:47

@demccormack demccormack left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I forgot we already have build.yml doing some of this. So remove the new workflow and adapt build.yml to my requirements. Here is an example of how it should look if the new book was called "The Verse Awakens":

name: Build LaTeX PDF

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v7

      - name: Setup LaTeX
        uses: xu-cheng/latex-action@v4
        with:
          root_file: main.tex

      - name: Rename PDF with commit SHA
        run: mv main.pdf the-verse-awakens-${{ github.sha }}.pdf

      - name: Upload PDF preview artifact
        id: upload-pdf
        uses: actions/upload-artifact@v7
        with:
          name: the-verse-awakens-${{ github.sha }}.pdf
          path: the-verse-awakens-${{ github.sha }}.pdf
          archive: false

      - name: Add PDF preview to PR
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v9
        env:
          ARTIFACT_URL: ${{ steps.upload-pdf.outputs.artifact-url }}
          PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
          MERGE_SHA: ${{ github.sha }}
        with:
          script: |
            const marker = '<!-- pdf-preview -->';
            const headSha = process.env.PR_HEAD_SHA;
            const mergeSha = process.env.MERGE_SHA;

            const body = `${marker}
            ### 📖 PDF Preview

            **[Open PDF preview ↗](${process.env.ARTIFACT_URL})**

            Includes PR commit ${headSha.substring(0, 7)}  
            Built from merge commit ${mergeSha.substring(0, 7)}`;

            const comments = await github.paginate(github.rest.issues.listComments, {
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
            });

            const existingComments = comments.filter(
              comment =>
                comment.user.type === 'Bot' &&
                comment.body.includes(marker)
            );

            for (const comment of existingComments) {
              await github.rest.issues.deleteComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                comment_id: comment.id,
              });
            }

            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body,
            });

      - name: Create Release (on tag)
        if: startsWith(github.ref, 'refs/tags/')
        uses: softprops/action-gh-release@v3
        with:
          files: the-verse-awakens-${{ github.sha }}.pdf
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Copilot AI and others added 2 commits September 20, 2026 16:29
Co-authored-by: demccormack <52194107+demccormack@users.noreply.github.com>
Co-authored-by: demccormack <52194107+demccormack@users.noreply.github.com>

Copilot AI commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I forgot we already have build.yml doing some of this. So remove the new workflow and adapt build.yml to my requirements. Here is an example of how it should look if the new book was called "...

Addressed in 2a8e8ee. The generated build.yml now carries the PDF preview/upload/comment logic with the project slug substituted, and the separate pdf_preview.yml scaffold has been removed.

@github-actions

Copy link
Copy Markdown

📖 PDF Preview

Open PDF preview ↗

Includes PR commit 2a8e8ee
Built from merge commit 60da153

@demccormack
demccormack merged commit c54d458 into main Sep 20, 2026
3 checks passed
@demccormack
demccormack deleted the copilot/add-automation-tools branch September 20, 2026 18:41
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.

Add automation tools to generated projects

2 participants