|
1 | | -# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node |
2 | | -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs |
3 | | - |
4 | | -name: Node.js CI |
| 1 | +# This workflow will do a clean installation of node dependencies, build the app dist, transfer the dist files to the remote server and clear the cache on the server |
| 2 | +name: Production deploy CI |
5 | 3 |
|
6 | 4 | on: |
7 | 5 | push: |
8 | | - branches: [ "main" ] |
9 | | - pull_request: |
10 | | - branches: [ "main" ] |
| 6 | + branches: ['main'] |
11 | 7 |
|
12 | 8 | jobs: |
13 | 9 | build: |
14 | | - |
15 | 10 | runs-on: ubuntu-latest |
16 | 11 |
|
17 | 12 | strategy: |
18 | 13 | matrix: |
19 | | - node-version: [18.x, 20.x, 22.x] |
20 | | - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ |
| 14 | + node-version: [20.x, 22.x] |
21 | 15 |
|
22 | 16 | steps: |
23 | | - - uses: actions/checkout@v4 |
24 | | - - name: Use Node.js ${{ matrix.node-version }} |
25 | | - uses: actions/setup-node@v4 |
26 | | - with: |
27 | | - node-version: ${{ matrix.node-version }} |
28 | | - cache: 'npm' |
29 | | - - run: npm ci |
30 | | - - run: npm run build --if-present |
31 | | - - run: npm test |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - name: Use Node.js ${{ matrix.node-version }} |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: ${{ matrix.node-version }} |
| 22 | + cache: 'npm' |
| 23 | + |
| 24 | + # Node dependencies clean install |
| 25 | + - name: Node dependencies clean install |
| 26 | + run: npm ci |
| 27 | + |
| 28 | + # Build app dist |
| 29 | + - name: Build app dist |
| 30 | + run: npm run build --if-present |
| 31 | + |
| 32 | + # Add SSH Key |
| 33 | + - name: Add SSH key |
| 34 | + env: |
| 35 | + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |
| 36 | + run: | |
| 37 | + mkdir -p ~/.ssh |
| 38 | + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa |
| 39 | + chmod 600 ~/.ssh/id_rsa |
| 40 | +
|
| 41 | + # Deploy dist files to hosting |
| 42 | + - name: Deploy to remove server |
| 43 | + run: scp -r -P ${{ secrets.SSH_PORT }} -o strictHostKeyChecking=no ./dist/* ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:www/domain-lookup.${{ vars.DOMAIN }}/public_html |
| 44 | + |
| 45 | + # Clear cache on the server |
| 46 | + - name: Clear cache on the server |
| 47 | + run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} -p ${{ secrets.SSH_PORT }} "site-tools-client domain update id=4 flush_cache=1" |
| 48 | + |
| 49 | + # Show link |
| 50 | + - name: Show link |
| 51 | + run: echo "Deployed! https://domain-lookup.${{ vars.DOMAIN }}" |
0 commit comments