From 464f0ecf999c7b6a4d9fcf6e8eaf35d25e913295 Mon Sep 17 00:00:00 2001 From: Ze0ro99 <146000493+Ze0ro99@users.noreply.github.com> Date: Thu, 8 May 2025 18:06:21 +0300 Subject: [PATCH] Update deploy.yml Signed-off-by: Ze0ro99 <146000493+Ze0ro99@users.noreply.github.com> --- .github/workflows/deploy.yml | 97 +++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d2ec231..d6e7ebd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,34 +4,97 @@ on: push: branches: - main + - "feature/*" + - "fix/*" pull_request: branches: - main + - "feature/*" + - "fix/*" permissions: - contents: read + contents: write jobs: deploy: runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + always-auth: false + check-latest: false + + - name: Ensure package-lock.json exists + run: | + if [ ! -f package-lock.json ]; then + npm install --package-lock-only + fi + + - name: Install dependencies + run: npm install + + - name: Ensure Speed Insights is installed + run: | + if ! npm list @vercel/speed-insights > /dev/null 2>&1; then + npm install @vercel/speed-insights + fi + + - name: Update package.json with dependencies and scripts + run: | + npm pkg set dependencies.next="^14.2.0" + npm pkg set dependencies.react="^18.2.0" + npm pkg set dependencies.react-dom="^18.2.0" + npm pkg set dependencies.@vercel/speed-insights="^1.0.0" + npm pkg set scripts.build="next build" + npm pkg set scripts.start="next start" + npm pkg set scripts.dev="next dev" + npm install + + - name: Create Next.js layout file if missing + run: | + if [ ! -f app/layout.js ]; then + mkdir -p app + echo "import { SpeedInsights } from \"@vercel/speed-insights/next\"; export default function RootLayout({ children }) { return ({children}); }" > app/layout.js + fi + + - name: Create Next.js page file if missing + run: | + if [ ! -f app/page.js ]; then + echo "export default function Home() { return

Welcome to PiMetaConnect

; }" > app/page.js + fi + + - name: Create next.config.js if missing + run: | + if [ ! -f next.config.js ]; then + echo "module.exports = { reactStrictMode: true, }" > next.config.js + fi - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '18' - cache: 'npm' + - name: Create or update vercel.json + run: | + if [ ! -f vercel.json ]; then + echo "{\"version\": 2, \"public\": true, \"builds\": [{\"src\": \"public/**/*\", \"use\": \"@vercel/static\"}, {\"src\": \"api/**/*.js\", \"use\": \"@vercel/node\"}, {\"src\": \"next.config.js\", \"use\": \"@vercel/next\"}], \"routes\": [{\"src\": \"/privacy\", \"dest\": \"/public/privacy.html\"}, {\"src\": \"/terms\", \"dest\": \"/public/terms.html\"}, {\"src\": \"/api/(.*)\", \"dest\": \"/api/$1\"}, {\"src\": \"/(.*)\", \"dest\": \"/\"}]}" > vercel.json + fi - - name: Install dependencies - run: npm install + - name: Commit changes if any + run: | + git config user.name "GitHub Action" + git config user.email "action@github.com" + git add . + git diff --staged --quiet || git commit -m "Auto-update files and dependencies" + git push origin git@github.com:Ze0ro99/PiMetaConnect.git - - name: Build project - run: npm run build + - name: Build project + run: npm run build - - name: Deploy to Vercel - env: - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - run: npx vercel --prod --token $VERCEL_TOKEN + - name: Deploy to Vercel + env: + VERCEL_TOKEN: ${{ .github/workflows/deploy.yml }} + run: npx vercel --prod --token deploy.yml