From 7c515446518fa2b6b60686d0c103ed42483e978e Mon Sep 17 00:00:00 2001 From: jgoutin Date: Wed, 30 Jun 2021 10:33:21 +0200 Subject: [PATCH] Migrate from Travis --- .ansible-lint | 1 + .flake8 | 4 + .travis.yml | 13 ---- .yamllint.yaml | 4 + README.md | 2 +- azure-pipelines.yml | 100 +++++++++++++++++++++++++ molecule/default/tests/test_default.py | 21 +++--- 7 files changed, 122 insertions(+), 23 deletions(-) create mode 100644 .flake8 delete mode 100644 .travis.yml create mode 100644 .yamllint.yaml create mode 100644 azure-pipelines.yml diff --git a/.ansible-lint b/.ansible-lint index 670d097..cbbea21 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,2 +1,3 @@ +--- skip_list: - '304' # Detect CMake option "-DPYTHON3=ON" and environment variable. diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..0f47db6 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +filename = *.py,src/ +max-line-length = 88 +extend-ignore = E203, E402 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a8e90fa..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -sudo: required -language: python -services: docker - -install: - - pip install ansible molecule[docker] testinfra yamllint ansible-lint - -script: - - molecule test - -notifications: - webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..cc55376 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,4 @@ +--- +extends: default +rules: + line-length: disable diff --git a/README.md b/README.md index 26728c9..5c782a5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/Accelize/ansible-role-accelize-drm.svg?branch=master)](https://travis-ci.org/Accelize/ansible-role-ansible-drm) +[![Build Status](https://dev.azure.com/Accelize/DRM/_apis/build/status/Ansible%20-%20Accelize%20DRM?branchName=master)](https://dev.azure.com/Accelize/DRM/_build/latest?definitionId=27&branchName=master) Accelize DRM Ansible Role ========================= diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..967e784 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,100 @@ +--- +name: Ansible Role Accelize DRM + +trigger: + batch: true + branches: + include: + - master + tags: + include: + - "*" + paths: + exclude: + - "*.md" + - ".gitignore" + - "LICENSE" + +pr: none + +pool: + vmImage: ubuntu-20.04 + +jobs: + - job: tests + displayName: Tests + variables: + cacheDir: /tmp/.pipeline_cache + steps: + + - checkout: self + fetchDepth: 1 + path: ansible-role-accelize-drm # Must match role name in molecule/converge.yml + + - task: Cache@2 + inputs: + key: cache + path: $(cacheDir) + displayName: Cache packages + + - script: | + echo "##vso[task.prependpath]$HOME/.local/bin" + pip install --disable-pip-version-check --cache-dir $(cacheDir)/.pip_packages -U ansible flake8 yamllint ansible-lint black bandit molecule-docker pytest-testinfra + displayName: Get dependencies + condition: always() + + - script: flake8 + displayName: Lint Python modules + condition: always() + + - script: black . --check --diff + displayName: Check black style is applied + condition: always() + + - script: bandit -r . -x ./molecule + displayName: Check Python security + condition: always() + + - script: yamllint -s . + displayName: Lint YAML files + condition: always() + + - script: ansible-lint . + displayName: Lint Ansible configuration + condition: always() + + - script: molecule test + displayName: Test Ansible role + condition: always() + env: + ANSIBLE_STDOUT_CALLBACK: debug + ANSIBLE_FORCE_COLOR: "True" + ANSIBLE_NOCOLOR": "False" + + - job: + displayName: Ansible Galaxy publish + dependsOn: tests + condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags'), ne(variables['Build.Reason'], 'Schedule')) + variables: + - group: ansibleGalaxy + steps: + + - checkout: none + + - script: ansible-galaxy role import --token $(AnsibleGalaxyToken) --role-name accelize.accelize_drm Accelize ansible-role-accelize-drm + displayName: Publish role to Ansible Galaxy + + - task: GitHubRelease@1 + displayName: Publish GitHub release + inputs: + gitHubConnection: Accelize-application + repositoryName: $(Build.Repository.Name) + action: create + target: $(Build.SourceVersion) + tagSource: gitTag + tagPattern: '[0-9]+\.[0-9]+\.[0-9]+' + isPreRelease: contains($(libraryVersion.version), '-') + releaseNotesSource: inline + releaseNotesInline: Role Available on Ansible galaxy. + changeLogCompareToRelease: lastFullRelease + changeLogType: commitBased diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 7932a87..fb9593c 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -5,16 +5,18 @@ import testinfra.utils.ansible_runner testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("all") def test_packages_installed(host): """ Test that packages are installed """ - if (host.ansible.get_variables().get('accelize_drm_no_install') or - host.ansible.get_variables().get('accelize_drm_from_source')): - pytest.skip('No packages installed') + if host.ansible.get_variables().get( + "accelize_drm_no_install" + ) or host.ansible.get_variables().get("accelize_drm_from_source"): + pytest.skip("No packages installed") assert host.package("libaccelize-drm").is_installed @@ -23,9 +25,10 @@ def test_include_installed(host): """ Test that includes are installed """ - if (not host.ansible.get_variables().get('accelize_drm_devel') and - not host.ansible.get_variables().get('accelize_drm_from_source')): - pytest.skip('No headers installed') + if not host.ansible.get_variables().get( + "accelize_drm_devel" + ) and not host.ansible.get_variables().get("accelize_drm_from_source"): + pytest.skip("No headers installed") assert host.file("/usr/include/accelize/drm.h").exists @@ -34,5 +37,5 @@ def test_library_configuration_installed(host): """ Test that library configuration files are installed """ - assert host.file('/root/.accelize_drm/cred.json').exists - assert host.file('/etc/accelize_drm/conf.json').exists + assert host.file("/root/.accelize_drm/cred.json").exists + assert host.file("/etc/accelize_drm/conf.json").exists