Skip to content

Commit 325f74b

Browse files
gnikitawvwgk
authored andcommitted
ci: add preview support
This is experimental
1 parent c4efce5 commit 325f74b

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

.github/workflows/delete_preview.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Github action to cleanup a PR preview
2+
# Runs when a pull request is merged or comment contains '#delete_preview'
3+
#
4+
5+
name: PR Preview Cleanup
6+
7+
on:
8+
issue_comment:
9+
types: [created]
10+
11+
pull_request:
12+
types:
13+
- closed
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
if: github.event.pull_request.merged == true || contains(github.event.comment.body, '#delete-preview')
19+
20+
steps:
21+
# Checkout existing gh-pages branch into PUBLISH_DIR
22+
- name: Checkout gh-pages
23+
uses: actions/checkout@v3
24+
with:
25+
ref: gh-pages
26+
27+
# Cleanup preview files
28+
- name: PR Cleanup
29+
run: rm -rf pr/${{github.event.issue.number}}
30+
31+
- name: Commit and push to gh-pages
32+
uses: EndBug/[email protected]
33+
with:
34+
message: "Sphinx build cleanup pr/${{github.event.issue.number}}"
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
38+
# Comment on pull request
39+
- name: Comment on pull request
40+
uses: peter-evans/create-or-update-comment@v2
41+
with:
42+
issue-number: ${{github.event.issue.number}}
43+
body: The preview build for this PR has now been deleted.

.github/workflows/preview.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Github action to build preview sphinx site and commit to gh-pages branch
2+
# Built site is pushed to 'gh-pages' branch
3+
#
4+
5+
name: Sphinx Preview Build
6+
7+
on:
8+
issue_comment:
9+
types: [created]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
if: github.event.issue.pull_request && contains(github.event.comment.body, '#preview')
15+
16+
steps:
17+
- name: Checkout pr/${{github.event.issue.number}}
18+
uses: actions/checkout@v3
19+
20+
- name: Fetch pr/${{github.event.issue.number}}
21+
run: |
22+
git fetch origin pull/${{github.event.issue.number}}/head:pr-${{github.event.issue.number}}
23+
git checkout pr-${{github.event.issue.number}}
24+
25+
- name: Install dependencies
26+
uses: mamba-org/provision-with-micromamba@main
27+
with:
28+
environment-file: environment.yaml
29+
30+
- name: Safe workflow for build preview
31+
run: if [ -d "_build" ]; then rm -rf _build; fi
32+
33+
- name: Build page and Translations
34+
if: contains(github.event.comment.body, '#preview')
35+
run: |
36+
make gettext html
37+
38+
- name: Create nojekyll file
39+
run: |
40+
touch _build/.nojekyll
41+
42+
- name: Deploy documentation sphinx
43+
uses: JamesIves/[email protected]
44+
with:
45+
token: ${{ secrets.GITHUB_TOKEN }}
46+
branch: gh-pages
47+
target-folder: pr/${{github.event.issue.number}}
48+
folder: _build/html
49+
clean: false
50+
git-config-email: [email protected]
51+
git-config-name: Fortran
52+
53+
- name: Comment on pull request
54+
uses: peter-evans/create-or-update-comment@v2
55+
with:
56+
issue-number: ${{github.event.issue.number}}
57+
body: "This PR has been built with Sphinx and can be previewed at: https://fortran-lang.github.io/fpm/pr/${{github.event.issue.number}}"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,9 @@ msgstr "This is "
118118

119119
After adding or updating translations
120120
build the documentation as described above.
121+
122+
## Pull Requests Previews
123+
124+
You can build the Preview of the fpm-docs website by opening a pull request
125+
and commenting `#preview` on the pull request. Similarly, you can force the
126+
deletion of the preview by commenting `#delete-preview`.

0 commit comments

Comments
 (0)