PreTeXtBook / pretext-cli

Command line interface for quickly creating, authoring, and building PreTeXt documents.
https://pretextbook.org
GNU General Public License v3.0
17 stars 17 forks source link

GitHub action for `pretext deploy` #644

Open StevenClontz opened 11 months ago

StevenClontz commented 11 months ago

In an ideal world, I should be able to push my updated PreTeXt project to main, and then GitHub actions builds/generates everything and deploys it. This is particularly useful for projects such as https://github.com/TeamBasedInquiryLearning/linear-algebra that involve multiple contributors: I'd especially love to see a preview of the built project on every pull request, or a failed CI notification when the project doesn't build with the proposed contribution. Then when I thumbs-up the contribution and merge it into main, I get a fresh build and deployment automatically.

cmhughes commented 9 months ago

My attempt (which fails) at this is

name: cmh-deploy-gh-pages

on:
  push:

jobs:
  cmh-preTeXt-build:
    runs-on: ubuntu-latest
    steps:
      - name: install python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: Install pretext
        run: |
          python -m ensurepip
          python -m pip install --upgrade pip
          python -m pip install --upgrade pretext
      - name: load the "base actions/checkout" so as to access cmh-preTeXt-explore
        uses: actions/checkout@v4
      - name: cmh-build-html
        run: pretext build web
      - name: cmh-deploy-html
        run: pretext deploy

Here's a link to my repo: https://github.com/cmhughes/preTeXt-cmh-explore/tree/main and the failing action log: https://github.com/cmhughes/preTeXt-cmh-explore/actions/runs/7583169500/job/20654242271

I'd love to know what I'm doing wrong, and if anyone knows how to fix this.

StevenClontz commented 9 months ago

Thanks for the attempt! I haven't looked closely at this PR, but my hot take is that the issue here is that I wouldn't expect pretext deploy to work within an action. What the pretext deploy CLI command does is a bunch of git commands which the GitHub Action probably (shouldn't?) have permissions to perform in order to get files pushed to a gh-pages branch. Instead, our ideal GitHub action should perform some combination of https://github.com/actions/upload-pages-artifact and https://github.com/actions/deploy-pages to deploy an update that doesn't touch the repository itself (importantly, not inflating the size of a repo with the history of its deployments).

cmhughes commented 9 months ago

Thanks for the response 😊

Just to be clear, I'm not submitting a pull request (PR).

I'm a little confused about your point as looking at the following, which is run from within the devcontainer, this looks very much like a github action

https://github.com/cmhughes/preTeXt-cmh-explore/actions/runs/7581933289

But I've probably misunderstood things!

cmhughes commented 9 months ago

For anyone interested, I've now got a working demonstration of this at https://github.com/cmhughes/preTeXt-cmh-explore using the following GitHubActions

name: cmh-deploy-gh-pages

on:
  push:

permissions:
  contents: write

jobs:
  cmh-preTeXt-build:
    runs-on: ubuntu-latest
    steps:
      - name: install python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: Install pretext
        run: |
          python -m ensurepip
          python -m pip install --upgrade pip
          python -m pip install --upgrade pretext
      - name: load the "base actions/checkout" so as to access cmh-preTeXt-explore
        uses: actions/checkout@v4
      - name: cmh-build-html
        run: pretext build web
      - name: cmh-deploy-html-NEW
        # https://github.com/marketplace/actions/deploy-to-github-pages
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: output/web

references/links

my next step

I'm hoping to append the above to produce a (latex-generated) pdf, and deploy it somewhere appropriate to the repo above.

StevenClontz commented 8 months ago

Thanks - taking a closer look now.

I think you figured out what I poorly alluded to the other day: rather than using pretext deploy in an Action (which does a bunch of Git branch management and assumes the machine has Git permissions), using something like the JamesIves/github-pages-deploy-action@v4 custom action intended to deploy arbitrary files to GitHub Pages feels like the way to go.

My next hint would be that the basic ubuntu-latest machine won't have all the TeX installations needed to produce a PDF. But maybe the action can be wired up to use one of these docker images? https://github.com/cmhughes/preTeXt-cmh-explore/blob/3ed7015fd6eedf2c123e7d20602b64e8315ab49b/.devcontainer.json#L17