This repository was archived by the owner on Feb 3, 2026. It is now read-only.
forked from hack-rpi/HackRPI-Website-2024
-
Notifications
You must be signed in to change notification settings - Fork 10
183 lines (161 loc) · 6.31 KB
/
nextjs.yml
File metadata and controls
183 lines (161 loc) · 6.31 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Build NextJS Site
on:
push:
branches: ["main"]
paths-ignore:
- '**/*.md'
- 'docs/**'
pull_request:
branches: ["main", "develop"]
paths-ignore:
- '**/*.md'
- 'docs/**'
# Set minimal permissions (security best practice)
permissions: {}
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# Improved to cancel in-progress PR builds but preserve main builds
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
# Detect file changes to optimize what jobs run
changes:
runs-on: ubuntu-latest
# Grant permissions to create check runs (needed for action outputs)
permissions:
checks: read
contents: read
pull-requests: read
outputs:
code: ${{ steps.filter.outputs.code }}
styles: ${{ steps.filter.outputs.styles }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
code:
- '**/*.{js,jsx,ts,tsx}'
- 'package.json'
- 'package-lock.json'
- 'yarn.lock'
styles:
- '**/*.{css,scss}'
- 'tailwind.config.{js,ts}'
# Build job
build:
runs-on: ubuntu-latest
needs: [changes]
if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'pull_request' }}
timeout-minutes: 15
# Grant specific permissions needed for build job
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}
# Optimized caching strategy
- name: Cache node_modules
uses: actions/cache@v4
id: node-modules-cache
with:
path: node_modules
key: ${{ runner.os }}-${{ steps.detect-package-manager.outputs.manager }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-v2
- name: Restore Next.js build cache
uses: actions/cache@v4
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} --no-audit --force
- name: Add Amplify outputs file
run: touch amplify_outputs.json
- name: Populate Amplify outputs file
run: echo "{}" > amplify_outputs.json
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
env:
NODE_OPTIONS: --max-old-space-size=4096 --no-deprecation
# Test job
test:
runs-on: ubuntu-latest
needs: [changes]
if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'pull_request' }}
# Grant specific permissions needed for test job
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Cache node_modules
uses: actions/cache@v4
id: node-modules-cache
with:
path: node_modules
key: ${{ runner.os }}-${{ steps.detect-package-manager.outputs.manager }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-v2
- name: Install dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} --no-audit --force
- name: Add Amplify outputs file
run: touch amplify_outputs.json
- name: Populate Amplify outputs file
run: echo "{}" > amplify_outputs.json
- name: Run unit tests (excluding E2E tests)
run: ${{ steps.detect-package-manager.outputs.manager }} test -- --testPathIgnorePatterns="e2e"
- name: Display E2E test instructions
run: |
echo "========== E2E TESTS SHOULD BE RUN MANUALLY =========="
echo "As requested, E2E tests are excluded from CI and should be run manually by developers"
echo "To run E2E tests locally, use: npx playwright test"
echo "======================================================"