-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
916dfe7
commit 4f5d58b
Showing
1 changed file
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |