|
1 | 1 | on: |
2 | | - workflow_dispatch: |
| 2 | + workflow_dispatch: # To allow for manuel trigger of this workflow. Cf |
| 3 | + # https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflow_dispatch |
3 | 4 | push: |
4 | | - branches: main |
| 5 | + branches-ignore: # Triggers for push to all branches but main |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: |
| 9 | + - opened |
| 10 | + - reopened |
| 11 | + - synchronize |
| 12 | + - closed # Including closed to remove preview when PR is closed. |
| 13 | + branches: |
| 14 | + - main # PR to main only |
5 | 15 |
|
6 | | -name: Quarto Publish |
| 16 | +name: Preview |
| 17 | + |
| 18 | +env: |
| 19 | + PREVIEW_BRANCH: gh-pages |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: preview-${{ github.ref }} # preview followed by the reference of the branch or tag that triggered the workflow |
| 23 | + cancel-in-progress: true |
7 | 24 |
|
8 | 25 | jobs: |
9 | | - build-deploy: |
| 26 | + build-render: |
| 27 | + if: github.event.action != 'closed' # If closing the PR, no publishing |
10 | 28 | runs-on: ubuntu-latest |
| 29 | + # To cancel previous actions that could run on this PR |
11 | 30 | steps: |
12 | 31 | - name: Check out repository |
13 | | - uses: actions/checkout@v3 |
| 32 | + uses: actions/checkout@v5 |
| 33 | + with: |
| 34 | + fetch-depth: 0 # To enable full access to Git repo |
| 35 | + ref: ${{ github.event.pull_request.head.ref }} # Reference of the commit to checkout to. To ensure it's the one of the PR |
| 36 | + repository: ${{github.event.pull_request.head.repo.full_name}} # Reference to the branch to checkout to. Useful with PR from forks |
| 37 | + |
| 38 | + # add software dependencies here and any libraries |
| 39 | + # See more at https://github.com/quarto-dev/quarto-actions/blob/main/examples/example-03-dependencies.md |
| 40 | + - name: Configure safe.directory # Workaround for actions/checkout#760 |
| 41 | + run: git config --global --add safe.directory /__w/ssphub/ssphub |
| 42 | + |
| 43 | + - name: Install npm |
| 44 | + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} |
| 45 | + uses: actions/setup-node@v2 |
| 46 | + with: |
| 47 | + node-version: '18' |
| 48 | + |
| 49 | + - name: Set up R |
| 50 | + uses: r-lib/actions/setup-r@v2 |
| 51 | + |
| 52 | + - name: Install babelquarto |
| 53 | + uses: r-lib/actions/setup-r-dependencies@v2 |
| 54 | + with: |
| 55 | + packages: | |
| 56 | + github::ropensci-review-tools/babelquarto@a485fea |
| 57 | +
|
| 58 | + - name: Render bilingual project |
| 59 | + run: Rscript scripts/render.R |
14 | 60 |
|
15 | | - - uses: actions/setup-python@v4 |
| 61 | + - name: Deploy preview |
| 62 | + id: deploy-preview |
| 63 | + |
16 | 64 | with: |
17 | | - python-version: '3.10' # Version range or exact version of a Python version to use, using SemVer's version range syntax |
18 | | - - run: pip install jupyter nbformat |
19 | | - - uses: quarto-dev/quarto-actions/setup@v2 |
| 65 | + source-dir: ./_site/ |
| 66 | + preview-branch: ${{ env.PREVIEW_BRANCH }} |
| 67 | + action: deploy |
| 68 | + comment: false |
| 69 | + |
| 70 | + - name: Comment PR (custom) |
| 71 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 72 | + with: |
| 73 | + header: pr-preview |
| 74 | + message: | |
| 75 | + :rocket: View preview at <br> ${{ steps.deploy-preview.outputs.preview-url }} <br> |
| 76 | + <h6>Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.deploy-preview.outputs.action-start-time }}. <br> Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete. <br> </h6> |
| 77 | +
|
| 78 | +
|
| 79 | + delete-preview: |
| 80 | + if: github.event.action == 'closed' # Only run when PR is closed |
| 81 | + runs-on: ubuntu-latest |
| 82 | + steps: |
| 83 | + - name: Check out repository |
| 84 | + uses: actions/checkout@v5 |
| 85 | + with: |
| 86 | + fetch-depth: 0 # To enable full access to Git repo |
| 87 | + ref: ${{ github.event.pull_request.head.ref }} # Reference of the commit to checkout to. To ensure it's the one of the PR |
| 88 | + repository: ${{github.event.pull_request.head.repo.full_name}} # Reference to the branch to checkout to. Useful with PR from forks |
| 89 | + |
| 90 | + - name: Remove preview |
| 91 | + id: remove-preview |
| 92 | + |
20 | 93 | with: |
21 | | - version: 1.7.31 |
| 94 | + action: remove |
22 | 95 |
|
23 | | - - name: Render and Publish |
24 | | - uses: quarto-dev/quarto-actions/publish@v2 |
| 96 | + - name: Comment PR that preview was removed |
| 97 | + uses: marocchino/sticky-pull-request-comment@v2 |
25 | 98 | with: |
26 | | - target: netlify |
27 | | - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
28 | | - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
| 99 | + header: pr-preview |
| 100 | + message: | |
| 101 | + Preview removed because the pull request was closed. |
| 102 | + ${{ steps.remove-preview.outputs.action-start-time }} |
0 commit comments