aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: 77c072b93e56ae042d4022ee8d66c88a753332a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '14.x'

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: "Cache JS modules"
        uses: actions/cache@v2
        id: yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: "Cache gems"
        uses: actions/cache@v2
        id: gem-cache
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-gems-

      - name: "Install Ruby and Javascript dependencies"
        env:
          RAILS_ENV: "test"
          NODE_ENV: "test"
        run: |
          bundle config set path 'vendor/bundle'
          bundle install --jobs 4 --retry 3
          yarn --force
          yarn run webpack-single-shot

      - name: "Build site"
        run: bundle exec jekyll build

      - name: "Run style checks"
        run: |
          bundle exec rubocop
          yarn run eslint

      - name: "Run tests"
        run: bundle exec rake

      - name: "Create tarball"
        run: tar czvf site.tar.gz _site

      - name: "Upload tarball"
        uses: appleboy/scp-action@master
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          port: ${{ secrets.PORT }}
          key: ${{ secrets.KEY }}
          passphrase: ${{ secrets.PASSPHRASE }}
          source: "site.tar.gz"
          target: "tmp"

      - name: "Update file system"
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          port: ${{ secrets.PORT }}
          key: ${{ secrets.KEY }}
          passphrase: ${{ secrets.PASSPHRASE }}
          script: |
            cd tmp
            tar xzvf site.tar.gz
            rm -rf ${{ secrets.DEST }}/*
            cp -r _site/* ${{ secrets.DEST }}/
            rm -r _site site.tar.gz