diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7d3000d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,93 @@ +--- +name: CI + +env: + ROLE_NAME: wcm_io_devops.jenkins_configuration_as_code + +defaults: + run: + working-directory: 'wcm_io_devops.jenkins_configuration_as_code' + +'on': + pull_request: + push: + branches: + - master + +jobs: + + lint: + name: "Lint (${{ matrix.NAME }})" + runs-on: ubuntu-latest + strategy: + matrix: + include: + - NAME: min_ansible_version + ANSIBLE_VERSION: "==2.7.*" + ANSIBLE_LINT_VERSION: "==4.2.*" + - NAME: latest + ANSIBLE_VERSION: "" + ANSIBLE_LINT_VERSION: "" + + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + with: + path: '${{ env.ROLE_NAME }}' + + - name: Cache PIP + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ matrix.ANSIBLE_VERSION }}-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip-${{ matrix.ANSIBLE_VERSION }}- + + - name: Create ansible.cfg + run: "printf '[defaults]\nroles_path=./tests/requirements/:../' > ansible.cfg" + + - name: Install role requirements + uses: BSFishy/pip-action@v1 + with: + requirements: "${{ env.ROLE_NAME }}/requirements.txt" + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install pip tools. + run: | + pip3 install wheel --upgrade + + - name: Install test dependencies. + run: > + pip3 install yamllint + ansible${{ matrix.ANSIBLE_VERSION }} + ansible-lint${{ matrix.ANSIBLE_LINT_VERSION }} + --upgrade + + - name: Install Galaxy requirements. + run: | + ansible-galaxy install -r tests/requirements.yml -p ./tests/requirements + + - name: Lint code. + run: | + yamllint . + ansible-lint + + - name: Test syntax. + run: | + ansible-playbook tests/test.yml -i tests/inventory --syntax-check + + galaxy: + name: "Ansible Galaxy import" + needs: + - lint + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + steps: + - name: Trigger a new import on Galaxy. + uses: robertdebock/galaxy-action@affc5472cd0b08f64a51eafba49b08898c1bbeb8 + with: + galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..769d40c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,18 @@ +--- +name: Release + +'on': + release: + types: + - published + +jobs: + + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Trigger a new import on Galaxy. + uses: robertdebock/galaxy-action@affc5472cd0b08f64a51eafba49b08898c1bbeb8 + with: + galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 00bccb2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -language: python -cache: pip -python: "3.7" -env: - # run against latest version - - ANSIBLE_VERSION=latest - # run against minimal required version - - ANSIBLE_VERSION=2.7.* ANSIBLE_LINT_VERSION=4.2.* - -# Use the new container infrastructure -sudo: false - -# Install pip -addons: - apt: - packages: - - python-pip - -install: - # Install ansible and dependencies - - if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible ansible-lint --upgrade; else pip install ansible=="$ANSIBLE_VERSION" ansible-lint=="$ANSIBLE_LINT_VERSION" --upgrade; fi - - # Check ansible version - - ansible --version - - # Create ansible.cfg with correct roles_path - - printf '[defaults]\nroles_path=./tests/requirements/:../' > ansible.cfg - -script: - # Install requirements - - ansible-galaxy install -r tests/requirements.yml -p ./tests/requirements - - # Run ansible-lint - - ansible-lint . - - # Basic role syntax check - - ansible-playbook tests/test.yml -i tests/inventory --syntax-check - -notifications: - webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..207a3a9 --- /dev/null +++ b/.yamllint @@ -0,0 +1,13 @@ +--- +extends: default + +rules: + line-length: + max: 120 + level: warning + truthy: + allowed-values: ['true', 'false', 'yes', 'no'] + +ignore: | + .travis.yml + tests/requirements/ diff --git a/README.md b/README.md index 8e96239..3989b35 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/wcm-io-devops/ansible-jenkins-configuration-as-code.svg?branch=master)](https://travis-ci.com/wcm-io-devops/ansible-jenkins-configuration-as-code) +[![CI](https://github.com/wcm-io-devops/ansible-jenkins-configuration-as-code/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/wcm-io-devops/ansible-jenkins-configuration-as-code/actions?query=workflow%3ACI) # wcm_io_devops.jenkins_configuration_as_code diff --git a/defaults/main.yml b/defaults/main.yml index baf6958..b8ac86a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,4 @@ +--- # Jenkins admin username jenkins_casc_admin_username: admin @@ -52,4 +53,4 @@ jenkins_casc_plugins_present: # Plugins no longer needed for configuration-as-code jenkins_casc_plugins_absent: - - name: configuration-as-code-support \ No newline at end of file + - name: configuration-as-code-support diff --git a/handlers/main.yml b/handlers/main.yml index 6ac176b..f0e9ae6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,3 @@ +--- - name: wcm_io_devops.jenkins_configuration_as_code reload include_tasks: reload.yml diff --git a/meta/main.yml b/meta/main.yml index c3bd015..3b0066d 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,3 +1,4 @@ +--- galaxy_info: role_name: jenkins_configuration_as_code author: Tobias Richter @@ -8,18 +9,18 @@ galaxy_info: min_ansible_version: 2.7 platforms: - - name: EL - versions: - - all - - name: Debian - versions: - - all - - name: Ubuntu - versions: - - all - - name: GenericLinux - versions: - - all + - name: EL + versions: + - all + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - all + - name: GenericLinux + versions: + - all galaxy_tags: - wcmio @@ -29,18 +30,16 @@ galaxy_info: dependencies: # install plugins - - { role: wcm_io_devops.jenkins_plugins, - version: 1.5.0, - jenkins_plugins_admin_username: "{{ jenkins_casc_admin_username }}", - jenkins_plugins_admin_password: "{{ jenkins_casc_admin_password }}", - jenkins_plugins_jenkins_hostname: "{{ jenkins_casc_jenkins_hostname }}", - jenkins_plugins_jenkins_port: "{{ jenkins_casc_jenkins_port }}", - jenkins_plugins_jenkins_home: "{{ jenkins_casc_jenkins_home }}", - jenkins_plugins_jenkins_url_prefix: "{{ jenkins_casc_jenkins_url_prefix }}", - jenkins_plugins_present: "{{ jenkins_casc_plugins_present }}", - tags: [ - "dependency", - "jenkins_configuration_as_code_plugins", - "wcm_io_devops.jenkins_plugins" - ] - } + - role: wcm_io_devops.jenkins_plugins + version: 1.5.0 + jenkins_plugins_admin_username: "{{ jenkins_casc_admin_username }}" + jenkins_plugins_admin_password: "{{ jenkins_casc_admin_password }}" + jenkins_plugins_jenkins_hostname: "{{ jenkins_casc_jenkins_hostname }}" + jenkins_plugins_jenkins_port: "{{ jenkins_casc_jenkins_port }}" + jenkins_plugins_jenkins_home: "{{ jenkins_casc_jenkins_home }}" + jenkins_plugins_jenkins_url_prefix: "{{ jenkins_casc_jenkins_url_prefix }}" + jenkins_plugins_present: "{{ jenkins_casc_plugins_present }}" + tags: + - "dependency" + - "jenkins_configuration_as_code_plugins" + - "wcm_io_devops.jenkins_plugins" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..08e19e4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +# This role needs to have the following PIP components installed \ No newline at end of file diff --git a/tasks/configure.yml b/tasks/configure.yml index ab7612b..a004a3e 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,3 +1,4 @@ +--- - name: "configure : check if '{{ jenkins_casc_config_path }}' exists." stat: path: "{{ jenkins_casc_config_path }}" diff --git a/tasks/main.yml b/tasks/main.yml index 7c5ebb4..2fb15f7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,3 +1,4 @@ +--- - include_tasks: upload.yml tags: - jcasc-upload diff --git a/tasks/reload.yml b/tasks/reload.yml index 242caa8..0af95b2 100644 --- a/tasks/reload.yml +++ b/tasks/reload.yml @@ -1,3 +1,4 @@ +--- - name: "reload : reload Jenkins configuration as code configuration." jenkins_script: script: "{{ lookup('file', 'files/groovy/jcasc/reload.groovy') }}" diff --git a/tasks/upload.yml b/tasks/upload.yml index f173ba0..612c2f5 100644 --- a/tasks/upload.yml +++ b/tasks/upload.yml @@ -1,3 +1,4 @@ +--- - name: "upload : calculate files to upload order to check that no files exist with overlapping names." set_fact: _jenkins_casc_found_config_files: "{{ _jenkins_casc_found_config_files | default([]) + [item] }}" diff --git a/tests/requirements.yml b/tests/requirements.yml index a2b1ef1..18857a3 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -1,2 +1,3 @@ +--- - name: wcm_io_devops.jenkins_plugins version: master diff --git a/tests/test.yml b/tests/test.yml index b08c675..fcb3eae 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,4 +1,5 @@ +--- - name: test role syntax hosts: test roles: - - ansible-jenkins-configuration-as-code + - wcm_io_devops.jenkins_configuration_as_code