Skip to content

Commit 6c20cdb

Browse files
committed
chore: implement ai suggestions
1 parent 028e616 commit 6c20cdb

3 files changed

Lines changed: 53 additions & 31 deletions

File tree

.github/actions/setup-and-build/action.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "Setup and Build"
22
description: "Setup Node.js, install dependencies, and optionally build"
33
inputs:
44
node-version:
5-
description: "Node.js version"
5+
description: "Node.js version (can use env.DEFAULT_NODE_VERSION or repository variable)"
66
required: false
77
default: "22"
88
build:
@@ -22,28 +22,27 @@ inputs:
2222
required: false
2323
default: ""
2424
npm-ci-flags:
25-
description: "Additional flags for npm ci (e.g. --ignore-scripts --no-audit --no-fund)"
25+
description: "Flags for npm ci (default: --no-audit --no-fund --prefer-offline). Add --ignore-scripts if needed to skip postinstall scripts"
2626
required: false
27-
default: ""
27+
default: "--no-audit --no-fund --prefer-offline"
2828

2929
runs:
3030
using: "composite"
3131
steps:
3232
- name: Setup Node.js
33-
if: inputs.setup == 'true'
33+
if: ${{ inputs.setup == 'true' }}
3434
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
3535
with:
3636
node-version: ${{ inputs.node-version }}
37-
registry-url: "https://registry.npmjs.org"
3837
cache: "npm"
3938

4039
- name: Install dependencies
41-
if: inputs.setup == 'true'
40+
if: ${{ inputs.setup == 'true' }}
4241
shell: bash
4342
run: npm ci ${{ inputs.npm-ci-flags }}
4443

4544
- name: Build website
46-
if: inputs.build == 'true'
45+
if: ${{ inputs.build == 'true' }}
4746
shell: bash
4847
env:
4948
HUBSPOT_TRACKING_ID: ${{ inputs.build-analytics-id }}

.github/workflows/deploy.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Checkout repository
2424
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2525
with:
26-
lfs: true
26+
lfs: true # LFS required for building with images/assets
2727
fetch-depth: 1
2828

2929
- name: Setup and build
@@ -34,6 +34,30 @@ jobs:
3434
- name: Create CNAME file
3535
run: echo "openfga.dev" > ./build/CNAME
3636

37+
- name: Preserve PR previews from gh-pages
38+
timeout-minutes: 5
39+
run: |
40+
# Clone the gh-pages branch with authentication to avoid rate limits and support private repos
41+
if git clone --branch gh-pages --single-branch --depth 1 \
42+
https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git gh-pages-temp 2>/dev/null; then
43+
44+
# Copy pr-preview directory if it exists
45+
if [ -d "gh-pages-temp/pr-preview" ]; then
46+
echo "Preserving PR previews..."
47+
cp -r gh-pages-temp/pr-preview ./build/
48+
# Count actual PR preview directories (excluding parent)
49+
preview_count=$(find ./build/pr-preview -mindepth 1 -maxdepth 1 -type d 2>/dev/null | wc -l)
50+
echo "Preserved ${preview_count} PR preview(s)"
51+
else
52+
echo "No PR previews to preserve"
53+
fi
54+
55+
# Clean up temp directory
56+
rm -rf gh-pages-temp
57+
else
58+
echo "No gh-pages branch found or unable to clone - this is normal for first deployment"
59+
fi
60+
3761
- name: Setup Pages
3862
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
3963

.github/workflows/pr.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Checkout repository
5050
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
5151
with:
52-
lfs: false
52+
lfs: false # LFS not needed for code checks
5353
fetch-depth: 2
5454

5555
- name: Setup dependencies
@@ -58,6 +58,7 @@ jobs:
5858
build: 'false'
5959

6060
- name: Run ${{ matrix.check }}
61+
timeout-minutes: 5
6162
run: ${{ matrix.command }}
6263
continue-on-error: ${{ matrix.continue-on-error || false }}
6364

@@ -77,7 +78,7 @@ jobs:
7778
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
7879
with:
7980
fetch-depth: 1
80-
lfs: false
81+
lfs: false # LFS not needed for markdown link checks
8182

8283
- name: Check Markdown links (${{ matrix.extension }})
8384
uses: tcort/github-action-markdown-link-check@a800ad5f1c35bf61987946fd31c15726a1c9f2ba # v1.1.0
@@ -104,20 +105,16 @@ jobs:
104105
- name: Checkout repository
105106
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
106107
with:
107-
lfs: true
108+
lfs: true # LFS required for building with images/assets
108109
fetch-depth: 2
109110

110111
- name: Set base URL for build
111112
id: set-base-url
112113
run: |
113114
# Set base URL for PR preview builds (excluding Dependabot)
114115
if [ "${{ github.actor }}" != "dependabot[bot]" ]; then
115-
# Validate PR number is numeric
116+
# PR number is validated by GitHub and guaranteed to be numeric
116117
pr_number="${{ github.event.pull_request.number }}"
117-
if ! [[ "$pr_number" =~ ^[0-9]+$ ]]; then
118-
echo "Error: Invalid PR number: $pr_number"
119-
exit 1
120-
fi
121118
echo "build_base_url=/pr-preview/pr-${pr_number}/" >> $GITHUB_OUTPUT
122119
echo "Building with PR preview URL: /pr-preview/pr-${pr_number}/"
123120
else
@@ -136,7 +133,7 @@ jobs:
136133
with:
137134
name: build-artifacts
138135
path: ./build/
139-
retention-days: 1
136+
retention-days: 7 # Increased from 1 day for debugging purposes
140137
compression-level: 9
141138

142139
# Deploy preview only for non-Dependabot PRs from the main repo (not forks)
@@ -158,7 +155,7 @@ jobs:
158155
with:
159156
ref: gh-pages
160157
fetch-depth: 1
161-
lfs: false
158+
lfs: false # LFS not needed for gh-pages management
162159

163160
- name: Download build artifacts
164161
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
@@ -167,20 +164,21 @@ jobs:
167164
path: ./build/
168165

169166
- name: Deploy preview to gh-pages
167+
timeout-minutes: 5
170168
run: |
169+
# Validate PR number is numeric
170+
if [[ ! "${{ github.event.pull_request.number }}" =~ ^[0-9]+$ ]]; then
171+
echo "Error: Invalid PR number: ${{ github.event.pull_request.number }}"
172+
exit 1
173+
fi
174+
171175
# Configure git
172176
git config user.name "github-actions[bot]"
173177
git config user.email "github-actions[bot]@users.noreply.github.com"
174178
175179
# Setup preview directory
176180
preview_dir="pr-preview/pr-${{ github.event.pull_request.number }}"
177181
178-
# Validate PR number and directory path
179-
if ! [[ "${{ github.event.pull_request.number }}" =~ ^[0-9]+$ ]]; then
180-
echo "Error: Invalid PR number: ${{ github.event.pull_request.number }}"
181-
exit 1
182-
fi
183-
184182
# Ensure preview directory is within pr-preview folder
185183
if [[ "${preview_dir}" != pr-preview/pr-* ]]; then
186184
echo "Error: Invalid preview directory path: ${preview_dir}"
@@ -304,23 +302,24 @@ jobs:
304302
with:
305303
ref: gh-pages
306304
fetch-depth: 1
307-
lfs: false
305+
lfs: false # LFS not needed for gh-pages management
308306

309307
- name: Remove preview directory
308+
timeout-minutes: 5
310309
run: |
310+
# Validate PR number is numeric
311+
if [[ ! "${{ github.event.pull_request.number }}" =~ ^[0-9]+$ ]]; then
312+
echo "Error: Invalid PR number: ${{ github.event.pull_request.number }}"
313+
exit 1
314+
fi
315+
311316
# Configure git
312317
git config user.name "github-actions[bot]"
313318
git config user.email "github-actions[bot]@users.noreply.github.com"
314319
315320
# Remove preview directory
316321
preview_dir="pr-preview/pr-${{ github.event.pull_request.number }}"
317322
318-
# Validate PR number and directory path before removal
319-
if ! [[ "${{ github.event.pull_request.number }}" =~ ^[0-9]+$ ]]; then
320-
echo "Error: Invalid PR number: ${{ github.event.pull_request.number }}"
321-
exit 1
322-
fi
323-
324323
# Ensure we're only removing from pr-preview folder
325324
if [[ "${preview_dir}" != pr-preview/pr-* ]]; then
326325
echo "Error: Invalid preview directory path: ${preview_dir}"

0 commit comments

Comments
 (0)