aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/.github/workflows/test.yml
blob: f0590a08cad14f766bf8664232c8d1bf2c5232cc (plain) (blame)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: This even works?

on: [push, pull_request]

env:
  JEKYLL_PROJECT_AUTHOR: egor-tensin
  JEKYLL_PROJECT_NAME: egor-tensin.github.io

jobs:
  local_build:
    name: Local build
    runs-on: ubuntu-18.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          path: src
      - name: Checkout Jekyll project
        uses: actions/checkout@v2
        with:
          repository: ${{ env.JEKYLL_PROJECT_AUTHOR }}/${{ env.JEKYLL_PROJECT_NAME }}
          path: ${{ env.JEKYLL_PROJECT_NAME }}
      - name: Add ~/.local/bin to PATH
        run: echo "::add-path::$HOME/.local/bin"
      - name: chruby/ruby-install are not installed
        run: |
          test '' = "$( type -t chruby-exec )"
          test '' = "$( type -t ruby-install )"
      - name: Install Ruby
        run: |
          cd src
          make ruby-install
          make ruby-install/clean
          make ruby
          make chruby
          make chruby/clean
      - name: chruby/ruby-install were installed
        run: |
          test 'file' = "$( type -t chruby-exec )"
          test 'file' = "$( type -t ruby-install )"
      - name: Install dependencies
        run: |
          cd src
          make bundler
          make dependencies "PROJECT_DIR=../$JEKYLL_PROJECT_NAME"
      - name: _site doesn't exist
        run: |
          cd -- "$JEKYLL_PROJECT_NAME"
          test ! -e '_site'
      - name: Build Jekyll project
        run: |
          cd src
          make jekyll/build "PROJECT_DIR=../$JEKYLL_PROJECT_NAME"
      - name: _site exists
        run: |
          cd -- "$JEKYLL_PROJECT_NAME"
          test -d '_site'
          test -f '_site/index.html'
  docker_build:
    name: Docker build
    runs-on: ubuntu-18.04
    steps:
      - name: Running as regular user
        run: test "$( id -u )" != 0
      - name: Docker is accessible as regular user
        run: docker ps
      - name: Checkout
        uses: actions/checkout@v2
        with:
          path: src
      - name: Checkout Jekyll project
        uses: actions/checkout@v2
        with:
          repository: ${{ env.JEKYLL_PROJECT_AUTHOR }}/${{ env.JEKYLL_PROJECT_NAME }}
          path: ${{ env.JEKYLL_PROJECT_NAME }}
      - name: Build Docker images
        run: |
          cd src
          make docker/build "PROJECT_DIR=../$JEKYLL_PROJECT_NAME"
      - name: _site doesn't exist
        run: test ! -e "$JEKYLL_PROJECT_NAME/_site"
      - name: Start containers
        run: |
          cd src
          make docker/up "PROJECT_DIR=../$JEKYLL_PROJECT_NAME"
          sleep 3
          make docker/logs
      - name: Check container UID
        run: |
          pid="$( docker inspect -f '{{.State.Pid}}' jekyll_project_1 )"
          info="$( ps --no-headers -o uid:1,gid:1 -p "$pid" )"
          test "$( id -u ) $( id -g )" = "$info"
      - name: _site exists
        run: |
          test -d "$JEKYLL_PROJECT_NAME/_site"
          test -f "$JEKYLL_PROJECT_NAME/_site/index.html"
      - name: Check _site ownership
        run: |
          test "$( id -u ) $( id -g )" = "$( stat -c '%u %g' "$JEKYLL_PROJECT_NAME/_site" )"
          test "$( id -u ) $( id -g )" = "$( stat -c '%u %g' "$JEKYLL_PROJECT_NAME/_site/index.html" )"
      - name: Fetch index.html
        run: curl -sS -D - http://localhost:4000/index.html
      - name: _site/dummy.txt doesn't exist
        run: test ! -e "$JEKYLL_PROJECT_NAME/_site/dummy.txt"
      - name: create dummy.txt
        run: |
          echo 123 > "$JEKYLL_PROJECT_NAME/dummy.txt"
          sleep 3
      - name: _site/dummy.txt exists
        run: test -f "$JEKYLL_PROJECT_NAME/_site/dummy.txt"
      - name: Check _site/dummy.txt ownership
        run: test "$( id -u ) $( id -g )" = "$( stat -c '%u %g' "$JEKYLL_PROJECT_NAME/_site/dummy.txt" )"
      - name: Fetch dummy.txt
        run: curl -sS -D - http://localhost:4000/dummy.txt
      - name: Stop containers
        run: |
          cd src
          make docker/down
  docker_root_build:
    name: Docker build (as root)
    runs-on: ubuntu-18.04
    steps:
      - name: Running as regular user
        run: test "$( id -u )" != 0
      - name: sudo makes root
        run: test "$( sudo id -u )" = 0
      - name: Checkout
        uses: actions/checkout@v2
        with:
          path: src
      - name: Checkout Jekyll project
        uses: actions/checkout@v2
        with:
          repository: ${{ env.JEKYLL_PROJECT_AUTHOR }}/${{ env.JEKYLL_PROJECT_NAME }}
          path: ${{ env.JEKYLL_PROJECT_NAME }}
      - name: Jekyll project is owned by root
        run: sudo chown -R -- root:root "$JEKYLL_PROJECT_NAME"
      - name: Build Docker images
        run: |
          cd src
          sudo make docker/build "PROJECT_DIR=../$JEKYLL_PROJECT_NAME"
      - name: _site doesn't exist
        run: test ! -e "$JEKYLL_PROJECT_NAME/_site"
      - name: Start containers
        run: |
          cd src
          sudo make docker/up "PROJECT_DIR=../$JEKYLL_PROJECT_NAME"
          sleep 3
          sudo make docker/logs
      - name: Check container UID
        run: |
          pid="$( docker inspect -f '{{.State.Pid}}' jekyll_project_1 )"
          info="$( ps --no-headers -o uid:1,gid:1 -p "$pid" )"
          test '999 999' = "$info"
      - name: _site exists
        run: |
          test -d "$JEKYLL_PROJECT_NAME/_site"
          test -f "$JEKYLL_PROJECT_NAME/_site/index.html"
      - name: Check _site ownership
        run: |
          test '999 999' = "$( stat -c '%u %g' "$JEKYLL_PROJECT_NAME/_site" )"
          test '999 999' = "$( stat -c '%u %g' "$JEKYLL_PROJECT_NAME/_site/index.html" )"
      - name: Fetch index.html
        run: curl -sS -D - http://localhost:4000/index.html
      - name: _site/dummy.txt doesn't exist
        run: test ! -e "$JEKYLL_PROJECT_NAME/_site/dummy.txt"
      - name: create dummy.txt
        run: |
          echo 123 | sudo tee "$JEKYLL_PROJECT_NAME/dummy.txt"
          sleep 3
      - name: _site/dummy.txt exists
        run: test -f "$JEKYLL_PROJECT_NAME/_site/dummy.txt"
      - name: Check _site/dummy.txt ownership
        run: test '999 999' = "$( stat -c '%u %g' "$JEKYLL_PROJECT_NAME/_site/dummy.txt" )"
      - name: Fetch dummy.txt
        run: curl -sS -D - http://localhost:4000/dummy.txt
      - name: Stop containers
        run: |
          cd src
          sudo make docker/down