ci(gitlab-ci): add `rubocop` linter (with `allow_failure`) [skip ci]
[arvados-formula.git] / .gitlab-ci.yml
1 # -*- coding: utf-8 -*-
2 # vim: ft=yaml
3 ---
4 ###############################################################################
5 # Define all YAML node anchors
6 ###############################################################################
7 .node_anchors:
8   # `only` (also used for `except` where applicable)
9   only_branch_master_parent_repo: &only_branch_master_parent_repo
10     - 'master@saltstack-formulas/arvados-formula'
11   # `stage`
12   stage_lint: &stage_lint 'lint'
13   stage_release: &stage_release 'release'
14   stage_test: &stage_test 'test'
15   # `image`
16   image_commitlint: &image_commitlint 'myii/ssf-commitlint:11'
17   image_dindruby: &image_dindruby 'myii/ssf-dind-ruby:2.7.1-r3'
18   image_precommit: &image_precommit
19     name: 'myii/ssf-pre-commit:2.9.2'
20     entrypoint: ['/bin/bash', '-c']
21   image_rubocop: &image_rubocop 'pipelinecomponents/rubocop:latest'
22   image_semantic-release: &image_semanticrelease 'myii/ssf-semantic-release:15.14'
23   # `services`
24   services_docker_dind: &services_docker_dind
25     - 'docker:dind'
26   # `variables`
27   # https://forum.gitlab.com/t/gitlab-com-ci-caching-rubygems/5627/3
28   # https://bundler.io/v1.16/bundle_config.html
29   variables_bundler: &variables_bundler
30     BUNDLE_CACHE_PATH: '${CI_PROJECT_DIR}/.cache/bundler'
31     BUNDLE_WITHOUT: 'production'
32   # `cache`
33   cache_bundler: &cache_bundler
34     key: '${CI_JOB_STAGE}'
35     paths:
36       - '${BUNDLE_CACHE_PATH}'
37
38 ###############################################################################
39 # Define stages and global variables
40 ###############################################################################
41 stages:
42   - *stage_lint
43   - *stage_test
44   - *stage_release
45 variables:
46   DOCKER_DRIVER: 'overlay2'
47
48 ###############################################################################
49 # `lint` stage: `commitlint` & `pre-commit`
50 ###############################################################################
51 commitlint:
52   stage: *stage_lint
53   image: *image_commitlint
54   script:
55     # Add `upstream` remote to get access to `upstream/master`
56     - 'git remote add upstream ${CI_PROJECT_URL}.git'
57     - 'git fetch --all'
58     # Set default commit hashes for `--from` and `--to`
59     - 'export COMMITLINT_FROM="$(git merge-base upstream/master HEAD)"'
60     - 'export COMMITLINT_TO="${CI_COMMIT_SHA}"'
61     # `coqbot` adds a merge commit to test PRs on top of the latest commit in
62     # the repo; amend this merge commit message to avoid failure
63     - |
64       if [ "${GITLAB_USER_LOGIN}" = "coqbot" ] \
65       && [ "${CI_COMMIT_BRANCH}" != "master" ]; then
66         git commit --amend -m \
67           'chore: reword coqbot merge commit message for commitlint'
68         export COMMITLINT_TO=HEAD
69       fi
70     # Run `commitlint`
71     - 'commitlint --from "${COMMITLINT_FROM}"
72                   --to   "${COMMITLINT_TO}"
73                   --verbose'
74
75 pre-commit:
76   stage: *stage_lint
77   image: *image_precommit
78   # https://pre-commit.com/#gitlab-ci-example
79   variables:
80     PRE_COMMIT_HOME: '${CI_PROJECT_DIR}/.cache/pre-commit'
81   cache:
82     key: '${CI_JOB_NAME}'
83     paths:
84       - '${PRE_COMMIT_HOME}'
85   script:
86     - 'pre-commit run --all-files --color always --verbose'
87
88 # Use a separate job for `rubocop` other than the one potentially run by `pre-commit`
89 # - The `pre-commit` check will only be available for formulas that pass the default
90 #   `rubocop` check -- and must continue to do so
91 # - This job is allowed to fail, so can be used for all formulas
92 # - Furthermore, this job uses all of the latest `rubocop` features & cops,
93 #   which will help when upgrading the `rubocop` linter used in `pre-commit`
94 rubocop:
95   allow_failure: true
96   stage: *stage_lint
97   image: *image_rubocop
98   script:
99     - 'rubocop -d -P -S --enable-pending-cops'
100
101 ###############################################################################
102 # Define `test` template
103 ###############################################################################
104 .test_instance:
105   stage: *stage_test
106   image: *image_dindruby
107   services: *services_docker_dind
108   variables: *variables_bundler
109   cache: *cache_bundler
110   before_script:
111     # TODO: This should work from the env vars above automatically
112     - 'bundle config set path "${BUNDLE_CACHE_PATH}"'
113     - 'bundle config set without "${BUNDLE_WITHOUT}"'
114     - 'bundle install'
115   script:
116     # Alternative value to consider: `${CI_JOB_NAME}`
117     - 'bin/kitchen verify "${DOCKER_ENV_CI_JOB_NAME}"'
118
119 ###############################################################################
120 # `test` stage: each instance below uses the `test` template above
121 ###############################################################################
122 ## Define the rest of the matrix based on Kitchen testing
123 # Make sure the instances listed below match up with
124 # the `platforms` defined in `kitchen.yml`
125 # api-debian-10-tiamat-py3: {extends: '.test_instance'}
126 # keepstore-debian-10-tiamat-py3: {extends: '.test_instance'}
127 # shell-debian-10-tiamat-py3: {extends: '.test_instance'}
128 # workbench-debian-10-tiamat-py3: {extends: '.test_instance'}
129 # api-debian-9-tiamat-py3: {extends: '.test_instance'}
130 # keepstore-debian-9-tiamat-py3: {extends: '.test_instance'}
131 # shell-debian-9-tiamat-py3: {extends: '.test_instance'}
132 # workbench-debian-9-tiamat-py3: {extends: '.test_instance'}
133 # api-ubuntu-2004-tiamat-py3: {extends: '.test_instance'}
134 # keepstore-ubuntu-2004-tiamat-py3: {extends: '.test_instance'}
135 # shell-ubuntu-2004-tiamat-py3: {extends: '.test_instance'}
136 # workbench-ubuntu-2004-tiamat-py3: {extends: '.test_instance'}
137 # api-ubuntu-1804-tiamat-py3: {extends: '.test_instance'}
138 # keepstore-ubuntu-1804-tiamat-py3: {extends: '.test_instance'}
139 # shell-ubuntu-1804-tiamat-py3: {extends: '.test_instance'}
140 # workbench-ubuntu-1804-tiamat-py3: {extends: '.test_instance'}
141 # api-centos-7-tiamat-py3: {extends: '.test_instance'}
142 # keepstore-centos-7-tiamat-py3: {extends: '.test_instance'}
143 # shell-centos-7-tiamat-py3: {extends: '.test_instance'}
144 # workbench-centos-7-tiamat-py3: {extends: '.test_instance'}
145 # api-debian-10-master-py3: {extends: '.test_instance'}
146 # keepstore-debian-10-master-py3: {extends: '.test_instance'}
147 # shell-debian-10-master-py3: {extends: '.test_instance'}
148 # workbench-debian-10-master-py3: {extends: '.test_instance'}
149 # api-ubuntu-2004-master-py3: {extends: '.test_instance'}
150 # keepstore-ubuntu-2004-master-py3: {extends: '.test_instance'}
151 # shell-ubuntu-2004-master-py3: {extends: '.test_instance'}
152 # workbench-ubuntu-2004-master-py3: {extends: '.test_instance'}
153 # api-ubuntu-1804-master-py3: {extends: '.test_instance'}
154 # keepstore-ubuntu-1804-master-py3: {extends: '.test_instance'}
155 # shell-ubuntu-1804-master-py3: {extends: '.test_instance'}
156 # workbench-ubuntu-1804-master-py3: {extends: '.test_instance'}
157 # api-debian-10-3001-py3: {extends: '.test_instance'}
158 # keepstore-debian-10-3001-py3: {extends: '.test_instance'}
159 # shell-debian-10-3001-py3: {extends: '.test_instance'}
160 # workbench-debian-10-3001-py3: {extends: '.test_instance'}
161 # api-debian-9-3001-py3: {extends: '.test_instance'}
162 # keepstore-debian-9-3001-py3: {extends: '.test_instance'}
163 # shell-debian-9-3001-py3: {extends: '.test_instance'}
164 # workbench-debian-9-3001-py3: {extends: '.test_instance'}
165 # api-ubuntu-2004-3001-py3: {extends: '.test_instance'}
166 # keepstore-ubuntu-2004-3001-py3: {extends: '.test_instance'}
167 # shell-ubuntu-2004-3001-py3: {extends: '.test_instance'}
168 # workbench-ubuntu-2004-3001-py3: {extends: '.test_instance'}
169 # api-ubuntu-1804-3001-py3: {extends: '.test_instance'}
170 # keepstore-ubuntu-1804-3001-py3: {extends: '.test_instance'}
171 # shell-ubuntu-1804-3001-py3: {extends: '.test_instance'}
172 # workbench-ubuntu-1804-3001-py3: {extends: '.test_instance'}
173 # api-centos-7-3001-py3: {extends: '.test_instance'}
174 # keepstore-centos-7-3001-py3: {extends: '.test_instance'}
175 shell-centos-7-3001-py3: {extends: '.test_instance'}
176 # workbench-centos-7-3001-py3: {extends: '.test_instance'}
177 # api-debian-10-3000-3-py3: {extends: '.test_instance'}
178 # keepstore-debian-10-3000-3-py3: {extends: '.test_instance'}
179 # shell-debian-10-3000-3-py3: {extends: '.test_instance'}
180 # workbench-debian-10-3000-3-py3: {extends: '.test_instance'}
181 # api-debian-9-3000-3-py3: {extends: '.test_instance'}
182 # keepstore-debian-9-3000-3-py3: {extends: '.test_instance'}
183 # shell-debian-9-3000-3-py3: {extends: '.test_instance'}
184 # workbench-debian-9-3000-3-py3: {extends: '.test_instance'}
185 # api-ubuntu-1804-3000-3-py3: {extends: '.test_instance'}
186 # keepstore-ubuntu-1804-3000-3-py3: {extends: '.test_instance'}
187 # shell-ubuntu-1804-3000-3-py3: {extends: '.test_instance'}
188 # workbench-ubuntu-1804-3000-3-py3: {extends: '.test_instance'}
189 # api-centos-7-3000-3-py3: {extends: '.test_instance'}
190 keepstore-centos-7-3000-3-py3: {extends: '.test_instance'}
191 # shell-centos-7-3000-3-py3: {extends: '.test_instance'}
192 # workbench-centos-7-3000-3-py3: {extends: '.test_instance'}
193 # api-ubuntu-1804-3000-3-py2: {extends: '.test_instance'}
194 # keepstore-ubuntu-1804-3000-3-py2: {extends: '.test_instance'}
195 # shell-ubuntu-1804-3000-3-py2: {extends: '.test_instance'}
196 # workbench-ubuntu-1804-3000-3-py2: {extends: '.test_instance'}
197
198 ###############################################################################
199 # `release` stage: `semantic-release`
200 ###############################################################################
201 semantic-release:
202   only: *only_branch_master_parent_repo
203   stage: *stage_release
204   image: *image_semanticrelease
205   variables:
206     MAINTAINER_TOKEN: '${GH_TOKEN}'
207   script:
208     # Update `AUTHORS.md`
209     - '${HOME}/go/bin/maintainer contributor'
210     # Run `semantic-release`
211     - 'semantic-release'