-
Notifications
You must be signed in to change notification settings - Fork 57
119 lines (102 loc) · 3.59 KB
/
Copy pathpr.yml
File metadata and controls
119 lines (102 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: PR Preview
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
pull_request_target:
types:
- opened
- reopened
- synchronize
- closed
concurrency:
group: pr-preview-${{ github.event.number }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
lint:
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
run: npm ci
- name: Run formatter autofix
run: npm run format
- name: Run linter
run: npm run lint -- --frail
- name: Check for lint changes
id: lint_changes
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Notify forked PRs
if: steps.lint_changes.outputs.has_changes == 'true' && github.repository != github.event.pull_request.head.repo.full_name
run: |
echo "::warning::Format fixes were generated but cannot be pushed automatically for pull requests from forks. Please run 'npm run format' locally and push the changes."
- name: Commit lint fixes
if: steps.lint_changes.outputs.has_changes == 'true' && github.repository == github.event.pull_request.head.repo.full_name
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: apply lint and format fixes"
- name: Push lint fixes
if: steps.lint_changes.outputs.has_changes == 'true' && github.repository == github.event.pull_request.head.repo.full_name
run: |
git push origin HEAD:${{ github.head_ref }} || echo "Unable to push lint fixes (likely due to branch permissions)."
deploy-preview:
if: ${{ github.event_name == 'pull_request_target' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v5
if: ${{ github.event.action != 'closed' }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v5
if: ${{ github.event.action != 'closed' }}
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install dependencies
if: ${{ github.event.action != 'closed' }}
run: npm ci
- name: Build documentation
if: ${{ github.event.action != 'closed' }}
run: npm run build
env:
BASE_URL: /docs/pr-preview/pr-${{ github.event.number }}/
GITHUB_BRANCH: ${{ github.event.pull_request.head.ref }}
- name: Ensure build directory exists for cleanup
if: ${{ github.event.action == 'closed' }}
run: mkdir -p build
- name: Deploy PR Preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./build/
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto