ci: linting added before building in the deploy job #5
This file contains hidden or 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
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install Node jobs | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22.17.0 | |
| - name: Install dependencies | |
| run: npm install --frozen-lockfile | |
| - name: Run linting | |
| run: npm run lint | |
| - name: Add the firebase service json | |
| run: | | |
| mkdir -p src/app/private | |
| echo '${{secrets.FIREBASE_SERVICE_JSON}}' > src/app/private/alyse-firebase.json | |
| - name: Build app | |
| run: npm run build | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install Node jobs | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22.17.0 | |
| - name: Install dependencies | |
| run: npm install --frozen-lockfile | |
| - name: Run linting | |
| run: npm run lint | |
| - name: Build app | |
| run: npm run build | |
| - name: Configure SSH | |
| env: | |
| SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts | |
| - name: deploy to EC2 | |
| env: | |
| EC2_HOST: ${{secrets.EC2_HOST}} | |
| EC2_USER: ${{secrets.EC2_USER}} | |
| run: | | |
| # Create deployment directory | |
| ssh $EC2_USER@$EC2_HOST "mkdir -p ~/app" | |
| # Copy files to EC2 instance | |
| rsync -avz \ | |
| --exclude='.git' \ | |
| --exclude='node_modules' \ | |
| --exclude='.github' \ | |
| . $EC2_USER@EC2_HOST:~/app/ | |
| # Install prod dependencies on EC2 | |
| ssh EC2_USER@EC2_HOST | |
| "source ~/.bashrc && | |
| cd ~/.app && | |
| eval \$(fnm env) && | |
| npm install --frozen-lockfile" | |
| # Stop existing pm2 | |
| ssh EC2_USER@EC2_HOST | |
| "source ~/.bashrc && | |
| cd ~/.app && | |
| eval \$(fnm env) && | |
| pm2 delete server || true" | |
| # Start app with pm2 | |
| ssh EC2_USER@EC2_HOST | |
| "source ~/.bashrc && | |
| cd ~/.app && | |
| eval \$(fnm env) && | |
| cd ~/app && | |
| pm2 start npm --name "server" -- run start" |