diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml
index 28960e8df..220c50c8b 100644
--- a/.github/workflows/publish-docs.yml
+++ b/.github/workflows/publish-docs.yml
@@ -1,8 +1,7 @@
name: Publish docs
+
on:
push:
- branches:
- - main
permissions:
contents: read
@@ -16,34 +15,40 @@ concurrency:
jobs:
build:
runs-on: ubuntu-latest
-
steps:
- - uses: actions/checkout@v4
+ - name: Checkout ⬇️
+ uses: actions/checkout@v4
with:
fetch-depth: 0
-
- - uses: actions/setup-node@v4
+ - name: Setup Node 🎛️
+ uses: actions/setup-node@v4
with:
node-version: 20
cache: "yarn"
registry-url: "https://registry.npmjs.org"
-
- - run: yarn install --immutable
- - uses: nrwl/nx-set-shas@v4
- - if: github.ref != 'refs/heads/main'
+ - name: Yarn Install 📦️
+ run: yarn install --immutable
+ - name: Setup NX 1/2 🎛️
+ uses: nrwl/nx-set-shas@v4
+ - name: Setup NX 2/2 🎛
+ if: github.ref != 'refs/heads/main'
run: git branch --track main origin/main
- - run: yarn nx affected -t build --parallel=3
+ - name: Build 🔨
+ run: yarn build
- - uses: actions/configure-pages@v4
+ - name: Configure GitHub pages ⚙️
+ uses: actions/configure-pages@v4
with:
static_site_generator: next
- - name: Upload artifact
+ - name: Upload artifact ⬆️
uses: actions/upload-pages-artifact@v3
with:
path: packages/docs/out
+ name: site
deploy:
+ if: github.ref == 'refs/heads/main'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
@@ -55,3 +60,54 @@ jobs:
- name: Publish to GitHub Pages 🚀
id: deployment
uses: actions/deploy-pages@v4
+
+ deploy-preview:
+ if: github.ref != 'refs/heads/main'
+ environment:
+ name: github-pages-preview
+ url:
+ https://mittwald.github.io/flow-previews/${{
+ github.event.pull_request.number }}
+
+ runs-on: ubuntu-latest
+ needs: build
+
+ steps:
+ - name: Download the artifact ⬇️
+ uses: actions/download-artifact@v3
+ with:
+ name: "site"
+ path: docs
+
+ - name: Upload files to GitHub Pages 🚀
+ uses: cpina/github-action-push-to-another-repository@v1
+ env:
+ API_TOKEN_GITHUB: ${{ secrets.PUBLISH_PAT }}
+ with:
+ source-directory: "docs"
+ destination-github-username: "mittwald-machine"
+ destination-repository-name: "flow-previews"
+ target-branch: master
+ target-directory: "docs/${{ github.event.pull_request.number }}"
+
+ - name: Output the URL
+ run: echo "${{ jobs.deploy-preview.environment.url }}"
+
+ comment-on-pull-request:
+ runs-on: ubuntu-latest
+ permissions:
+ pull-requests: write
+ # Only run if a comment was not already made
+ if:
+ ${{ github.event_name == 'pull_request' && github.event.action == 'opened'
+ && !contains(github.event.pull_request.body, 'A [live preview]') }}
+ steps:
+ - uses: actions/github-script@v5
+ with:
+ script: |
+ github.rest.issues.createComment({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: 'A [live preview](${{ jobs.deploy-preview.environment.url }}) is being deployed!
Please note that it may take a few seconds for GitHub Pages to build and deploy.'
+ })