Skip to content

Commit e09f455

Browse files
first pass
1 parent 53704dc commit e09f455

File tree

7 files changed

+194
-8
lines changed

7 files changed

+194
-8
lines changed

.github/workflows/pr-preview.yaml

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
name: Deploy PR Preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, closed]
6+
7+
# Cancel previous runs when new commits are pushed to the PR
8+
concurrency:
9+
group: pr-preview-${{ github.event.pull_request.number }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
deploy-preview:
14+
name: Deploy PR Preview
15+
runs-on: ubuntu-latest
16+
if: github.event.action != 'closed'
17+
permissions:
18+
pull-requests: write
19+
deployments: write
20+
contents: read
21+
22+
steps:
23+
- name: Checkout PR code
24+
uses: actions/checkout@v6
25+
with:
26+
ref: ${{ github.event.pull_request.head.sha }}
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v6
30+
with:
31+
node-version: '22'
32+
cache: 'npm'
33+
cache-dependency-path: 'package-lock.json'
34+
35+
- name: Install dependencies
36+
run: |
37+
echo "Installing dependencies..."
38+
npm ci
39+
40+
- name: Build Docusaurus site
41+
env:
42+
DOCUSAURUS_BASE_URL: /pr-${{ github.event.pull_request.number }}
43+
run: |
44+
echo "Building site with base URL: $DOCUSAURUS_BASE_URL"
45+
npm run build
46+
47+
- name: Prepare deployment directory
48+
run: |
49+
PR_DIR="pr-${{ github.event.pull_request.number }}"
50+
echo "Creating directory: $PR_DIR"
51+
mkdir -p "$PR_DIR"
52+
53+
# Create config.yaml
54+
cat > "$PR_DIR/config.yaml" << 'EOF'
55+
static:
56+
files: 'build/**'
57+
urlPath: 'pr-${{ github.event.pull_request.number }}'
58+
extensions: ['html']
59+
index: true
60+
EOF
61+
62+
# Copy build directory
63+
cp -r build "$PR_DIR/"
64+
65+
echo "Contents of $PR_DIR:"
66+
ls -la "$PR_DIR"
67+
68+
- name: Install HarperDB CLI
69+
run: |
70+
npm install harperdb
71+
72+
- name: Deploy to HarperDB
73+
env:
74+
HARPER_PREVIEW_TARGET: ${{ secrets.HARPER_PREVIEW_TARGET }}
75+
HARPER_PREVIEW_USERNAME: ${{ secrets.HARPER_PREVIEW_USERNAME }}
76+
HARPER_PREVIEW_PASSWORD: ${{ secrets.HARPER_PREVIEW_PASSWORD }}
77+
run: |
78+
cd "$PR_DIR"
79+
# Add your additional arguments here
80+
npx harper deploy \
81+
target=$HARPER_PREVIEW_TARGET \
82+
username=$HARPER_PREVIEW_USERNAME \
83+
password=$HARPER_PREVIEW_PASSWORD \
84+
project=pr-${{ github.event.pull_request.number }} \
85+
restart=true \
86+
replicated=true
87+
88+
- name: Create deployment
89+
env:
90+
HARPER_PREVIEW_TARGET: ${{ secrets.HARPER_PREVIEW_TARGET }}
91+
uses: actions/github-script@v8
92+
with:
93+
script: |
94+
const prNumber = context.payload.pull_request.number;
95+
const target = process.env.HARPER_PREVIEW_TARGET;
96+
const deploymentUrl = `${target}/pr-${prNumber}`;
97+
98+
// Create deployment
99+
const deployment = await github.rest.repos.createDeployment({
100+
owner: context.repo.owner,
101+
repo: context.repo.repo,
102+
ref: context.payload.pull_request.head.sha,
103+
environment: `pr-${prNumber}`,
104+
description: `Preview deployment for PR #${prNumber}`,
105+
auto_merge: false,
106+
required_contexts: []
107+
});
108+
109+
// Create deployment status
110+
await github.rest.repos.createDeploymentStatus({
111+
owner: context.repo.owner,
112+
repo: context.repo.repo,
113+
deployment_id: deployment.data.id,
114+
state: 'success',
115+
environment_url: deploymentUrl,
116+
description: 'Preview deployment successful'
117+
});
118+
119+
// Also add a comment to the PR
120+
await github.rest.issues.createComment({
121+
owner: context.repo.owner,
122+
repo: context.repo.repo,
123+
issue_number: prNumber,
124+
body: `## 🚀 Preview Deployment\n\nYour preview deployment is ready!\n\n🔗 **Preview URL:** ${deploymentUrl}\n\nThis preview will update automatically when you push new commits.`
125+
});
126+
127+
cleanup-preview:
128+
name: Cleanup PR Preview
129+
runs-on: ubuntu-latest
130+
if: github.event.action == 'closed'
131+
permissions:
132+
pull-requests: write
133+
deployments: write
134+
contents: read
135+
136+
steps:
137+
- name: Checkout code
138+
uses: actions/checkout@v6
139+
140+
- name: Setup Node.js
141+
uses: actions/setup-node@v6
142+
with:
143+
node-version: '22'
144+
cache: 'npm'
145+
cache-dependency-path: 'package-lock.json'
146+
147+
- name: Install HarperDB CLI
148+
run: |
149+
npm install harperdb
150+
151+
- name: Remove preview deployment
152+
run: |
153+
# Add your cleanup command here (e.g., harper undeploy or similar)
154+
npx harper drop-component project=pr-${{ github.event.pull_request.number }} replicated=true restart=true
155+
echo "Cleaning up preview for PR #${{ github.event.pull_request.number }}"
156+
157+
- name: Update deployment status
158+
uses: actions/github-script@v7
159+
with:
160+
script: |
161+
const prNumber = context.payload.pull_request.number;
162+
163+
// Mark deployment as inactive
164+
const deployments = await github.rest.repos.listDeployments({
165+
owner: context.repo.owner,
166+
repo: context.repo.repo,
167+
environment: `pr-${prNumber}`
168+
});
169+
170+
for (const deployment of deployments.data) {
171+
await github.rest.repos.createDeploymentStatus({
172+
owner: context.repo.owner,
173+
repo: context.repo.repo,
174+
deployment_id: deployment.id,
175+
state: 'inactive',
176+
description: 'Preview deployment removed'
177+
});
178+
}
179+
180+
// Add cleanup comment to PR
181+
await github.rest.issues.createComment({
182+
owner: context.repo.owner,
183+
repo: context.repo.repo,
184+
issue_number: prNumber,
185+
body: `## 🧹 Preview Cleanup\n\nThe preview deployment for this PR has been removed.`
186+
});

docs/developers/applications/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ This guide is going to walk you through building a basic Harper application usin
8181
8282
## Custom Functionality with JavaScript
8383

84-
[The getting started guide](../../learn/) covers how to build an application entirely through schema configuration. However, if your application requires more custom functionality, you will probably want to employ your own JavaScript modules to implement more specific features and interactions. This gives you tremendous flexibility and control over how data is accessed and modified in Harper. Let's take a look at how we can use JavaScript to extend and define "resources" for custom functionality. In Harper, data is accessed through our [Resource API](../../reference/resources/), a standard interface to access data sources, tables, and make them available to endpoints. Database tables are `Resource` classes, and so extending the function of a table is as simple as extending their class.
84+
[The getting started guide](/learn/) covers how to build an application entirely through schema configuration. However, if your application requires more custom functionality, you will probably want to employ your own JavaScript modules to implement more specific features and interactions. This gives you tremendous flexibility and control over how data is accessed and modified in Harper. Let's take a look at how we can use JavaScript to extend and define "resources" for custom functionality. In Harper, data is accessed through our [Resource API](../../reference/resources/), a standard interface to access data sources, tables, and make them available to endpoints. Database tables are `Resource` classes, and so extending the function of a table is as simple as extending their class.
8585

8686
To define custom (JavaScript) resources as endpoints, we need to create a `resources.js` module (this goes in the root of your application folder). And then endpoints can be defined with Resource classes that `export`ed. This can be done in addition to, or in lieu of the `@export`ed types in the schema.graphql. If you are exporting and extending a table you defined in the schema make sure you remove the `@export` from the schema so that don't export the original table or resource to the same endpoint/path you are exporting with a class. Resource classes have methods that correspond to standard HTTP/REST methods, like `get`, `post`, `patch`, and `put` to implement specific handling for any of these methods (for tables they all have default implementations). Let's add a property to the dog records when they are returned, that includes their age in human years. To do this, we get the `Dog` class from the defined tables, extend it (with our custom logic), and export it:
8787

@@ -117,8 +117,8 @@ type Breed @table {
117117
We use the new table's (static) `get()` method to retrieve a breed by id. Harper will maintain the current context, ensuring that we are accessing the data atomically, in a consistent snapshot across tables. This provides:
118118

119119
1. Automatic tracking of most recently updated timestamps across resources for caching purposes
120-
1. Sharing of contextual metadata (like user who requested the data)
121-
1. Transactional atomicity for any writes (not needed in this get operation, but important for other operations)
120+
2. Sharing of contextual metadata (like user who requested the data)
121+
3. Transactional atomicity for any writes (not needed in this get operation, but important for other operations)
122122

123123
The resource methods are automatically wrapped with a transaction and will automatically commit the changes when the method finishes. This allows us to fully utilize multiple resources in our current transaction. With our own snapshot of the database for the Dog and Breed table we can then access data like this:
124124

docs/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Here, you'll find all things Harper, and everything you need to get started, tro
1919

2020
## Getting Started
2121

22-
The best way to get started using Harper is to head over to the [Learn](../learn/) section and work through the Getting Started and Developer guides.
22+
The best way to get started using Harper is to head over to the [Learn](/learn/) section and work through the Getting Started and Developer guides.
2323

2424
## Building with Harper
2525

fabric/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Fabric Studio is the web-based GUI for Harper. Studio enables you to administer,
88

99
[Sign up for free!](https://fabric.harper.fast/#/sign-up)
1010

11-
Harper includes a simplified local Studio that is packaged with all Harper installations and served directly from the cluster. It can be enabled in the [configuration file](../docs/deployments/configuration#localstudio). This section is dedicated to the hosted Studio accessed at [studio.harperdb.io](https://fabric.harper.fast/).
11+
Harper includes a simplified local Studio that is packaged with all Harper installations and served directly from the cluster. It can be enabled in the [configuration file](/docs/deployments/configuration#localstudio). This section is dedicated to the hosted Studio accessed at [studio.harperdb.io](https://fabric.harper.fast/).
1212

1313
---
1414

versioned_docs/version-4.5/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Welcome to the Harper Documentation! Here, you'll find all things Harper, and ev
1717

1818
## Getting Started
1919

20-
The best way to get started using Harper is to head over to the [Learn](../../learn/) section and work through the Getting Started and Developer guides.
20+
The best way to get started using Harper is to head over to the [Learn](/learn/) section and work through the Getting Started and Developer guides.
2121

2222
## Building with Harper
2323

versioned_docs/version-4.6/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Here, you'll find all things Harper, and everything you need to get started, tro
1919

2020
## Getting Started
2121

22-
The best way to get started using Harper is to head over to the [Learn](../../learn/) section and work through the Getting Started and Developer guides.
22+
The best way to get started using Harper is to head over to the [Learn](/learn/) section and work through the Getting Started and Developer guides.
2323

2424
## Building with Harper
2525

versioned_docs/version-4.7/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Here, you'll find all things Harper, and everything you need to get started, tro
1919

2020
## Getting Started
2121

22-
The best way to get started using Harper is to head over to the [Learn](../../learn/) section and work through the Getting Started and Developer guides.
22+
The best way to get started using Harper is to head over to the [Learn](/learn/) section and work through the Getting Started and Developer guides.
2323

2424
## Building with Harper
2525

0 commit comments

Comments
 (0)