|
| 1 | +# This file was automatically generated with PreTeXt 2.17.0. |
| 2 | +# If you modify this file, PreTeXt will no longer automatically update it. |
| 3 | +# |
| 4 | +# This workflow file can be used to automatically build a project and create |
| 5 | +# an artifact for deployment. It can also be used to deploy the project to |
| 6 | +# GitHub Pages or Cloudflare Pages. |
| 7 | +# |
| 8 | +# The workflow is triggered on pull requests or can be run manually. You can uncomment |
| 9 | +# the `push` event to have it run on pushes to the main branch as well. |
| 10 | +name: PreTeXt-CLI Actions |
| 11 | +on: |
| 12 | + # Runs on pull requests |
| 13 | + pull_request: |
| 14 | + branches: ["*"] |
| 15 | + ## Runs on pushes to main |
| 16 | + #push: |
| 17 | + # branches: ["main"] |
| 18 | + # Runs on demand |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + container: oscarlevin/pretext:full |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout source |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: install deps |
| 31 | + run: pip install -r requirements.txt |
| 32 | + |
| 33 | + - name: install local ptx files |
| 34 | + run: pretext --version |
| 35 | + |
| 36 | + - name: build deploy targets |
| 37 | + run: | |
| 38 | + version="$(pretext --version)" |
| 39 | + major="$(echo $version | cut -d '.' -f 1)" |
| 40 | + minor="$(echo $version | cut -d '.' -f 2)" |
| 41 | + if [ "$major" -ge 2 -a "$minor" -ge 5 ]; then |
| 42 | + echo "PreTeXt version is 2.5 or greater; using new build command" |
| 43 | + pretext build --deploys |
| 44 | + else |
| 45 | + echo "PreTeXt version is less than 2.5, using old build command" |
| 46 | + pretext build |
| 47 | + fi |
| 48 | + - name: stage deployment |
| 49 | + run: pretext deploy --stage-only |
| 50 | + |
| 51 | + - name: Bundle output/stage as artifact |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: deploy |
| 55 | + path: output/stage |
| 56 | + |
| 57 | + deploy-cloudflare: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: build |
| 60 | + if: vars.CLOUDFLARE_PROJECT_NAME != '' |
| 61 | + permissions: |
| 62 | + contents: read |
| 63 | + deployments: write |
| 64 | + |
| 65 | + steps: |
| 66 | + - name: Download artifact |
| 67 | + uses: actions/download-artifact@v4 |
| 68 | + with: |
| 69 | + name: deploy |
| 70 | + path: deploy |
| 71 | + - name: Create 404.html |
| 72 | + run: echo "404 page not found" >> deploy/404.html |
| 73 | + - name: Publish to Cloudflare |
| 74 | + uses: cloudflare/pages-action@v1 |
| 75 | + with: |
| 76 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 77 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 78 | + projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }} |
| 79 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + branch: ${{ github.head_ref || github.ref_name }} |
| 81 | + directory: deploy |
| 82 | + |
| 83 | + deploy-ghpages: |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: build |
| 86 | + if: vars.PTX_ENABLE_DEPLOY_GHPAGES == 'yes' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) |
| 87 | + permissions: |
| 88 | + contents: read |
| 89 | + pages: write |
| 90 | + id-token: write |
| 91 | + concurrency: |
| 92 | + group: "page" |
| 93 | + cancel-in-progress: false |
| 94 | + environment: |
| 95 | + name: github-pages |
| 96 | + url: ${{ steps.deployment.outputs.page_url }} |
| 97 | + steps: |
| 98 | + - name: Download website artifact |
| 99 | + uses: actions/download-artifact@v4 |
| 100 | + with: |
| 101 | + name: deploy |
| 102 | + path: deploy |
| 103 | + - name: Setup GitHub Pages |
| 104 | + id: check |
| 105 | + uses: actions/configure-pages@v4 |
| 106 | + - name: Upload artifact |
| 107 | + uses: actions/upload-pages-artifact@v3 |
| 108 | + with: |
| 109 | + path: deploy |
| 110 | + - name: Deploy to Github Pages |
| 111 | + id: deployment |
| 112 | + uses: actions/deploy-pages@v4 |
0 commit comments