Skip to content

Commit

Permalink
Generate a preview website for documentation PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Jan 25, 2023
1 parent d004bcf commit e481d4c
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/src/main/asciidoc/**'
- '.github/workflows/doc-build.yml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'docs/src/main/asciidoc/**'
- '.github/workflows/doc-build.yml'
Expand Down Expand Up @@ -58,3 +59,16 @@ jobs:
- name: Build Docs
run: |
./mvnw -e -B --settings .github/mvn-settings.xml clean package -pl docs
- name: Store PR id
run: echo ${{ github.event.number }} > pr-id.txt

- name: Persist documentation
uses: actions/upload-artifact@v3
with:
name: documentation
path: |
pr-id.txt
docs/
target/asciidoc/generated/config/
retention-days: 1
22 changes: 22 additions & 0 deletions .github/workflows/preview-teardown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Surge.sh Preview Teardown

on:
pull_request_target:
types: [closed]

jobs:
preview-teardown:
runs-on: ubuntu-latest
steps:
- name: Teardown surge preview
id: deploy
run: npx surge teardown https://quarkus-io-pr-main-${{ steps.pr.outputs.id }}-preview.surge.sh --token ${{ secrets.SURGE_TOKEN }}
- name: Update PR status comment
uses: actions-cool/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
🙈 The PR is closed and the preview is expired.
<!-- Sticky Pull Request Comment -->
body-include: '<!-- Sticky Pull Request Comment -->'
number: ${{ github.event.number }}
100 changes: 100 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Surge.sh Preview

on:
workflow_run:
workflows: ["Quarkus Documentation CI"]
types:
- completed

jobs:
preview:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
steps:
- name: Download PR Artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success
name: documentation
path: documentation
- name: Store PR id as variable
id: pr
run: |
echo "id=$(<documentation/pr-id.txt)" >> $GITHUB_OUTPUT
rm -f pr-id.txt
- uses: actions/checkout@v3
with:
repository: quarkusio/quarkusio.github.io
path: quarkusio
- name: Sync documentation
shell: bash
run: |
chmod 755 ./documentation/docs/sync-web-site.sh
./documentation/docs/sync-web-site.sh main ../../quarkusio/
- name: Set up ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7 # can change this to 2.7 or whatever version you prefer
- name: Build Jekyll site
uses: limjh16/jekyll-action-ts@v2
with:
enable_cache: true
### Enables caching. Similar to https://github.com/actions/cache.
#
format_output: false
### Uses prettier https://prettier.io to format jekyll output HTML.
#
# prettier_opts: '{ "useTabs": true }'
### Sets prettier options (in JSON) to format output HTML. For example, output tabs over spaces.
### Possible options are outlined in https://prettier.io/docs/en/options.html
#
prettier_ignore: '*'
### Ignore paths for prettier to not format those html files.
### Useful if the file is exceptionally large, so formatting it takes a while.
### Also useful if HTML compression is enabled for that file / formatting messes it up.
#
# jekyll_src: sample_site
### If the jekyll website source is not in root, specify the directory. (in this case, sample_site)
### By default, this is not required as the action searches for a _config.yml automatically.
#
gem_src: quarkusio
### By default, this is not required as the action searches for a _config.yml automatically.
### However, if there are multiple Gemfiles, the action may not be able to determine which to use.
### In that case, specify the directory. (in this case, sample_site)
###
### If jekyll_src is set, the action would automatically choose the Gemfile in jekyll_src.
### In that case this input may not be needed as well.
#
# key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
# restore-keys: ${{ runner.os }}-gems-
### In cases where you want to specify the cache key, enable the above 2 inputs
### Follows the format here https://github.com/actions/cache
#
# custom_opts: '--future'
### If you need to specify any Jekyll build options, enable the above input
### Flags accepted can be found here https://jekyllrb.com/docs/configuration/options/#build-command-options
- name: Publishing to surge for preview
id: deploy
run: npx surge ./quarkusio/_site --domain https://quarkus-io-pr-main-${{ steps.pr.outputs.id }}-preview.surge.sh --token ${{ secrets.SURGE_TOKEN }}
- name: Update PR status comment on success
uses: actions-cool/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
🎊 PR Preview ${{ github.sha }} has been successfully built and deployed to https://quarkus-io-pr-main-${{ steps.pr.outputs.id }}-preview.surge.sh/version/main/guides/
<img width="300" src="https://user-images.githubusercontent.com/507615/90250366-88233900-de6e-11ea-95a5-84f0762ffd39.png">
<!-- Sticky Pull Request Comment -->
body-include: '<!-- Sticky Pull Request Comment -->'
number: ${{ steps.pr.outputs.id }}
- name: Update PR status comment on failure
if: ${{ failure() }}
uses: actions-cool/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
😭 Deploy PR Preview failed.
<img width="300" src="https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png">
<!-- Sticky Pull Request Comment -->
body-include: '<!-- Sticky Pull Request Comment -->'
number: ${{ steps.pr.outputs.id }}

0 comments on commit e481d4c

Please sign in to comment.