|
| 1 | +name: SSR deploy |
| 2 | +on: [push, pull_request] |
| 3 | +jobs: |
| 4 | + deploy: |
| 5 | + if: github.event_name == 'push' |
| 6 | + runs-on: ubuntu-latest |
| 7 | + env: |
| 8 | + TARGET: ${{ format('/home/{0}/superhero-ui', secrets.SSR_STAGE_USER) }} |
| 9 | + steps: |
| 10 | + - uses: actions/checkout@v2 |
| 11 | + - uses: actions/setup-node@v2 |
| 12 | + with: |
| 13 | + node-version: 14.x |
| 14 | + - uses: actions/cache@v2 |
| 15 | + with: |
| 16 | + path: ~/.npm |
| 17 | + key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} |
| 18 | + - run: npm ci |
| 19 | + - run: npm run ssr:build |
| 20 | + |
| 21 | + - name: Deploy to stage |
| 22 | + uses: easingthemes/ssh-deploy@v2.1.5 |
| 23 | + env: |
| 24 | + SSH_PRIVATE_KEY: ${{ secrets.SSR_STAGE_PRIVATE_KEY }} |
| 25 | + REMOTE_HOST: ${{ secrets.SSR_STAGE_HOST }} |
| 26 | + REMOTE_USER: ${{ secrets.SSR_STAGE_USER }} |
| 27 | + SOURCE: . |
| 28 | + TARGET: ${{ env.TARGET }} |
| 29 | + EXCLUDE: '/.git/, /node_modules/' |
| 30 | + |
| 31 | + - name: Execute SSH commmands on remote server |
| 32 | + uses: JimCronqvist/action-ssh@master |
| 33 | + env: |
| 34 | + NODE_ENV: production |
| 35 | + HOME: /home/${{ secrets.SSR_STAGE_USER }} |
| 36 | + NVM_DIR: /home/${{ secrets.SSR_STAGE_USER }}/.nvm |
| 37 | + TARGET: ${{ env.TARGET }} |
| 38 | + with: |
| 39 | + hosts: '${{ secrets.SSR_STAGE_USER }}@${{ secrets.SSR_STAGE_HOST }}' |
| 40 | + privateKey: ${{ secrets.SSR_STAGE_PRIVATE_KEY }} |
| 41 | + debug: true |
| 42 | + command: | |
| 43 | + source ${{ env.NVM_DIR }}/nvm.sh || exit 1 |
| 44 | + cd ${{ env.TARGET }} || exit 1 |
| 45 | + nvm install 14 --latest-npm --no-progress --default || exit 1 |
| 46 | + npm ci || exit 1 |
| 47 | + killall node |
| 48 | + setsid nohup npm run ssr:start </dev/null &2>log.log & |
| 49 | + disown |
| 50 | +
|
| 51 | + comment: |
| 52 | + if: github.event_name == 'pull_request' |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - uses: unsplash/comment-on-pr@85a56be792d927ac4bfa2f4326607d38e80e6e60 |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + HOST: ${{ secrets.SSR_STAGE_HOST }} |
| 59 | + with: |
| 60 | + msg: SSR will be deployed to [${{ env.HOST }}](https://${{ env.HOST }}), [bundle report](https://${{ env.HOST }}/report.html) |
| 61 | + check_for_duplicate_msg: true |
0 commit comments