Skip to content

Commit a45fe13

Browse files
beep boop
1 parent 5c51eda commit a45fe13

File tree

3 files changed

+30
-39
lines changed

3 files changed

+30
-39
lines changed

.github/workflows/deploy.yaml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,27 @@
11
name: Deploy Docusaurus to GitHub Pages
22

33
on:
4-
# Trigger the workflow on pull requests and pushes to specific branches
5-
pull_request:
64
push:
75
branches:
86
- main
97
# Allows you to run this workflow manually from the Actions tab
108
workflow_dispatch:
119

1210
# Concurrency configuration to manage parallel workflow runs
13-
#
14-
# Group composition: pages-<event_type>-<unique_identifier>
15-
# - event_type: 'pull_request', 'push', or 'workflow_dispatch'
16-
# - unique_identifier: PR number for PRs, branch ref for pushes/manual runs
17-
#
18-
# Examples of group names:
19-
# - PR #123: "pages-pull_request-123"
20-
# - Push to main: "pages-push-refs/heads/main"
21-
# - Manual run on main: "pages-workflow_dispatch-refs/heads/main"
22-
#
23-
# Behavior:
24-
# - PRs: New commits cancel previous runs (cancel-in-progress: true)
25-
# - Main branch: Runs complete without cancellation (cancel-in-progress: false)
26-
# - Manual dispatch: Runs complete without cancellation (cancel-in-progress: false)
2711
concurrency:
28-
group: pages-${{ github.event_name }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }}
29-
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
12+
group: production-deploy
13+
cancel-in-progress: false
3014

3115
jobs:
3216
build:
3317
name: Build Docusaurus
3418
runs-on: ubuntu-latest
3519
steps:
36-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v6
3721
with:
3822
fetch-depth: 0
3923

40-
- uses: actions/setup-node@v4
24+
- uses: actions/setup-node@v6
4125
with:
4226
node-version: '22'
4327
cache: 'npm'
@@ -81,8 +65,6 @@ jobs:
8165
needs: build
8266
name: Deploy to GitHub Pages
8367
runs-on: ubuntu-latest
84-
# Only deploy on push to main or manual trigger, not on PRs
85-
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch'
8668

8769
permissions:
8870
pages: write

.github/workflows/pr-preview.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ jobs:
4444
echo "Building site with base URL: $DOCUSAURUS_BASE_URL"
4545
npm run build
4646
47+
- name: Upload build artifact for local testing
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: pr-${{ github.event.pull_request.number }}-build
51+
path: build/
52+
retention-days: 30
53+
4754
- name: Prepare deployment directory
4855
run: |
4956
PR_DIR="pr-${{ github.event.pull_request.number }}"
@@ -149,9 +156,19 @@ jobs:
149156
npm install harperdb
150157
151158
- name: Remove preview deployment
159+
env:
160+
HARPER_PREVIEW_TARGET: ${{ secrets.HARPER_PREVIEW_TARGET }}
161+
HARPER_PREVIEW_USERNAME: ${{ secrets.HARPER_PREVIEW_USERNAME }}
162+
HARPER_PREVIEW_PASSWORD: ${{ secrets.HARPER_PREVIEW_PASSWORD }}
152163
run: |
153164
# 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
165+
npx harper drop-component \
166+
target=${HARPER_PREVIEW_TARGET}:9925 \
167+
username=$HARPER_PREVIEW_USERNAME \
168+
password=$HARPER_PREVIEW_PASSWORD \
169+
project=pr-${{ github.event.pull_request.number }} \
170+
replicated=true \
171+
restart=true
155172
echo "Cleaning up preview for PR #${{ github.event.pull_request.number }}"
156173
157174
- name: Update deployment status

scripts/preview-pr.mjs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async function main() {
9898
// Get the workflow run for this PR (using sanitized branch name)
9999
const runs = JSON.parse(
100100
execSync(
101-
`gh api repos/HarperDB/documentation/actions/runs --paginate -X GET -f branch=${sanitizedBranch} --jq '.workflow_runs | map(select(.conclusion == "success" and .name == "Deploy Docusaurus to GitHub Pages")) | sort_by(.created_at) | reverse | .[0]'`,
101+
`gh api repos/HarperDB/documentation/actions/runs --paginate -X GET -f branch=${sanitizedBranch} --jq '.workflow_runs | map(select(.conclusion == "success" and .name == "Deploy PR Preview")) | sort_by(.created_at) | reverse | .[0]'`,
102102
{ encoding: 'utf-8' }
103103
)
104104
);
@@ -126,10 +126,11 @@ async function main() {
126126
})
127127
);
128128

129-
const artifact = artifacts.find((a) => a.name === 'github-pages');
129+
const artifactName = `pr-${PR_NUMBER}-build`;
130+
const artifact = artifacts.find((a) => a.name === artifactName);
130131

131132
if (!artifact) {
132-
console.error(`❌ No 'github-pages' artifact found for this PR`);
133+
console.error(`❌ No '${artifactName}' artifact found for this PR`);
133134
process.exit(1);
134135
}
135136

@@ -170,28 +171,19 @@ async function main() {
170171
throw new Error('Downloaded artifact file not found');
171172
}
172173

173-
// Extract the artifact (it's a tar.gz inside a zip)
174+
// Extract the artifact (it's a direct zip of the build directory)
174175
console.log('📂 Extracting artifact...');
175-
execSync(`unzip -q "${artifactZip}" -d "${PR_DIR}"`, { stdio: 'inherit' });
176-
177-
// The github-pages artifact contains a tar.gz file
178-
const tarFile = join(PR_DIR, 'artifact.tar');
179-
if (existsSync(tarFile)) {
180-
mkdirSync(BUILD_DIR, { recursive: true });
181-
execSync(`tar -xzf "${tarFile}" -C "${BUILD_DIR}"`, { stdio: 'inherit' });
182-
} else {
183-
throw new Error('Expected artifact.tar not found in artifact');
184-
}
176+
mkdirSync(BUILD_DIR, { recursive: true });
177+
execSync(`unzip -q "${artifactZip}" -d "${BUILD_DIR}"`, { stdio: 'inherit' });
185178

186179
// Verify extracted files are within expected directory
187180
const resolvedBuildDir = join(BUILD_DIR);
188181
if (!resolvedBuildDir.startsWith(PREVIEW_DIR)) {
189182
throw new Error('Security violation: extracted files outside preview directory');
190183
}
191184

192-
// Clean up compressed files
185+
// Clean up zip file
193186
rmSync(artifactZip, { force: true });
194-
rmSync(tarFile, { force: true });
195187

196188
console.log('\n✅ Preview ready!\n');
197189
console.log(`📁 Build location: ${BUILD_DIR}`);

0 commit comments

Comments
 (0)