|
| 1 | +name: Build and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout Repository |
| 13 | + uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Setup Node.js |
| 16 | + uses: actions/setup-node@v3 |
| 17 | + with: |
| 18 | + node-version: '16' |
| 19 | + |
| 20 | + - name: Install Dependencies |
| 21 | + run: npm ci |
| 22 | + |
| 23 | + - name: Build Project |
| 24 | + run: npm run build |
| 25 | + |
| 26 | + - name: Upload Build Artifact |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: build-files |
| 30 | + path: | |
| 31 | + dist |
| 32 | + ecosystem.config.js |
| 33 | + package.json |
| 34 | + package-lock.json |
| 35 | +
|
| 36 | + deploy: |
| 37 | + needs: build |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Download Build Artifact |
| 41 | + uses: actions/download-artifact@v4 |
| 42 | + with: |
| 43 | + name: build-files |
| 44 | + path: build-files |
| 45 | + |
| 46 | + - name: List downloaded artifact |
| 47 | + run: ls -la build-files |
| 48 | + |
| 49 | + - name: Ensure target directory exists on Linode |
| 50 | + uses: appleboy/ssh-action@master |
| 51 | + with: |
| 52 | + host: ${{ secrets.LINODE_HOST }} |
| 53 | + username: ${{ secrets.LINODE_USER }} |
| 54 | + key: ${{ secrets.LINODE_SSH_KEY }} |
| 55 | + script: | |
| 56 | + mkdir -p /home/puppeteer-user/candycomp-location-correction |
| 57 | +
|
| 58 | + - name: Copy Build Files to Linode Server |
| 59 | + uses: appleboy/scp-action@master |
| 60 | + with: |
| 61 | + host: ${{ secrets.LINODE_HOST }} |
| 62 | + username: ${{ secrets.LINODE_USER }} |
| 63 | + key: ${{ secrets.LINODE_SSH_KEY }} |
| 64 | + source: 'build-files/.' |
| 65 | + target: '/home/puppeteer-user/candycomp-location-correction/' |
| 66 | + strip_components: 1 |
| 67 | + |
| 68 | + - name: Create .env file on Linode |
| 69 | + uses: appleboy/ssh-action@master |
| 70 | + with: |
| 71 | + host: ${{ secrets.LINODE_HOST }} |
| 72 | + username: ${{ secrets.LINODE_USER }} |
| 73 | + key: ${{ secrets.LINODE_SSH_KEY }} |
| 74 | + script: | |
| 75 | + cat <<'EOF' > /home/puppeteer-user/candycomp-location-correction/.env |
| 76 | + PORT=${{ secrets.PORT }} |
| 77 | + GMAPS_API_KEY=${{ secrets.GMAPS_API_KEY }} |
| 78 | + USPS_TOKEN_URL=${{ secrets.USPS_TOKEN_URL }} |
| 79 | + USPS_ADDRESS_URL=${{ secrets.USPS_ADDRESS_URL }} |
| 80 | + USPS_CONSUMER_KEY=${{ secrets.USPS_CONSUMER_KEY }} |
| 81 | + USPS_CONSUMER_SECRET=${{ secrets.USPS_CONSUMER_SECRET }} |
| 82 | + NODE_ENV=production |
| 83 | + EOF |
| 84 | +
|
| 85 | + - name: List deployment directory contents |
| 86 | + uses: appleboy/ssh-action@master |
| 87 | + with: |
| 88 | + host: ${{ secrets.LINODE_HOST }} |
| 89 | + username: ${{ secrets.LINODE_USER }} |
| 90 | + key: ${{ secrets.LINODE_SSH_KEY }} |
| 91 | + script: 'ls -la /home/puppeteer-user/candycomp-location-correction/' |
| 92 | + |
| 93 | + - name: Install Node Modules on Linode |
| 94 | + uses: appleboy/ssh-action@master |
| 95 | + with: |
| 96 | + host: ${{ secrets.LINODE_HOST }} |
| 97 | + username: ${{ secrets.LINODE_USER }} |
| 98 | + key: ${{ secrets.LINODE_SSH_KEY }} |
| 99 | + script: | |
| 100 | + cd /home/puppeteer-user/candycomp-location-correction |
| 101 | + npm ci |
| 102 | +
|
| 103 | + - name: Start or Reload and Save PM2 Process on Linode |
| 104 | + uses: appleboy/ssh-action@master |
| 105 | + with: |
| 106 | + host: ${{ secrets.LINODE_HOST }} |
| 107 | + username: ${{ secrets.LINODE_USER }} |
| 108 | + key: ${{ secrets.LINODE_SSH_KEY }} |
| 109 | + script: | |
| 110 | + cd /home/puppeteer-user/candycomp-location-correction |
| 111 | + pm2 startOrReload ecosystem.config.js |
| 112 | + pm2 save |
0 commit comments