Skip to content

Commit d072912

Browse files
committed
ci: streamline workflows
1 parent 6ab12c4 commit d072912

8 files changed

Lines changed: 276 additions & 184 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "Setup and Build"
2+
description: "Setup Node.js, install dependencies, and optionally build"
3+
inputs:
4+
node-version:
5+
description: "Node.js version"
6+
required: false
7+
default: "22"
8+
build:
9+
description: "Run build step"
10+
required: false
11+
default: "true"
12+
setup:
13+
description: "Setup Node.js and install dependencies"
14+
required: false
15+
default: "true"
16+
# Build environment variables
17+
build-analytics-id:
18+
description: "Analytics tracking ID"
19+
required: false
20+
default: ""
21+
build-base-url:
22+
description: "Base URL for build"
23+
required: false
24+
default: ""
25+
26+
runs:
27+
using: "composite"
28+
steps:
29+
- name: Setup Node.js
30+
if: inputs.setup == 'true'
31+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
32+
with:
33+
node-version: ${{ inputs.node-version }}
34+
registry-url: "https://registry.npmjs.org"
35+
cache: "npm"
36+
37+
- name: Install dependencies
38+
if: inputs.setup == 'true'
39+
shell: bash
40+
run: npm ci
41+
42+
- name: Build website
43+
if: inputs.build == 'true'
44+
shell: bash
45+
env:
46+
HUBSPOT_TRACKING_ID: ${{ inputs.build-analytics-id }}
47+
BASE_URL: ${{ inputs.build-base-url }}
48+
run: npm run build

.github/workflows/checks.yaml

Lines changed: 0 additions & 70 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
11
name: Deploy to GitHub Pages
22

33
on:
4-
# Nightly @ 5AM UTC
5-
schedule:
6-
- cron: '0 5 * * *'
7-
# When triggered manually
84
workflow_dispatch:
9-
# When a commit is pushed to the main branch
105
push:
116
branches:
127
- main
138

9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: 'pages'
16+
cancel-in-progress: false
17+
1418
jobs:
15-
deploy:
16-
name: Deploy to GitHub Pages
17-
permissions:
18-
contents: write
19+
build:
20+
name: Build
1921
runs-on: ubuntu-latest
2022
steps:
21-
- name: Cached LFS checkout
22-
uses: nschloe/action-cached-lfs-checkout@f46300cd8952454b9f0a21a3d133d4bd5684cfc2
23+
- name: Checkout repository
24+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
25+
with:
26+
lfs: true
27+
fetch-depth: 1
2328

24-
- name: Set up node
25-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
29+
- name: Setup and build
30+
uses: ./.github/actions/setup-and-build
2631
with:
27-
node-version: '22'
28-
registry-url: 'https://registry.npmjs.org'
29-
cache: 'npm'
32+
build-analytics-id: ${{ secrets.HUBSPOT_TRACKING_ID }}
3033

31-
- name: Install dependencies
32-
run: npm ci
34+
- name: Create CNAME file
35+
run: echo "openfga.dev" > ./build/CNAME
3336

34-
- name: Build website
35-
run: npm run build
36-
env:
37-
HUBSPOT_TRACKING_ID: ${{ secrets.HUBSPOT_TRACKING_ID }}
37+
- name: Setup Pages
38+
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
3839

39-
# Popular action to deploy to GitHub Pages:
40-
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
41-
- name: Deploy to GitHub Pages
42-
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e
40+
- name: Upload artifact
41+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
4342
with:
44-
github_token: ${{ secrets.GITHUB_TOKEN }}
45-
# Build output to publish to the `gh-pages` branch:
46-
publish_dir: ./build
47-
cname: openfga.dev
48-
# The following lines assign commit authorship to the official
49-
# GH-Actions bot for deploys to `gh-pages` branch:
50-
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
51-
# The GH actions bot is used by default if you didn't specify the two fields.
52-
# You can swap them out with your own user credentials.
53-
user_name: github-actions[bot]
54-
user_email: 41898282+github-actions[bot]@users.noreply.github.com
43+
path: ./build
44+
45+
deploy:
46+
name: Deploy to GitHub Pages
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
50+
runs-on: ubuntu-latest
51+
needs: build
52+
steps:
53+
- name: Deploy to GitHub Pages
54+
id: deployment
55+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

.github/workflows/pr.yml

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
- closed
12+
- ready_for_review
13+
14+
permissions:
15+
contents: read
16+
17+
# Prevent concurrent builds for the same PR
18+
concurrency:
19+
group: pr-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
# Run code quality checks
24+
code-checks:
25+
name: Code Quality (${{ matrix.check }})
26+
runs-on: ubuntu-latest
27+
if: github.event.action != 'closed' && github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
include:
32+
- check: format
33+
command: npm run format:check
34+
- check: lint
35+
command: npm run lint
36+
- check: types
37+
command: npm run typecheck
38+
- check: audit
39+
command: npm audit
40+
continue-on-error: true
41+
- check: circular-deps
42+
command: npx madge --circular . --extensions ts,js,jsx,tsx
43+
permissions:
44+
contents: read
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
48+
with:
49+
lfs: false
50+
fetch-depth: 2
51+
52+
- name: Setup dependencies
53+
uses: ./.github/actions/setup-and-build
54+
with:
55+
build: 'false'
56+
57+
- name: Run ${{ matrix.check }}
58+
run: ${{ matrix.command }}
59+
continue-on-error: ${{ matrix.continue-on-error || false }}
60+
61+
# Check markdown links
62+
markdown-link-check:
63+
name: Check Documentation Links (${{ matrix.extension }})
64+
runs-on: ubuntu-latest
65+
if: github.event.action != 'closed' && github.actor != 'dependabot[bot]' && github.event.pull_request.draft == false
66+
strategy:
67+
fail-fast: true
68+
matrix:
69+
extension: ['.md', '.mdx']
70+
permissions:
71+
contents: read
72+
steps:
73+
- name: Checkout repository
74+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
75+
with:
76+
fetch-depth: 1
77+
lfs: false
78+
79+
- name: Check Markdown links (${{ matrix.extension }})
80+
uses: tcort/github-action-markdown-link-check@a800ad5f1c35bf61987946fd31c15726a1c9f2ba # v1.1.0
81+
continue-on-error: true
82+
with:
83+
file-extension: ${{ matrix.extension }}
84+
use-quiet-mode: 'yes'
85+
config-file: '.github/workflows/markdown.links.config.json'
86+
87+
# Build and test deployment
88+
build-test:
89+
name: Build and Test
90+
if: |
91+
github.event.action != 'closed' &&
92+
github.event.pull_request.draft == false &&
93+
(needs.code-checks.result == 'success' || needs.code-checks.result == 'skipped' || github.actor == 'dependabot[bot]')
94+
needs: [code-checks] # Only build after checks pass (or are skipped for Dependabot)
95+
runs-on: ubuntu-latest
96+
permissions:
97+
contents: read
98+
steps:
99+
- name: Checkout repository
100+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
101+
with:
102+
lfs: true
103+
fetch-depth: 2
104+
105+
- name: Setup and build
106+
uses: ./.github/actions/setup-and-build
107+
with:
108+
build-base-url: ${{ github.actor != 'dependabot[bot]' && format('/pr-preview/pr-{0}', github.event.number) || '' }}
109+
110+
- name: Upload build artifacts
111+
if: github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository
112+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
113+
with:
114+
name: build-artifacts
115+
path: ./build/
116+
retention-days: 1
117+
compression-level: 9
118+
119+
# Deploy preview only for non-Dependabot PRs from the main repo (not forks)
120+
deploy-preview:
121+
name: Deploy Preview
122+
needs: build-test
123+
runs-on: ubuntu-latest
124+
if: |
125+
github.event.action != 'closed' &&
126+
github.actor != 'dependabot[bot]' &&
127+
github.event.pull_request.draft == false &&
128+
github.event.pull_request.head.repo.full_name == github.repository
129+
permissions:
130+
contents: write # Required for pr-preview-action to push to gh-pages
131+
pull-requests: write # Required for PR comments
132+
steps:
133+
- name: Checkout repository
134+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
135+
with:
136+
fetch-depth: 0
137+
lfs: false
138+
139+
- name: Download build artifacts
140+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
141+
with:
142+
name: build-artifacts
143+
path: ./build/
144+
145+
- name: Deploy preview
146+
uses: rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1.6.2
147+
id: preview-step
148+
with:
149+
source-dir: ./build/
150+
preview-branch: gh-pages
151+
umbrella-dir: pr-preview
152+
action: deploy
153+
154+
- name: Publish preview link
155+
if: steps['preview-step'].outputs['deployment-action'] == 'deploy'
156+
run: |
157+
url="${{ steps['preview-step'].outputs['preview-url'] }}"
158+
echo "Preview visible at ${url}" >> "$GITHUB_STEP_SUMMARY"
159+
echo "[Open preview](${url})" >> "$GITHUB_STEP_SUMMARY"
160+
161+
# Clean up preview on PR close (only for PRs from the main repo)
162+
cleanup-preview:
163+
name: Cleanup Preview
164+
runs-on: ubuntu-latest
165+
if: |
166+
github.event.action == 'closed' &&
167+
github.actor != 'dependabot[bot]' &&
168+
github.event.pull_request.draft == false &&
169+
github.event.pull_request.head.repo.full_name == github.repository
170+
permissions:
171+
contents: write
172+
steps:
173+
- name: Checkout repository
174+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
175+
with:
176+
fetch-depth: 1
177+
lfs: false
178+
179+
- name: Remove preview
180+
uses: rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1.6.2
181+
with:
182+
preview-branch: gh-pages
183+
umbrella-dir: pr-preview
184+
action: remove

0 commit comments

Comments
 (0)