Skip to content

Commit 156bb42

Browse files
MoX678viferga
andauthored
Add Ci Preview & Deploy (#13)
* added my tutorial cliamtic changed the style and modified it added windows installation added the windows installation * Modified the docs * intiai implementation * Add pull-requests permission to CI workflow * remove the old * Remove GitHub Actions workflow for Docusaurus deployment * trigger deploy * 12 * change main to master * Update baseUrl in Docusaurus config for correct deployment path * trigger preview 1 * Inject dynamic baseUrl into Docusaurus config for pull requests * Remove redundant checkout step in build preview workflow * Refactor build preview workflow: rename checkout step and simplify comment message * Refactor Docusaurus config: update navigation links to use "to" for internal routes * trigger preview 1 * Refactor build preview workflow: streamline baseUrl injection and cleanup process * Update docusaurus.config.js * Delete dummy.txt * Update Docusaurus configuration for deployment * Add deploy workflow configuration * try prettier checks * try prettier checks 2 * add husky to check before commiting * remove deprecates and resolve build * make node version 22 * spilt to parallel jobs * add caching between jops * add names for better formatting * Use single quotes, improve general configuration, improve ci." * Trying to make work the ci. * Using double quotes again. --------- Co-authored-by: Vicente Eduardo Ferrer Garcia <[email protected]>
1 parent 4e3d8c6 commit 156bb42

File tree

15 files changed

+8474
-3063
lines changed

15 files changed

+8474
-3063
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.docusaurus
3+
build
4+
static

.eslintrc.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// .eslintrc.js
2+
module.exports = {
3+
root: true,
4+
extends: [
5+
"plugin:@docusaurus/recommended",
6+
"plugin:mdx/recommended",
7+
"plugin:import/recommended",
8+
],
9+
plugins: ["@docusaurus", "mdx", "import"],
10+
parserOptions: {
11+
ecmaVersion: 2021,
12+
sourceType: "module",
13+
ecmaFeatures: {
14+
jsx: true,
15+
},
16+
},
17+
18+
settings: {
19+
react: {
20+
version: "detect",
21+
},
22+
// Fix for import resolution if you keep getting import errors
23+
"import/resolver": {
24+
node: {
25+
extensions: [".js", ".jsx", ".ts", ".tsx"],
26+
},
27+
},
28+
},
29+
rules: {
30+
"@docusaurus/no-untranslated-text": "off",
31+
"@docusaurus/string-literal-i18n-messages": "error",
32+
33+
// Suggest using Docusaurus headings, but don't error out
34+
"@docusaurus/prefer-docusaurus-heading": "warn",
35+
36+
// Import rules
37+
"import/no-unresolved": [
38+
"error",
39+
{ ignore: ["^@theme", "^@docusaurus", "^@site"] },
40+
],
41+
"import/no-named-as-default": "off",
42+
},
43+
};

.github/workflows/deploy.yml

Lines changed: 110 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,134 @@
1-
name: Test and Deploy Docusaurus
1+
name: Docs CI
22

33
on:
4-
workflow_dispatch:
5-
pull_request:
64
push:
7-
branches:
8-
- master
5+
branches: [master]
6+
pull_request:
7+
types: [opened, synchronize, reopened, closed]
8+
9+
permissions:
10+
contents: write
11+
pages: write
12+
id-token: write
13+
pull-requests: write
914

1015
jobs:
1116
build:
12-
name: Build Docusaurus
17+
name: Build Site
18+
if: github.event.action != 'closed'
1319
runs-on: ubuntu-latest
20+
1421
steps:
15-
- uses: actions/checkout@v4
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
1627
with:
17-
fetch-depth: 0
18-
- uses: actions/setup-node@v4
28+
node-version: 22
29+
30+
- name: Cache npm dependencies
31+
uses: actions/cache@v4
1932
with:
20-
node-version: 18
21-
cache: npm
33+
path: ~/.npm
34+
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
35+
restore-keys: |
36+
${{ runner.os }}-node-
2237
2338
- name: Install dependencies
24-
run: npm ci
25-
- name: Build website
39+
run: npm ci --prefer-offline
40+
41+
- name: Lint Code (ESLint)
42+
run: npm run lint
43+
44+
- name: Check Formatting (Prettier)
45+
run: npm run format
46+
47+
- name: Inject correct baseUrl into docusaurus.config.js
48+
id: inject
49+
run: |
50+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
51+
BASE_URL="/${{ github.event.repository.name }}/pr-${{ github.event.number }}/"
52+
else
53+
BASE_URL="/${{ github.event.repository.name }}/"
54+
fi
55+
56+
echo "Using baseUrl=$BASE_URL"
57+
echo "baseUrl=$BASE_URL" >> $GITHUB_OUTPUT
58+
59+
sed -i "s|baseUrl: '.*'|baseUrl: '$BASE_URL'|" docusaurus.config.js
60+
61+
- name: Build Docusaurus site
2662
run: npm run build
2763

28-
- name: Upload Build Artifact
29-
if: github.event_name != 'pull_request'
30-
uses: actions/upload-pages-artifact@v3
64+
- name: Upload site build as artifact
65+
uses: actions/upload-artifact@v4
3166
with:
67+
name: docusaurus-build
3268
path: build
3369

3470
deploy:
35-
name: Deploy to GitHub Pages
71+
name: Deploy Preview
3672
needs: build
37-
if: github.event_name != 'pull_request'
73+
if: github.event.action != 'closed'
74+
runs-on: ubuntu-latest
3875

39-
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
40-
permissions:
41-
pages: write # to deploy to Pages
42-
id-token: write # to verify the deployment originates from an appropriate source
76+
steps:
77+
- name: Download build artifact
78+
uses: actions/download-artifact@v4
79+
with:
80+
name: docusaurus-build
81+
path: build
4382

44-
# Deploy to the github-pages environment
45-
environment:
46-
name: github-pages
47-
url: ${{ steps.deployment.outputs.page_url }}
83+
- name: Determine deploy target
84+
id: vars
85+
run: |
86+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
87+
echo "destination_dir=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT
88+
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-${{ github.event.number }}/" >> $GITHUB_OUTPUT
89+
else
90+
echo "destination_dir=." >> $GITHUB_OUTPUT
91+
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" >> $GITHUB_OUTPUT
92+
fi
4893
94+
- name: Deploy to GitHub Pages
95+
uses: peaceiris/actions-gh-pages@v4
96+
with:
97+
github_token: ${{ secrets.GITHUB_TOKEN }}
98+
publish_dir: ./build
99+
publish_branch: gh-pages
100+
destination_dir: ${{ steps.vars.outputs.destination_dir }}
101+
keep_files: true
102+
103+
- name: Comment preview link on PR
104+
if: github.event_name == 'pull_request'
105+
uses: marocchino/sticky-pull-request-comment@v2
106+
with:
107+
header: docusaurus-preview
108+
message: |
109+
🚀 **Preview Deployed**
110+
🔗 [View Preview](${{ steps.vars.outputs.url }})
111+
112+
cleanup:
113+
name: Cleanup Preview
114+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
49115
runs-on: ubuntu-latest
116+
50117
steps:
51-
- name: Deploy to GitHub Pages
52-
id: deployment
53-
uses: actions/deploy-pages@v4
118+
- name: Checkout gh-pages
119+
uses: actions/checkout@v4
120+
with:
121+
ref: gh-pages
122+
123+
- name: Remove PR preview directory
124+
run: |
125+
git config user.name "github-actions[bot]"
126+
git config user.email "github-actions[bot]@users.noreply.github.com"
127+
128+
if [ -d "pr-${{ github.event.pull_request.number }}" ]; then
129+
git rm -rf pr-${{ github.event.pull_request.number }}
130+
git commit -m "🧹 Remove preview for PR #${{ github.event.pull_request.number }}"
131+
git push
132+
else
133+
echo "Directory pr-${{ github.event.pull_request.number }} not found, skipping cleanup"
134+
fi

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
echo "▶ Running Prettier..."
3+
npx lint-staged

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll.eslint": "explicit"
6+
},
7+
"[markdown]": {
8+
"editor.defaultFormatter": "esbenp.prettier-vscode"
9+
},
10+
"[javascript]": {
11+
"editor.defaultFormatter": "esbenp.prettier-vscode"
12+
}
13+
}

docs/tutorials/treetraversal.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DocusaurusTreeVisualization from "@site/src/components/TreeTraversal/DocusaurusWrapper";
1+
import DocusaurusTreeVisualization from '@site/src/components/TreeTraversal/DocusaurusWrapper';
22

33
# Traversing a Polyglot Tree with MetaCall
44
import StarRepo from '@site/src/components/StarRepo';

0 commit comments

Comments
 (0)