diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..dba7106f --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,150 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +############################################################################### +# Define all YAML node anchors +############################################################################### +.node_anchors: + # `stage` + stage_lint: &stage_lint 'lint' + stage_release: &stage_release 'release' + stage_test: &stage_test 'test' + # `image` + image_commitlint: &image_commitlint 'myii/ssf-commitlint:11' + image_dindruby: &image_dindruby 'myii/ssf-dind-ruby:2.7.1-r3' + 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' + # `only` (also used for `except` where applicable) + only_branch_master_parent_repo: &only_branch_master_parent_repo + - 'master@saltstack-formulas/consul-formula' + +############################################################################### +# Define stages and global variables +############################################################################### +stages: + - *stage_lint + - *stage_test + - *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 -c user.name='Null' -c user.email='null@example.com' 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' + +############################################################################### +# Define `test` template +############################################################################### +.test_instance: + stage: *stage_test + image: *image_dindruby + services: + - 'docker:dind' + # https://forum.gitlab.com/t/gitlab-com-ci-caching-rubygems/5627/3 + # https://bundler.io/v1.16/bundle_config.html + variables: + BUNDLE_CACHE_PATH: '${CI_PROJECT_DIR}/.cache/bundler' + BUNDLE_WITHOUT: 'production' + cache: + key: '${CI_JOB_STAGE}' + paths: + - '${BUNDLE_CACHE_PATH}' + 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}"' + +############################################################################### +# `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` +default-debian-10-master-py3: {extends: '.test_instance'} +default-ubuntu-2004-master-py3: {extends: '.test_instance'} +# default-ubuntu-1804-master-py3: {extends: '.test_instance'} +default-centos-8-master-py3: {extends: '.test_instance'} +default-fedora-32-master-py3: {extends: '.test_instance'} +# default-fedora-31-master-py3: {extends: '.test_instance'} +# default-opensuse-leap-152-master-py3: {extends: '.test_instance'} +# default-amazonlinux-2-master-py3: {extends: '.test_instance'} +# default-debian-10-3000-3-py3: {extends: '.test_instance'} +# default-debian-9-3000-3-py3: {extends: '.test_instance'} +# default-ubuntu-1804-3000-3-py3: {extends: '.test_instance'} +# default-centos-8-3000-3-py3: {extends: '.test_instance'} +# default-centos-7-3000-3-py3: {extends: '.test_instance'} +# default-fedora-31-3000-3-py3: {extends: '.test_instance'} +default-opensuse-leap-152-3000-3-py3: {extends: '.test_instance'} +default-amazonlinux-2-3000-3-py3: {extends: '.test_instance'} +# default-ubuntu-1804-3000-3-py2: {extends: '.test_instance'} +# default-ubuntu-1604-3000-3-py2: {extends: '.test_instance'} +# default-arch-base-latest-3000-3-py2: {extends: '.test_instance'} +# default-debian-10-2019-2-py3: {extends: '.test_instance'} +# default-debian-9-2019-2-py3: {extends: '.test_instance'} +# default-ubuntu-1804-2019-2-py3: {extends: '.test_instance'} +# default-ubuntu-1604-2019-2-py3: {extends: '.test_instance'} +# default-centos-8-2019-2-py3: {extends: '.test_instance'} +# default-centos-7-2019-2-py3: {extends: '.test_instance'} +# default-fedora-31-2019-2-py3: {extends: '.test_instance'} +# default-opensuse-leap-152-2019-2-py3: {extends: '.test_instance'} +# default-amazonlinux-2-2019-2-py3: {extends: '.test_instance'} +# default-centos-6-2019-2-py2: {extends: '.test_instance'} +# default-amazonlinux-1-2019-2-py2: {extends: '.test_instance'} +default-arch-base-latest-2019-2-py2: {extends: '.test_instance'} + +############################################################################### +# `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' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 15fcab78..00000000 --- a/.travis.yml +++ /dev/null @@ -1,143 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: ft=yaml ---- -## Machine config -os: 'linux' -arch: 'amd64' -dist: 'bionic' -version: '~> 1.0' - -## Language and cache config -language: 'ruby' -cache: 'bundler' - -## Services config -services: - - docker - -## Script to run for the test stage -script: - - bin/kitchen verify "${INSTANCE}" - -## Stages and jobs matrix -stages: - - test - - name: 'release' - if: 'branch = master AND type != pull_request' -jobs: - include: - ## Define the test stage that runs the linters (and testing matrix, if applicable) - - # Run all of the linters in a single job - - language: 'node_js' - node_js: 'lts/*' - env: 'Lint' - name: 'Lint: salt-lint, yamllint, rubocop, shellcheck & commitlint' - before_install: 'skip' - script: - # Install and run `salt-lint` - - pip install --user salt-lint - - git ls-files -- '*.sls' '*.jinja' '*.j2' '*.tmpl' '*.tst' - | xargs salt-lint - # Install and run `yamllint` - # Need at least `v1.17.0` for the `yaml-files` setting - - pip install --user yamllint>=1.17.0 - - yamllint -s . - # Install and run `rubocop` - - gem install rubocop - - rubocop -d - # Run `shellcheck` (already pre-installed in Travis) - - shellcheck --version - - git ls-files -- '*.sh' '*.bash' '*.ksh' - | xargs shellcheck - # Install and run `commitlint` - - npm i -D @commitlint/config-conventional - @commitlint/travis-cli - - commitlint-travis - - # Run `pre-commit` linters in a single job - - language: 'python' - env: 'Lint_pre-commit' - name: 'Lint: pre-commit' - before_install: 'skip' - cache: - directories: - - $HOME/.cache/pre-commit - script: - # Install and run `pre-commit` - - pip install pre-commit==2.7.1 - - pre-commit run --all-files --color always --verbose - - pre-commit run --color always --hook-stage manual --verbose commitlint-travis - - ## 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` - - env: INSTANCE=default-debian-10-master-py3 - - env: INSTANCE=default-ubuntu-2004-master-py3 - # - env: INSTANCE=default-ubuntu-1804-master-py3 - - env: INSTANCE=default-centos-8-master-py3 - - env: INSTANCE=default-fedora-32-master-py3 - # - env: INSTANCE=default-fedora-31-master-py3 - # - env: INSTANCE=default-opensuse-leap-152-master-py3 - # - env: INSTANCE=default-amazonlinux-2-master-py3 - # - env: INSTANCE=default-debian-10-3000-3-py3 - # - env: INSTANCE=default-debian-9-3000-3-py3 - # - env: INSTANCE=default-ubuntu-1804-3000-3-py3 - # - env: INSTANCE=default-centos-8-3000-3-py3 - # - env: INSTANCE=default-centos-7-3000-3-py3 - # - env: INSTANCE=default-fedora-31-3000-3-py3 - - env: INSTANCE=default-opensuse-leap-152-3000-3-py3 - - env: INSTANCE=default-amazonlinux-2-3000-3-py3 - # - env: INSTANCE=default-ubuntu-1804-3000-3-py2 - # - env: INSTANCE=default-ubuntu-1604-3000-3-py2 - # - env: INSTANCE=default-arch-base-latest-3000-3-py2 - # - env: INSTANCE=default-debian-10-2019-2-py3 - # - env: INSTANCE=default-debian-9-2019-2-py3 - # - env: INSTANCE=default-ubuntu-1804-2019-2-py3 - # - env: INSTANCE=default-ubuntu-1604-2019-2-py3 - # - env: INSTANCE=default-centos-8-2019-2-py3 - # - env: INSTANCE=default-centos-7-2019-2-py3 - # - env: INSTANCE=default-fedora-31-2019-2-py3 - # - env: INSTANCE=default-opensuse-leap-152-2019-2-py3 - # - env: INSTANCE=default-amazonlinux-2-2019-2-py3 - # - env: INSTANCE=default-centos-6-2019-2-py2 - # - env: INSTANCE=default-amazonlinux-1-2019-2-py2 - - env: INSTANCE=default-arch-base-latest-2019-2-py2 - - ## Define the release stage that runs `semantic-release` - - stage: 'release' - language: 'node_js' - node_js: 'lts/*' - env: 'Release' - name: 'Run semantic-release inc. file updates to AUTHORS, CHANGELOG & FORMULA' - before_install: 'skip' - script: - # Update `AUTHORS.md` - - export MAINTAINER_TOKEN=${GH_TOKEN} - - go get github.com/myii/maintainer - - maintainer contributor - - # Install all dependencies required for `semantic-release` - - npm i -D @semantic-release/changelog@3 - @semantic-release/exec@3 - @semantic-release/git@7 - deploy: - provider: 'script' - # Opt-in to `dpl v2` to complete the Travis build config validation (beta) - # * https://docs.travis-ci.com/user/build-config-validation - # Deprecated `skip_cleanup` can now be avoided, `cleanup: false` is by default - edge: true - # Run `semantic-release` - script: 'npx semantic-release@15.14' - -# Notification options: `always`, `never` or `change` -notifications: - webhooks: - if: 'repo = saltstack-formulas/consul-formula' - urls: - - https://saltstack-formulas.zulipchat.com/api/v1/external/travis?api_key=HsIq3o5QmLxdnVCKF9is0FUIpkpAY79P&stream=CI&topic=saltstack-formulas%2Fconsul-formula&ignore_pull_requests=true - on_success: always # default: always - on_failure: always # default: always - on_start: always # default: never - on_cancel: always # default: always - on_error: always # default: always diff --git a/.yamllint b/.yamllint index 740beca0..73bcbe2b 100644 --- a/.yamllint +++ b/.yamllint @@ -9,6 +9,7 @@ extends: default # 2. Any SLS files under directory `test/`, which are actually state files # 3. Any YAML files under directory `.kitchen/`, introduced during local testing ignore: | + .cache/ node_modules/ test/**/states/**/*.sls .kitchen/ diff --git a/CODEOWNERS b/CODEOWNERS index 2f235d68..7e6b4e21 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -25,6 +25,7 @@ /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 diff --git a/pre-commit_semantic-release.sh b/pre-commit_semantic-release.sh index ba805352..458b7b64 100755 --- a/pre-commit_semantic-release.sh +++ b/pre-commit_semantic-release.sh @@ -11,7 +11,7 @@ sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA ############################################################################### # Install `m2r` -sudo -H pip install m2r +pip3 install m2r # Copy and then convert the `.md` docs cp ./*.md docs/ diff --git a/release.config.js b/release.config.js index 6af7aa8f..93c27290 100644 --- a/release.config.js +++ b/release.config.js @@ -1,5 +1,6 @@ module.exports = { branch: 'master', + repositoryUrl: 'https://github.com/saltstack-formulas/consul-formula', plugins: [ ['@semantic-release/commit-analyzer', { preset: 'angular',