Skip to content

Commit 5a137a8

Browse files
committed
update dev.yml and prod.yml with concurrency to avoid double run
1 parent e1cfc6d commit 5a137a8

File tree

2 files changed

+99
-18
lines changed

2 files changed

+99
-18
lines changed

.github/workflows/dev.yaml

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,102 @@
11
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
34
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
515

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
724

825
jobs:
9-
build-deploy:
26+
build-render:
27+
if: github.event.action != 'closed' # If closing the PR, no publishing
1028
runs-on: ubuntu-latest
29+
# To cancel previous actions that could run on this PR
1130
steps:
1231
- 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
1460

15-
- uses: actions/setup-python@v4
61+
- name: Deploy preview
62+
id: deploy-preview
63+
uses: rossjrw/[email protected]
1664
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+
uses: rossjrw/[email protected]
2093
with:
21-
version: 1.7.31
94+
action: remove
2295

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
2598
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 }}

.github/workflows/prod.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
# Workflow run only on pushes to main and manual trigger
12
on:
23
workflow_dispatch:
4+
# cf https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflow_dispatch
35
push:
46
branches: main
57

6-
name: Quarto Publish
8+
name: CI - Quarto Publish
9+
10+
# Cancel previous workflow of ci that could be running
11+
concurrency:
12+
group: ci-${{ github.ref }} # preview followed by the reference of the branch or tag that triggered the workflow
13+
cancel-in-progress: true
714

815
jobs:
916
build-deploy:
1017
runs-on: ubuntu-latest
1118
steps:
1219
- name: Check out repository
13-
uses: actions/checkout@v3
20+
uses: actions/checkout@v3
1421

1522
- uses: actions/setup-python@v4
1623
with:
@@ -20,7 +27,7 @@ jobs:
2027
with:
2128
version: 1.7.31
2229

23-
- name: Render and Publish
30+
- name: Render and Publish
2431
uses: quarto-dev/quarto-actions/publish@v2
2532
with:
2633
target: netlify

0 commit comments

Comments
 (0)