template-formula/.gitlab-ci.yml
Dafydd Jones e3d3c121ef
Merge pull request #273 from jeff350/update_test_images
ci: use latest test images
2025-03-25 18:10:22 +00:00

254 lines
12 KiB
YAML

# -*- 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@saltstack-formulas/template-formula'
# `stage`
stage_lint: &stage_lint 'lint'
stage_release: &stage_release 'release'
stage_test: &stage_test 'test'
# `image`
image_commitlint: &image_commitlint 'techneg/ci-commitlint:v1.1.76'
image_dindruby: &image_dindruby 'techneg/ci-docker-python-ruby:v2.2.45'
image_dindrubybionic: &image_dindrubybionic 'techneg/ci-docker-python-ruby:v2.2.45'
image_precommit: &image_precommit 'techneg/ci-pre-commit:v2.4.10'
image_rubocop: &image_rubocop 'pipelinecomponents/rubocop:latest'
image_semantic-release: &image_semanticrelease 'myii/ssf-semantic-release:15.14'
# `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}'
###############################################################################
# Define stages and global variables
###############################################################################
stages:
- *stage_lint
- *stage_test
- *stage_release
variables:
DOCKER_DRIVER: 'overlay2'
###############################################################################
# `lint` stage: `commitlint`, `pre-commit` & `rubocop` (latest, failure allowed)
###############################################################################
commitlint:
stage: *stage_lint
image: *image_commitlint
script:
# Add `upstream` remote to get access to `upstream/master`
- 'git remote add upstream
https://gitlab.com/saltstack-formulas/template-formula.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'
# Use a separate job for `rubocop` other than the one potentially run by `pre-commit`
# - The `pre-commit` check will only be available for formulas that pass the default
# `rubocop` check -- and must continue to do so
# - This job is allowed to fail, so can be used for all formulas
# - Furthermore, this job uses all of the latest `rubocop` features & cops,
# which will help when upgrading the `rubocop` linter used in `pre-commit`
rubocop:
allow_failure: true
stage: *stage_lint
image: *image_rubocop
script:
- 'rubocop -d -P -S --enable-pending-cops'
###############################################################################
# Define `test` template
###############################################################################
.test_instance: &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}`
- 'bin/kitchen verify "${DOCKER_ENV_CI_JOB_NAME}"'
###############################################################################
# Define `test` template (`allow_failure: true`)
###############################################################################
.test_instance_failure_permitted:
<<: *test_instance
allow_failure: true
# <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'
- 'git config user.email "test@example.com"'
- 'git config user.name "Test Name"'
# 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:
- 'bin/kitchen verify default-debian-11-master-py3'
# REMOVEME>
###############################################################################
# `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`
# <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>
# yamllint disable rule:line-length
# Fedora 41+ will permit failure until this PR is merged into kitchen-docker
# https://github.com/test-kitchen/kitchen-docker/pull/427 is merged
# OpenSUSE master branch will fail until zypperpkg module is back in salt core
# https://github.com/saltstack/great-module-migration/issues/14
#
default-debian-12-master-py3: {extends: '.test_instance'}
default-debian-11-master-py3: {extends: '.test_instance'}
default-ubuntu-2404-master-py3: {extends: '.test_instance'}
default-ubuntu-2204-master-py3: {extends: '.test_instance'}
default-ubuntu-2004-master-py3: {extends: '.test_instance'}
default-centos-stream9-master-py3: {extends: '.test_instance'}
default-opensuse-leap-156-master-py3: {extends: '.test_instance_failure_permitted'}
default-opensuse-leap-155-master-py3: {extends: '.test_instance'}
default-opensuse-tmbl-latest-master-py3: {extends: '.test_instance'}
default-amazonlinux-2023-master-py3: {extends: '.test_instance'}
default-fedora-41-master-py3: {extends: '.test_instance_failure_permitted'}
default-fedora-40-master-py3: {extends: '.test_instance'}
default-oraclelinux-9-master-py3: {extends: '.test_instance'}
default-oraclelinux-8-master-py3: {extends: '.test_instance'}
default-almalinux-9-master-py3: {extends: '.test_instance'}
default-almalinux-8-master-py3: {extends: '.test_instance'}
default-rockylinux-9-master-py3: {extends: '.test_instance'}
default-rockylinux-8-master-py3: {extends: '.test_instance'}
default-debian-12-3007-1-py3: {extends: '.test_instance'}
default-debian-11-3007-1-py3: {extends: '.test_instance'}
default-ubuntu-2404-3007-1-py3: {extends: '.test_instance'}
default-ubuntu-2204-3007-1-py3: {extends: '.test_instance'}
default-ubuntu-2004-3007-1-py3: {extends: '.test_instance'}
default-centos-stream9-3007-1-py3: {extends: '.test_instance'}
default-opensuse-leap-156-3007-1-py3: {extends: '.test_instance'}
default-opensuse-leap-155-3007-1-py3: {extends: '.test_instance'}
default-opensuse-tmbl-latest-3007-1-py3: {extends: '.test_instance'}
default-fedora-41-3007-1-py3: {extends: '.test_instance_failure_permitted'}
default-fedora-40-3007-1-py3: {extends: '.test_instance'}
default-amazonlinux-2-3007-1-py3: {extends: '.test_instance_failure_permitted'}
default-amazonlinux-2023-3007-1-py3: {extends: '.test_instance'}
default-oraclelinux-9-3007-1-py3: {extends: '.test_instance'}
default-oraclelinux-8-3007-1-py3: {extends: '.test_instance'}
default-almalinux-9-3007-1-py3: {extends: '.test_instance'}
default-almalinux-8-3007-1-py3: {extends: '.test_instance'}
default-rockylinux-9-3007-1-py3: {extends: '.test_instance'}
default-rockylinux-8-3007-1-py3: {extends: '.test_instance'}
default-debian-12-3006-10-py3: {extends: '.test_instance'}
default-debian-11-3006-10-py3: {extends: '.test_instance'}
default-ubuntu-2404-3006-10-py3: {extends: '.test_instance'}
default-ubuntu-2204-3006-10-py3: {extends: '.test_instance'}
default-ubuntu-2004-3006-10-py3: {extends: '.test_instance'}
default-centos-stream9-3006-10-py3: {extends: '.test_instance'}
default-opensuse-leap-156-3006-10-py3: {extends: '.test_instance'}
default-opensuse-leap-155-3006-10-py3: {extends: '.test_instance'}
default-opensuse-tmbl-latest-3006-10-py3: {extends: '.test_instance'}
default-fedora-41-3006-10-py3: {extends: '.test_instance_failure_permitted'}
default-fedora-40-3006-10-py3: {extends: '.test_instance'}
default-amazonlinux-2-3006-10-py3: {extends: '.test_instance_failure_permitted'}
default-amazonlinux-2023-3006-10-py3: {extends: '.test_instance'}
default-oraclelinux-9-3006-10-py3: {extends: '.test_instance'}
default-oraclelinux-8-3006-10-py3: {extends: '.test_instance'}
default-almalinux-9-3006-10-py3: {extends: '.test_instance'}
default-almalinux-8-3006-10-py3: {extends: '.test_instance'}
default-rockylinux-9-3006-10-py3: {extends: '.test_instance'}
default-rockylinux-8-3006-10-py3: {extends: '.test_instance'}
# yamllint enable rule:line-length
###############################################################################
# `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'