Skip to content

Commit

Permalink
Merge pull request #122 from gradle/previews
Browse files Browse the repository at this point in the history
Enable previews of the community site
  • Loading branch information
oleg-nenashev authored Nov 14, 2024
2 parents dea5eb5 + 51a25cd commit 1204151
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ jobs:
# Build job
build:
runs-on: ubuntu-latest

permissions:
contents: write
packages: read
pull-requests: write

env:
PR_PATH: ${{ github.event.repository.name }}/pull/${{github.event.number}}
DOMAIN: gradle.github.io
PREVIEW_REPO: community-site-preview

steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -28,3 +39,27 @@ jobs:

- name: Build the docs
run: mkdocs build

- name: Deploy to PR preview
uses: peaceiris/actions-gh-pages@v4
if: github.ref != 'refs/heads/main'
with:
deploy_key: ${{ secrets.PREVIEW_DEPLOYMENT_KEY }}
external_repository: gradle/${{ env.PREVIEW_REPO }}
publish_dir: ./_site
destination_dir: ${{ env.PR_PATH }}

- name: Update comment
uses: hasura/[email protected]
if: github.ref != 'refs/heads/main'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: >
A preview of ${{ github.event.after }} is uploaded and can be seen here:
✨ https://${{ env.DOMAIN }}/${{ env.PREVIEW_REPO }}/${{ env.PR_PATH}}/ ✨
Changes may take a few minutes to propagate.
37 changes: 37 additions & 0 deletions .github/workflows/preview-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Delete preview on PR close
on:
pull_request:
types: [closed]

jobs:
delete_preview:
runs-on: ubuntu-20.04
env:
PR_PATH: ${{ github.event.repository.name }}/pull/${{github.event.number}}
DOMAIN: gradle.github.io
PREVIEW_REPO: community-site-preview

permissions:
pull-requests: write

steps:
- name: make empty dir
run: mkdir public

- name: delete folder
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.PREVIEW_DEPLOYMENT_KEY }}
external_repository: gradle/${{ env.PREVIEW_REPO }}
publish_dir: ./public
destination_dir: ${{ env.PR_PATH }}

- name: Comment on PR
uses: hasura/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: >
🪓 PR closed, deleted preview at https://github.com/${{ env.PREVIEW_REPO }}/tree/gh-pages/${{ env.PR_PATH }}/
3 changes: 2 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Run `BUILD_PDF=1 mkdocs build` to generate the PDF file in [_site/pdf/cookbook.p

## CI/CD

This site is built and deployed by GitHub Actions.
This site is built and deployed by GitHub Actions,
as well as previews in the pull requests.
We have continuous delivery, so your patches will be delivered just a few minutes
after the change is merged.

0 comments on commit 1204151

Please sign in to comment.