Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: deploy docs preview on pr #261

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions .github/workflows/docs_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,53 @@ on:
- docs/**
- .github/workflows/docs_publish.yml
- packages/contrast-docs/**
pull_request:
types:
- opened
- reopened
- synchronize
- closed
paths:
- docs/**
- .github/workflows/docs_publish.yml
- packages/contrast-docs/**

permissions:
contents: write
pull-requests: write

jobs:
deploy:
name: Publish docs to GitHub Pages
runs-on: ubuntu-22.04
env:
PREVIEW: ${{ github.event_name == 'pull_request' && github.ref_name != 'main' }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: ./.github/actions/setup_nix
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
cachixToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Build website

- name: Build production website
if: (!env.PREVIEW)
run: |
nix build .#contrast-docs
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@373f7f263a76c20808c831209c920827a82a2847 # v3.9.3
- name: Publish docs to GitHub Pages
if: (!env.PREVIEW)
uses: JamesIves/github-pages-deploy-action@65b5dfd4f5bcd3a7403bbc2959c144256167464e # v4.5.0
with:
folder: ./result
branch: gh-pages
clean-exclude: pr-preview
force: false

- name: Build preview website
if: env.PREVIEW
run: |
nix build --impure --expr "(builtins.getFlake \"git+file://$(pwd)?shallow=1\").outputs.legacyPackages.x86_64-linux.contrast-docs.override { docusaurusBaseUrl = \"contrast/pr-preview/pr-${{ github.event.number }}\"; }"
- name: Deploy preview
if: env.PREVIEW
uses: rossjrw/pr-preview-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./result
user_name: edgelessci
user_email: [email protected]
source-dir: ./result
1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

1 change: 0 additions & 1 deletion docs/static/_redirects

This file was deleted.

9 changes: 7 additions & 2 deletions packages/by-name/contrast-docs/package.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{ fetchYarnDeps
{ lib
, fetchYarnDeps
, mkYarnPackage
, contrast

# Configure the base URL when deploying previews under a subpath
, docusaurusBaseUrl ? ""
}:

mkYarnPackage rec {
Expand All @@ -18,6 +22,8 @@ mkYarnPackage rec {
configurePhase = ''
cp -r $node_modules node_modules
chmod +w node_modules
'' + lib.optionalString (docusaurusBaseUrl != "") ''
sed -i "s|baseUrl: '/contrast/',|baseUrl: '${docusaurusBaseUrl}',|" docusaurus.config.js
'';

buildPhase = ''
Expand All @@ -30,6 +36,5 @@ mkYarnPackage rec {
installPhase = ''
mkdir -p $out
cp -R build/* $out
cp CNAME $out
'';
}