generated from vanHeemstraSystems/template-default-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (123 loc) · 4.69 KB
/
deploy.yml
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
name: Deploy
on:
push:
branches:
- main
workflow_dispatch: # Allows manual triggering
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
# Clean up existing workspace
- run: |
echo "Cleaning up workspace..."
rm -rf hatch-project
rm -rf apps
rm -f nx.json
rm -f package.json
rm -f package-lock.json
# Create temporary directory for the new workspace
- run: |
echo "Creating temporary directory..."
mkdir -p /tmp/nx-workspace
cd /tmp/nx-workspace
echo "Creating new Nx workspace..."
npx create-nx-workspace@latest . \
--preset=react-monorepo \
--appName=hatch_project \
--style=css \
--nxCloud=skip \
--packageManager=npm \
--no-interactive \
--defaultBase=main
echo "Workspace contents:"
ls -la
echo "Copying workspace files back..."
cd $GITHUB_WORKSPACE
cp -r /tmp/nx-workspace/* .
cp -r /tmp/nx-workspace/.* . 2>/dev/null || true
# Configure base URL for GitHub Pages
- run: |
echo "Configuring base URL..."
REPO_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2)
echo "Base URL will be: /$REPO_NAME/"
# Update vite.config.ts
cat > apps/hatch_project/vite.config.ts << EOF
/// <reference types='vitest' />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
export default defineConfig({
root: __dirname,
base: '/$REPO_NAME/',
cacheDir: '../../node_modules/.vite/hatch_project',
plugins: [react(), nxViteTsPaths()],
build: {
outDir: '../../dist/apps/hatch_project',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: { transformMixedEsModules: true },
},
test: {
globals: true,
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
});
EOF
# Build for production
- run: |
echo "Running build command..."
npx nx build hatch_project --configuration=production --verbose
# Update HTML file with correct base URL
- run: |
echo "Updating base URL in index.html..."
REPO_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2)
# Use sed to update the base href and asset paths
sed -i "s|<base href=\"/\"|<base href=\"/$REPO_NAME/\"|g" dist/apps/hatch_project/index.html
sed -i "s|src=\"/assets|src=\"/$REPO_NAME/assets|g" dist/apps/hatch_project/index.html
sed -i "s|href=\"/assets|href=\"/$REPO_NAME/assets|g" dist/apps/hatch_project/index.html
sed -i "s|href=\"/favicon.ico|href=\"/$REPO_NAME/favicon.ico|g" dist/apps/hatch_project/index.html
echo "Updated index.html contents:"
cat dist/apps/hatch_project/index.html
# Debug: Show build output
- run: |
echo "Build output structure:"
ls -R dist/ || true
echo "Looking for build files:"
find . -type f \( \
-name "*.js" -o \
-name "*.html" -o \
-name "*.css" -o \
-name "*.json" -o \
-name "*.ico" -o \
-name "*.png" -o \
-name "*.svg" \
\) -not -path "./node_modules/*" -not -path "./.git/*" -not -path "./dist/*"
echo "Contents of apps/hatch_project:"
ls -la apps/hatch_project/
echo "Contents of dist directory (if exists):"
ls -la dist/ || true
# Verify build output
- run: |
echo "Verifying build output..."
if [ ! -f "dist/apps/hatch_project/index.html" ]; then
echo "Error: index.html not found in build output!"
exit 1
fi
# Deploy to GitHub Pages
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist/apps/hatch_project
enable_jekyll: false
keep_files: false
force_orphan: true