Skip to content

Commit

Permalink
feat(gitlab-ci): manage across formulas
Browse files Browse the repository at this point in the history
Include adapting for using `coqbot`.
  • Loading branch information
myii committed Dec 17, 2020
1 parent 65ca911 commit b0a854c
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 5 deletions.
83 changes: 83 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
###############################################################################
# Define all YAML node anchors
###############################################################################
.node_anchors:
# `only` (also used for `except` where applicable)
only_branch_master_parent_repo: &only_branch_master_parent_repo
- 'master@myii/ssf-formula'
# `stage`
stage_lint: &stage_lint 'lint'
stage_release: &stage_release 'release'
# `image`
image_commitlint: &image_commitlint 'myii/ssf-commitlint:11'
image_precommit: &image_precommit
name: 'myii/ssf-pre-commit:2.9.2'
entrypoint: ['/bin/bash', '-c']
image_semantic-release: &image_semanticrelease 'myii/ssf-semantic-release:15.14'

###############################################################################
# Define stages and global variables
###############################################################################
stages:
- *stage_lint
- *stage_release
variables:
DOCKER_DRIVER: 'overlay2'

###############################################################################
# `lint` stage: `commitlint` & `pre-commit`
###############################################################################
commitlint:
stage: *stage_lint
image: *image_commitlint
script:
# Add `upstream` remote to get access to `upstream/master`
- 'git remote add upstream ${CI_PROJECT_URL}.git'
- 'git fetch --all'
# Set default commit hashes for `--from` and `--to`
- 'export COMMITLINT_FROM="$(git merge-base upstream/master HEAD)"'
- 'export COMMITLINT_TO="${CI_COMMIT_SHA}"'
# `coqbot` adds a merge commit to test PRs on top of the latest commit in
# the repo; amend this merge commit message to avoid failure
- |
if [ "${GITLAB_USER_LOGIN}" = "coqbot" ] \
&& [ "${CI_COMMIT_BRANCH}" != "master" ]; then
git commit --amend -m \
'chore: reword coqbot merge commit message for commitlint'
export COMMITLINT_TO=HEAD
fi
# Run `commitlint`
- 'commitlint --from "${COMMITLINT_FROM}"
--to "${COMMITLINT_TO}"
--verbose'

pre-commit:
stage: *stage_lint
image: *image_precommit
# https://pre-commit.com/#gitlab-ci-example
variables:
PRE_COMMIT_HOME: '${CI_PROJECT_DIR}/.cache/pre-commit'
cache:
key: '${CI_JOB_NAME}'
paths:
- '${PRE_COMMIT_HOME}'
script:
- 'pre-commit run --all-files --color always --verbose'

###############################################################################
# `release` stage: `semantic-release`
###############################################################################
semantic-release:
only: *only_branch_master_parent_repo
stage: *stage_release
image: *image_semanticrelease
variables:
MAINTAINER_TOKEN: '${GH_TOKEN}'
script:
# Update `AUTHORS.md`
- '${HOME}/go/bin/maintainer contributor'
# Run `semantic-release`
- 'semantic-release'
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ignore: |
test/**/states/**/*.sls
.kitchen/
ssf/files/default/.cirrus.yml
ssf/files/default/.gitlab-ci.yml
ssf/files/default/.pre-commit-config.yaml
ssf/files/default/.rubocop.yml
ssf/files/default/.salt-lint
Expand Down
1 change: 1 addition & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ ssf:
- inspec/README.md
- .gitignore
- .cirrus.yml
- .gitlab-ci.yml
- .pre-commit-config.yaml
- .rstcheck.cfg
- .rubocop.yml
Expand Down
1 change: 1 addition & 0 deletions ssf/config/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ prepare-git-branch-for-{{ formula }}:
owner: {{ owner }}
formula: {{ formula }}
codeowners: {{ context.codeowners | yaml }}
gitlab: {{ context.git.gitlab | yaml }}
inspec_suites_kitchen: {{ inspec_suites_kitchen | yaml }}
inspec_suites_matrix: {{ context.inspec_suites_matrix | yaml }}
kitchen: {{ context.kitchen | yaml }}
Expand Down
11 changes: 9 additions & 2 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ssf_node_anchors:
- '/test/integration/**/README.md': '@saltstack-formulas/ssf'
- '/.gitignore': '@saltstack-formulas/ssf'
- '/.cirrus.yml': '@saltstack-formulas/ssf'
- '/.gitlab-ci.yml': '@saltstack-formulas/ssf'
- '/.pre-commit-config.yaml': '@saltstack-formulas/ssf'
- '/.rstcheck.cfg': '@saltstack-formulas/ssf'
- '/.rubocop.yml': '@saltstack-formulas/ssf'
Expand Down Expand Up @@ -58,8 +59,8 @@ ssf_node_anchors:
# An alternative method could be to use:
# `git describe --abbrev=0 --tags`
# yamllint disable rule:line-length rule:quoted-strings
title: "test(map): verify '`'map.jinja'`' dump using '`'_mapdata'`' state"
body: '* Semi-automated using https://github.com/myii/ssf-formula/pull/271'
title: "ci(gitlab-ci): use GitLab CI as Travis CI replacement"
body: '* Automated using https://github.com/myii/ssf-formula/pull/275'
# yamllint enable rule:line-length rule:quoted-strings
github:
owner: 'saltstack-formulas'
Expand All @@ -71,6 +72,12 @@ ssf_node_anchors:
fork:
name: 'origin'
branch: 'master'
# Currently supporting `ci_cd_only` for GitHub repos
gitlab:
# `coqbot` doesn't currently support sub-groups, only `owner/repo`
# owner: 'saltstack-formulas/formulas/github/saltstack-formulas'
owner: 'saltstack-formulas'
repo: ''
inspec_suites_kitchen: &isk_default
0: &isk_suite_default
name: 'default'
Expand Down
195 changes: 195 additions & 0 deletions ssf/files/default/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
{%- from tplroot ~ "/libcimatrix.jinja" import format_ci_matrix with context %}

{#- Prepare variable used for `saltcheck` #}
{%- set use_saltcheck = False %}
{%- if semrel_formula in ['cron'] %}
{%- set use_saltcheck = True %}
{%- endif %}
###############################################################################
# Define all YAML node anchors
###############################################################################
.node_anchors:
# `only` (also used for `except` where applicable)
only_branch_master_parent_repo: &only_branch_master_parent_repo
- 'master@{{ gitlab.owner }}/{{ gitlab.repo or formula }}'
# `stage`
stage_lint: &stage_lint 'lint'
stage_release: &stage_release 'release'
{%- if semrel_formula != 'ssf' %}
stage_test: &stage_test 'test'
{%- endif %}
# `image`
image_commitlint: &image_commitlint 'myii/ssf-commitlint:11'
{%- if semrel_formula != 'ssf' %}
image_dindruby: &image_dindruby 'myii/ssf-dind-ruby:2.7.1-r3'
{%- if semrel_formula == 'template' %}
image_dindrubybionic: &image_dindrubybionic 'myii/ssf-dind-ruby-bionic:1_2.5.1'
{%- endif %}
{%- endif %}
image_precommit: &image_precommit
name: 'myii/ssf-pre-commit:2.9.2'
entrypoint: ['/bin/bash', '-c']
image_semantic-release: &image_semanticrelease 'myii/ssf-semantic-release:15.14'
{%- if semrel_formula != 'ssf' %}
# `services`
services_docker_dind: &services_docker_dind
- 'docker:dind'
# `variables`
# https://forum.gitlab.com/t/gitlab-com-ci-caching-rubygems/5627/3
# https://bundler.io/v1.16/bundle_config.html
variables_bundler: &variables_bundler
BUNDLE_CACHE_PATH: '${CI_PROJECT_DIR}/.cache/bundler'
BUNDLE_WITHOUT: 'production'
# `cache`
cache_bundler: &cache_bundler
key: '${CI_JOB_STAGE}'
paths:
- '${BUNDLE_CACHE_PATH}'
{%- endif %}

###############################################################################
# Define stages and global variables
###############################################################################
stages:
- *stage_lint
{%- if semrel_formula != 'ssf' %}
- *stage_test
{%- endif %}
- *stage_release
variables:
DOCKER_DRIVER: 'overlay2'

###############################################################################
# `lint` stage: `commitlint` & `pre-commit`
###############################################################################
commitlint:
stage: *stage_lint
image: *image_commitlint
script:
# Add `upstream` remote to get access to `upstream/master`
- 'git remote add upstream ${CI_PROJECT_URL}.git'
- 'git fetch --all'
# Set default commit hashes for `--from` and `--to`
- 'export COMMITLINT_FROM="$(git merge-base upstream/master HEAD)"'
- 'export COMMITLINT_TO="${CI_COMMIT_SHA}"'
# `coqbot` adds a merge commit to test PRs on top of the latest commit in
# the repo; amend this merge commit message to avoid failure
- |
if [ "${GITLAB_USER_LOGIN}" = "coqbot" ] \
&& [ "${CI_COMMIT_BRANCH}" != "master" ]; then
git commit --amend -m \
'chore: reword coqbot merge commit message for commitlint'
export COMMITLINT_TO=HEAD
fi
# Run `commitlint`
- 'commitlint --from "${COMMITLINT_FROM}"
--to "${COMMITLINT_TO}"
--verbose'

pre-commit:
stage: *stage_lint
image: *image_precommit
# https://pre-commit.com/#gitlab-ci-example
variables:
PRE_COMMIT_HOME: '${CI_PROJECT_DIR}/.cache/pre-commit'
cache:
key: '${CI_JOB_NAME}'
paths:
- '${PRE_COMMIT_HOME}'
script:
- 'pre-commit run --all-files --color always --verbose'

{%- if platforms and not use_cirrus_ci %}

###############################################################################
# Define `test` template
###############################################################################
.test_instance:
stage: *stage_test
image: *image_dindruby
services: *services_docker_dind
variables: *variables_bundler
cache: *cache_bundler
before_script:
# TODO: This should work from the env vars above automatically
- 'bundle config set path "${BUNDLE_CACHE_PATH}"'
- 'bundle config set without "${BUNDLE_WITHOUT}"'
- 'bundle install'
script:
# Alternative value to consider: `${CI_JOB_NAME}`
- '{{ script_kitchen.bin }} {{ script_kitchen.cmd }} "${DOCKER_ENV_CI_JOB_NAME}"'

{%- if semrel_formula == 'template' %}
# <REMOVEME

###############################################################################
# Define `test_conversion` template
###############################################################################
.test_conversion:
stage: *stage_test
image: *image_dindrubybionic
services: *services_docker_dind
variables: *variables_bundler
cache: *cache_bundler
before_script:
- 'export CONVERTED=test-the-use_this_template-button'
- 'git clone . tmp/"${CONVERTED}"-formula'
- 'cd tmp/"${CONVERTED}"-formula'
# Install `pre-commit` hooks
- 'bin/install-hooks'
# Run the conversion script with debug output
- 'DEBUG=true bin/convert-formula.sh "${CONVERTED}"'
- '[ $(git rev-list HEAD --count) -eq 2 ]'
# Quick visual check that correct files have been updated
- 'git show --pretty="" --name-status'
# TODO: This should work from the env vars above automatically
- 'bundle config set path "${BUNDLE_CACHE_PATH}"'
- 'bundle config set without "${BUNDLE_WITHOUT}"'
- 'bundle install'
script:
- '{{ script_kitchen.bin }} {{ script_kitchen.cmd }} default-debian-10-tiamat-py3'
# REMOVEME>
{%- endif %}

###############################################################################
# `test` stage: each instance below uses the `test` template above
###############################################################################
## Define the rest of the matrix based on Kitchen testing
# Make sure the instances listed below match up with
# the `platforms` defined in `kitchen.yml`
{%- if semrel_formula == 'template' %}
# <REMOVEME
# NOTE: Please try to select up to six instances that add some meaningful
# testing of the formula's behaviour. If possible, try to refrain from
# the classical "chosing all the instances because I want to test on
# another/all distro/s" trap: it will just add time to the testing (see
# the discussion on #121). As an example, the set chosen below covers
# the most used distros families, systemd and non-systemd and the latest
# three supported Saltstack versions with python2 and 3.
# As for `kitchen.yml`, that should still contain all of the platforms,
# to allow for comprehensive local testing
# Ref: https://github.com/saltstack-formulas/template-formula/issues/118
# Ref: https://github.com/saltstack-formulas/template-formula/issues/121
test-formula-conversion: {extends: '.test_conversion'}
# REMOVEME>
{%- endif %}
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, width=0, use_gitlab_format=True) }}
{%- endif %}

###############################################################################
# `release` stage: `semantic-release`
###############################################################################
semantic-release:
only: *only_branch_master_parent_repo
stage: *stage_release
image: *image_semanticrelease
variables:
MAINTAINER_TOKEN: '${GH_TOKEN}'
script:
# Update `AUTHORS.md`
- '${HOME}/go/bin/maintainer contributor'
# Run `semantic-release`
- 'semantic-release'
7 changes: 7 additions & 0 deletions ssf/formulas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ ssf_node_anchors:
.cirrus.yml: &file__--cirrus--yml
<<: *file_default
template: 'jinja'
.gitlab-ci.yml: &file__--gitlab-ci--yml
<<: *file_default
template: 'jinja'
.pre-commit-config.yaml: &file__--pre-commit-config--yaml
<<: *file_default
template: 'jinja'
Expand Down Expand Up @@ -4393,6 +4396,8 @@ ssf:
github:
owner: 'myii'
repo: 'ssf-formula'
gitlab:
owner: 'myii'
inspec_suites_kitchen:
0:
inspec_yml:
Expand All @@ -4410,6 +4415,7 @@ ssf:
ignore:
additional:
- ssf/files/default/.cirrus.yml
- ssf/files/default/.gitlab-ci.yml
- ssf/files/default/.pre-commit-config.yaml
- ssf/files/default/.rubocop.yml
- ssf/files/default/.salt-lint
Expand All @@ -4431,6 +4437,7 @@ ssf:
docs/TOFS_pattern.rst: *file__docs__TOFS_pattern--rst
formula/libtofs.jinja: *file__formula__libtofs--jinja
.gitignore: *file__--gitignore
.gitlab-ci.yml: *file__--gitlab-ci--yml
.pre-commit-config.yaml: *file__--pre-commit-config--yaml
.rstcheck.cfg: *file__--rstcheck--cfg
.rubocop.yml: *file__--rubocop--yml
Expand Down
Loading

0 comments on commit b0a854c

Please sign in to comment.