about summary refs log tree commit diff
path: root/.circleci/config.yml
blob: a9ad9214578e2923193382fb685738da5df8756e (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
181
182
183
184
185
186
187
188
189
version: 2.1

orbs:
  ruby: circleci/ruby@1.2.0
  node: circleci/node@4.7.0

executors:
  default:
    parameters:
      ruby-version:
        type: string
    docker:
      - image: cimg/ruby:<< parameters.ruby-version >>
        environment:
          BUNDLE_JOBS: 3
          BUNDLE_RETRY: 3
          CONTINUOUS_INTEGRATION: true
          DB_HOST: localhost
          DB_USER: root
          DISABLE_SIMPLECOV: true
          RAILS_ENV: test
      - image: cimg/postgres:14.0
        environment:
          POSTGRES_USER: root
          POSTGRES_HOST_AUTH_METHOD: trust
      - image: circleci/redis:6-alpine

commands:
  install-system-dependencies:
    steps:
      - run:
          name: Install system dependencies
          command: |
            sudo apt-get update
            sudo apt-get install -y libicu-dev libidn11-dev
  install-ruby-dependencies:
    parameters:
      ruby-version:
        type: string
    steps:
      - run:
          command: |
            bundle config clean 'true'
            bundle config frozen 'true'
            bundle config without 'development production'
          name: Set bundler settings
      - ruby/install-deps:
          bundler-version: '2.2.31'
          key: ruby<< parameters.ruby-version >>-gems-v1
  wait-db:
    steps:
      - run:
          command: dockerize -wait tcp://localhost:5432 -wait tcp://localhost:6379 -timeout 1m
          name: Wait for PostgreSQL and Redis

jobs:
  build:
    docker:
      - image: cimg/ruby:3.0-node
        environment:
          RAILS_ENV: test
    steps:
      - checkout
      - install-system-dependencies
      - install-ruby-dependencies:
          ruby-version: '3.0'
      - node/install-packages:
          cache-version: v1
          pkg-manager: yarn
      - run:
          command: ./bin/rails assets:precompile
          name: Precompile assets
      - persist_to_workspace:
          paths:
            - public/assets
            - public/packs-test
          root: .

  test:
    parameters:
      ruby-version:
        type: string
    executor:
      name: default
      ruby-version: << parameters.ruby-version >>
    environment:
      ALLOW_NOPAM: true
      PAM_ENABLED: true
      PAM_DEFAULT_SERVICE: pam_test
      PAM_CONTROLLED_SERVICE: pam_test_controlled
    parallelism: 4
    steps:
      - checkout
      - install-system-dependencies
      - run:
          command: sudo apt-get install -y ffmpeg imagemagick libpam-dev
          name: Install additional system dependencies
      - run:
          command: bundle config with 'pam_authentication'
          name: Enable PAM authentication
      - install-ruby-dependencies:
          ruby-version: << parameters.ruby-version >>
      - attach_workspace:
          at: .
      - wait-db
      - run:
          command: ./bin/rails db:create db:schema:load db:seed
          name: Load database schema
      - ruby/rspec-test

  test-migrations:
    executor:
      name: default
      ruby-version: '3.0'
    steps:
      - checkout
      - install-system-dependencies
      - install-ruby-dependencies:
          ruby-version: '3.0'
      - wait-db
      - run:
          command: ./bin/rails db:create
          name: Create database
      - run:
          command: ./bin/rails db:migrate VERSION=20171010025614
          name: Run migrations up to v2.0.0
      - run:
          command: ./bin/rails tests:migrations:populate_v2
          name: Populate database with test data
      - run:
          command: ./bin/rails db:migrate
          name: Run all remaining migrations

  test-two-step-migrations:
    executor:
      name: default
      ruby-version: '3.0'
    steps:
      - checkout
      - install-system-dependencies
      - install-ruby-dependencies:
          ruby-version: '3.0'
      - wait-db
      - run:
          command: ./bin/rails db:create
          name: Create database
      - run:
          command: ./bin/rails db:migrate VERSION=20171010025614
          name: Run migrations up to v2.0.0
      - run:
          command: ./bin/rails tests:migrations:populate_v2
          name: Populate database with test data
      - run:
          command: ./bin/rails db:migrate
          name: Run all pre-deployment migrations
          evironment:
            SKIP_POST_DEPLOYMENT_MIGRATIONS: true
      - run:
          command: ./bin/rails db:migrate
          name: Run all post-deployment remaining migrations

workflows:
  version: 2
  build-and-test:
    jobs:
      - build
      - test:
          matrix:
            parameters:
              ruby-version:
                - '2.7'
                - '3.0'
          name: test-ruby<< matrix.ruby-version >>
          requires:
            - build
      - test-migrations:
          requires:
            - build
      - test-two-step-migrations:
          requires:
            - build
      - node/run:
          cache-version: v1
          name: test-webui
          pkg-manager: yarn
          requires:
            - build
          version: lts
          yarn-run: test:jest