|
| 1 | +name: pages |
| 2 | + |
| 3 | +# Builds the dashboard (app/) as a Shinylive app, which runs R in the visitor's browser, |
| 4 | +# and publishes it on GitHub Pages |
| 5 | +# Pull requests only build and check the export; deploying happens from main. |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + pull_request: |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + pages: write |
| 15 | + id-token: write |
| 16 | + |
| 17 | +# one deployment at a time; a newer push waits instead of cancelling a running deployment |
| 18 | +concurrency: |
| 19 | + group: pages |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + env: |
| 26 | + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v7 |
| 30 | + |
| 31 | + - uses: r-lib/actions/setup-r@v2 |
| 32 | + with: |
| 33 | + use-public-rspm: true |
| 34 | + |
| 35 | + # shinylive bundles only packages that are installed here, so install all of the app's |
| 36 | + # (the suggested ones in DESCRIPTION) plus shinylive itself |
| 37 | + - uses: r-lib/actions/setup-r-dependencies@v2 |
| 38 | + with: |
| 39 | + dependencies: '"all"' |
| 40 | + extra-packages: any::shinylive |
| 41 | + |
| 42 | + # the app finds R/figure.R, data/ and images/ next to app.R in the bundle |
| 43 | + - name: Assemble the app |
| 44 | + run: | |
| 45 | + mkdir -p _build/app/R |
| 46 | + cp app/app.R _build/app/ |
| 47 | + cp R/figure.R _build/app/R/ |
| 48 | + cp -r data images _build/app/ |
| 49 | +
|
| 50 | + - name: Export with Shinylive |
| 51 | + run: Rscript -e 'shinylive::export("_build/app", "_site", template_params = list(title = "Scientific figure dashboard"))' |
| 52 | + |
| 53 | + - name: Check the export |
| 54 | + run: | |
| 55 | + test -f _site/index.html |
| 56 | + test -f _site/app.json |
| 57 | + for pkg in ggplot2 patchwork magick ragg svglite; do |
| 58 | + test -d "_site/shinylive/webr/packages/$pkg" || { echo "$pkg was not bundled"; exit 1; } |
| 59 | + done |
| 60 | +
|
| 61 | + - uses: actions/configure-pages@v6 |
| 62 | + if: github.ref == 'refs/heads/main' |
| 63 | + |
| 64 | + - uses: actions/upload-pages-artifact@v5 |
| 65 | + if: github.ref == 'refs/heads/main' |
| 66 | + with: |
| 67 | + path: _site |
| 68 | + |
| 69 | + deploy: |
| 70 | + needs: build |
| 71 | + if: github.ref == 'refs/heads/main' |
| 72 | + runs-on: ubuntu-latest |
| 73 | + environment: |
| 74 | + name: github-pages |
| 75 | + url: ${{ steps.deployment.outputs.page_url }} |
| 76 | + |
| 77 | + steps: |
| 78 | + - id: deployment |
| 79 | + uses: actions/deploy-pages@v5 |
0 commit comments