fix(ci): include stamps in backend deploy + ensure uploads dir exists #3
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
| name: Deploy to Test Environment | |
| on: | |
| push: | |
| branches: [develop] | |
| workflow_dispatch: | |
| jobs: | |
| deploy-backend: | |
| name: Deploy Backend API | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: Postcards-Server | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: Postcards-Server/package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build TypeScript | |
| run: npm run build | |
| - name: Clean old build on server | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.TEST_HOST }} | |
| username: ${{ secrets.TEST_USERNAME }} | |
| key: ${{ secrets.DEPLOY_KEY }} | |
| script: | | |
| rm -rf /data/postcards/dist | |
| - name: Deploy to test server | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.TEST_HOST }} | |
| username: ${{ secrets.TEST_USERNAME }} | |
| key: ${{ secrets.DEPLOY_KEY }} | |
| source: "Postcards-Server/dist/,Postcards-Server/package.json,Postcards-Server/ecosystem.config.js,Postcards-Server/stamps/" | |
| target: "/data/postcards/" | |
| strip_components: 1 | |
| - name: Restart backend | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.TEST_HOST }} | |
| username: ${{ secrets.TEST_USERNAME }} | |
| key: ${{ secrets.DEPLOY_KEY }} | |
| script: | | |
| cd /data/postcards | |
| mkdir -p /data/postcards/uploads | |
| npm install --omit=dev | |
| pm2 reload postcards-api || pm2 start ecosystem.config.js | |
| pm2 save | |
| deploy-frontend: | |
| name: Deploy Frontend H5 | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: Postcards-UniApp | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: Postcards-UniApp/package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build H5 | |
| run: npm run build:h5 | |
| - name: Deploy to test server | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.TEST_HOST }} | |
| username: ${{ secrets.TEST_USERNAME }} | |
| key: ${{ secrets.DEPLOY_KEY }} | |
| source: "Postcards-UniApp/dist/build/h5/" | |
| target: "/data/postcards/h5" | |
| strip_components: 4 | |
| - name: Reload nginx | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.TEST_HOST }} | |
| username: ${{ secrets.TEST_USERNAME }} | |
| key: ${{ secrets.DEPLOY_KEY }} | |
| script: | | |
| nginx -t && systemctl reload nginx |