ci(travis): use structure of template-formula

This commit is contained in:
Alexander Weidinger 2019-04-24 18:18:10 +02:00
parent 475ad4f5f2
commit 88d3f3e2f8
17 changed files with 553 additions and 1 deletions

106
.gitignore vendored Normal file
View File

@ -0,0 +1,106 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a packager
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.kitchen
.kitchen.local.yml
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
# copied `.md` files used for conversion to `.rst` using `m2r`
docs/*.md

View File

@ -1 +0,0 @@
*~

61
.travis.yml Normal file
View File

@ -0,0 +1,61 @@
stages:
- test
- commitlint
- name: release
if: branch = master AND type != pull_request
sudo: required
cache: bundler
language: ruby
services:
- docker
before_install:
- bundle install
# Make sure the instances listed below match up with
# the `platforms` defined in `kitchen.yml`
env:
matrix:
- INSTANCE: default-debian-9-2019-2-py3
- INSTANCE: default-ubuntu-1804-2019-2-py3
- INSTANCE: default-ubuntu-1604-2018-3-py2
- INSTANCE: default-ubuntu-1604-2017-7-py2
script:
- bundle exec kitchen verify ${INSTANCE}
jobs:
include:
# Define the commitlint stage
- stage: commitlint
language: node_js
node_js: lts/*
before_install: skip
script:
- npm install @commitlint/config-conventional -D
- npm install @commitlint/travis-cli -D
- commitlint-travis
# Define the release stage that runs semantic-release
- stage: release
language: node_js
node_js: lts/*
before_install: skip
script:
# Update `AUTHORS.md`
- export MAINTAINER_TOKEN=${GH_TOKEN}
- go get github.com/alxwr/maintainer
- maintainer contributor
# Install all dependencies required for `semantic-release`
- npm install @semantic-release/changelog@3 -D
- npm install @semantic-release/exec@3 -D
- npm install @semantic-release/git@7 -D
deploy:
provider: script
skip_cleanup: true
script:
# Run `semantic-release`
- npx semantic-release@15

1
CHANGELOG.md Normal file
View File

@ -0,0 +1 @@

9
FORMULA Normal file
View File

@ -0,0 +1,9 @@
name: prometheus
os: FreeBSD
os_family: FreeBSD
version: 0.0.1
release: 1
minimum_version: 2016.11
summary: Prometheus formula
description: Formula to set up Prometheus
top_level_dir: prometheus

6
Gemfile Normal file
View File

@ -0,0 +1,6 @@
source "https://rubygems.org"
gem 'kitchen-docker', '>= 2.9'
gem 'kitchen-salt', '>= 0.5.0'
gem 'kitchen-inspec', '>= 1.1'

13
LICENSE Normal file
View File

@ -0,0 +1,13 @@
Copyright (c) 2014 Salt Stack Formulas
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

3
commitlint.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};

94
docs/README.rst Normal file
View File

@ -0,0 +1,94 @@
.. _readme:
prometheus-formula
================
|img_travis| |img_sr|
.. |img_travis| image:: https://travis-ci.com/saltstack-formulas/prometheus-formula.svg?branch=master
:alt: Travis CI Build Status
:scale: 100%
:target: https://travis-ci.com/saltstack-formulas/prometheus-formula
.. |img_sr| image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
:alt: Semantic Release
:scale: 100%
:target: https://github.com/semantic-release/semantic-release
Manage Prometheus.
.. contents:: **Table of Contents**
General notes
-------------
See the full `SaltStack Formulas installation and usage instructions
<https://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html>`_.
If you want to use this formula, please pay attention to the ``FORMULA`` file and/or ``git tag``,
which contains the currently released version. This formula is versioned according to `Semantic Versioning <http://semver.org/>`_.
See `Formula Versioning Section <https://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html#versioning>`_ for more details.
Contributing to this repo
-------------------------
Please see https://github.com/saltstack-formulas/prometheus-formula/blob/master/docs/CONTRIBUTING.rst
Available states
----------------
.. contents::
:local:
``prometheus``
^^^^^^^^^^^^
*Meta-state (This is a state that includes other states)*.
This installs the prometheus package,
manages the prometheus configuration file and then
starts the associated prometheus service.
``prometheus.package``
^^^^^^^^^^^^^^^^^^^^
This state will install the prometheus package only.
``prometheus.config``
^^^^^^^^^^^^^^^^^^^
This state will configure the prometheus service and has a dependency on ``prometheus.install``
via include list.
``prometheus.service``
^^^^^^^^^^^^^^^^^^^^
This state will start the prometheus service and has a dependency on ``prometheus.config``
via include list.
``prometheus.clean``
^^^^^^^^^^^^^^^^^^
*Meta-state (This is a state that includes other states)*.
this state will undo everything performed in the ``prometheus`` meta-state in reverse order, i.e.
stops the service,
removes the configuration file and
then uninstalls the package.
``prometheus.service.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^^
This state will stop the prometheus service and disable it at boot time.
``prometheus.config.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^
This state will remove the configuration of the prometheus service and has a
dependency on ``prometheus.service.clean`` via include list.
``prometheus.package.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^^
This state will remove the prometheus package and has a depency on
``prometheus.config.clean`` via include list.

64
kitchen.yml Normal file
View File

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
# For help on this file's format, see https://kitchen.ci/
driver:
name: docker
use_sudo: false
privileged: true
run_command: /lib/systemd/systemd
# Make sure the platforms listed below match up with
# the `env.matrix` instances defined in `.travis.yml`
platforms:
## SALT 2019.2
- name: debian-9-2019-2-py3
driver:
image: netmanagers/salt-2019.2-py3:debian-9
- name: ubuntu-1804-2019-2-py3
driver:
image: netmanagers/salt-2019.2-py3:ubuntu-1804
## SALT 2018.3
- name: ubuntu-1604-2018-3-py2
driver:
image: netmanagers/salt-2018.3-py2:ubuntu-1604
## SALT 2017.7
- name: ubuntu-1604-2017-7-py2
driver:
image: netmanagers/salt-2017.7-py2:ubuntu-1604
provisioner:
name: salt_solo
log_level: info
salt_install: none
require_chef: false
formula: prometheus
salt_copy_filter:
- .kitchen
- .git
state_top:
base:
'*':
- prometheus
pillars:
top.sls:
base:
'*':
- prometheus
pillars_from_files:
prometheus.sls: pillar.example
verifier:
# https://www.inspec.io/
name: inspec
sudo: true
# cli, documentation, html, progress, json, json-min, json-rspec, junit
reporter:
- cli
inspec_tests:
- path: test/integration/default
suites:
- name: default

30
pre-commit_semantic-release.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
###############################################################################
# (A) Update `FORMULA` with `${nextRelease.version}`
###############################################################################
sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA
###############################################################################
# (B) Use `m2r` to convert automatically produced `.md` docs to `.rst`
###############################################################################
# Install `m2r`
sudo -H pip install m2r
# Copy and then convert the `.md` docs
cp *.md docs/
cd docs/
m2r --overwrite *.md
# Change excess `H1` headings to `H2` in converted `CHANGELOG.rst`
sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst
sed -i -e '1,4s/-/=/g' CHANGELOG.rst
# Use for debugging output, when required
# cat AUTHORS.rst
# cat CHANGELOG.rst
# Return back to the main directory
cd ..

18
release-rules.js Normal file
View File

@ -0,0 +1,18 @@
// No release is triggered for the types commented out below.
// Commits using these types will be incorporated into the next release.
//
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
module.exports = [
{breaking: true, release: 'major'},
// {type: 'build', release: 'patch'},
// {type: 'chore', release: 'patch'},
// {type: 'ci', release: 'patch'},
{type: 'docs', release: 'patch'},
{type: 'feat', release: 'minor'},
{type: 'fix', release: 'patch'},
{type: 'perf', release: 'patch'},
{type: 'refactor', release: 'patch'},
{type: 'revert', release: 'patch'},
{type: 'style', release: 'patch'},
{type: 'test', release: 'patch'},
];

106
release.config.js Normal file
View File

@ -0,0 +1,106 @@
module.exports = {
branch: 'master',
plugins: [
['@semantic-release/commit-analyzer', {
preset: 'angular',
releaseRules: './release-rules.js',
}],
'@semantic-release/release-notes-generator',
['@semantic-release/changelog', {
changelogFile: 'CHANGELOG.md',
changelogTitle: '# Changelog',
}],
['@semantic-release/exec', {
prepareCmd: 'sh ./pre-commit_semantic-release.sh ${nextRelease.version}',
}],
['@semantic-release/git', {
assets: ['*.md', 'docs/*.rst', 'FORMULA'],
}],
'@semantic-release/github',
],
generateNotes: {
preset: 'angular',
writerOpts: {
// Required due to upstream bug preventing all types being displayed.
// Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317
// Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410
transform: (commit, context) => {
const issues = []
commit.notes.forEach(note => {
note.title = `BREAKING CHANGES`
})
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
if (commit.type === `feat`) {
commit.type = `Features`
} else if (commit.type === `fix`) {
commit.type = `Bug Fixes`
} else if (commit.type === `perf`) {
commit.type = `Performance Improvements`
} else if (commit.type === `revert`) {
commit.type = `Reverts`
} else if (commit.type === `docs`) {
commit.type = `Documentation`
} else if (commit.type === `style`) {
commit.type = `Styles`
} else if (commit.type === `refactor`) {
commit.type = `Code Refactoring`
} else if (commit.type === `test`) {
commit.type = `Tests`
} else if (commit.type === `build`) {
commit.type = `Build System`
// } else if (commit.type === `chore`) {
// commit.type = `Maintenance`
} else if (commit.type === `ci`) {
commit.type = `Continuous Integration`
} else {
return
}
if (commit.scope === `*`) {
commit.scope = ``
}
if (typeof commit.hash === `string`) {
commit.hash = commit.hash.substring(0, 7)
}
if (typeof commit.subject === `string`) {
let url = context.repository
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl
if (url) {
url = `${url}/issues/`
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue)
return `[#${issue}](${url}${issue})`
})
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
if (username.includes('/')) {
return `@${username}`
}
return `[@${username}](${context.host}/${username})`
})
}
}
// remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.issue) === -1) {
return true
}
return false
})
return commit
},
},
},
};

View File

@ -0,0 +1,14 @@
control 'Prometheus configuration' do
title 'should match desired lines'
describe file('/etc/prometheus/prometheus.yml') do
it { should be_file }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its('mode') { should cmp '0644' }
its('content') { should include 'File managed by Salt' }
its('content') { should include 'Your changes will be overwritten.' }
its('content') { should include 'global:' }
its('content') { should include 'alerting:' }
end
end

View File

@ -0,0 +1,7 @@
control 'Prometheus package' do
title 'should be installed'
describe package('prometheus') do
it { should be_installed }
end
end

View File

@ -0,0 +1,9 @@
control 'Prometheus service' do
impact 0.5
title 'should be running and enabled'
describe service('prometheus') do
it { should be_enabled }
it { should be_running }
end
end

View File

@ -0,0 +1,12 @@
name: prometheus
title: Prometheus Formula
maintainer: Alexander Weidinger
license: Apache-2.0
summary: Verify that the prometheus formula is setup and configured correctly
supports:
- os-name: debian
- os-name: ubuntu
- os-name: centos
- os-name: fedora
- os-name: opensuse
- os-name: freebsd