Skip to content

Commit

Permalink
👌 IMPROVE: Update to Github Actions (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell authored Mar 24, 2021
1 parent 921765a commit 0a1a0e4
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 102 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# use `# noqa xxx` at the end of a line, to ignore a particular error
# or add to the warn_list, to ignore for the whole project
warn_list: ['208']
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI

on:
push:
branches: [master]
tags:
- 'v*'
pull_request:

env:
galaxy-name: "marvel-nccr.cp2k"

jobs:

pre-commit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- uses: pre-commit/[email protected]

molecule:

strategy:
matrix:
distro: [ubuntu1604, ubuntu1804, ubuntu2004]
fail-fast: false

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v2
with:
path: ${{ env.galaxy-name }}

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Upgrade pip
run: |
pip install --upgrade pip
pip --version
- name: Install requirements
run: |
pip install wheel
pip install -r requirements.txt
working-directory: ${{ env.galaxy-name }}

- name: Run molecule
run: molecule test
working-directory: ${{ env.galaxy-name }}
env:
MOLECULE_DISTRO: ${{ matrix.distro }}

release:
name: Publish to ansible-galaxy
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
needs: [pre-commit, molecule]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: robertdebock/[email protected]
with:
galaxy_api_key: ${{ secrets.GALAXY_API_KEY }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.swp
.DS_Store
.galaxy_install_info
.vscode/
.tox/
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# For use with pre-commit.
# See usage instructions at https://pre-commit.com
repos:

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v1.5.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, "2", --preserve-quotes]

- repo: https://github.com/adrienverge/yamllint
rev: v1.25.0
hooks:
- id: yamllint

- repo: https://github.com/ansible/ansible-lint
rev: v4.3.5
hooks:
- id: ansible-lint
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .yamllint

This file was deleted.

9 changes: 9 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends: default
rules:
document-start: disable
line-length:
max: 200
level: warning
indentation:
spaces: 2
indent-sequences: false
52 changes: 43 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![Build Status](https://travis-ci.org/marvel-nccr/ansible-role-cp2k.svg?branch=master)](https://travis-ci.org/marvel-nccr/ansible-role-cp2k)
[![CI](https://github.com/marvel-nccr/ansible-role-cp2k/workflows/CI/badge.svg)](https://github.com/marvel-nccr/ansible-role-cp2k/actions)
[![Ansible Role](https://img.shields.io/ansible/role/25524.svg)](https://galaxy.ansible.com/marvel-nccr/cp2k)
[![Release](https://img.shields.io/github/tag/marvel-nccr/ansible-role-cp2k.svg)](https://github.com/marvel-nccr/ansible-role-cp2k/releases)

# Ansible Role: marvel-nccr.cp2k

Expand All @@ -14,22 +16,54 @@ See `defaults/main.yml`

## Example Playbook

```
- hosts: machines
```yaml
- hosts: servers
roles:
- role: nccr-marvel.slurm
- role: marvel-nccr.cp2k
```
## Development and testing
This role uses [Molecule](https://molecule.readthedocs.io/en/latest/#) and [Docker](https://www.docker.com/) for tests.
After installing [Docker](https://www.docker.com/):
Clone the repository into a package named `marvel-nccr.cp2k` (the folder must be named the same as the Ansible Galaxy name)

```bash
git clone https://github.com/marvel-nccr/ansible-role-cp2k marvel-nccr.cp2k
cd marvel-nccr.cp2k
```

Then run:

```bash
pip install -r requirements.txt # Installs molecule
molecule test # runs tests
```

## Tests
or use tox (see `tox.ini`):

This role uses [Molecule](https://molecule.readthedocs.io/en/latest/#) and
Docker for tests. Once Docker is installed, run tests using
```bash
pip install tox
tox
```

## Code style

Code style is formatted and linted with [pre-commit](https://pre-commit.com/).

```bash
pip install -r requirements.txt
molecule test
pip install pre-commit
pre-commit run -all
```

## Deployment

Deployment to Ansible Galaxy is automated *via* GitHub Actions.
Simply tag a release `vX.Y.Z` to initiate the CI and release workflow.
Note, the release will only complete if the CI tests pass.

## License

MIT
Expand Down
13 changes: 6 additions & 7 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
cp2k_version: "7.1"
cp2k_long_version: "v7.1.0"
cp2k_apt_version: "5.1-3"
Expand All @@ -12,12 +11,12 @@ cp2k_bin_dir: "{{ cp2k_prefix }}/bin"
cp2k_data_dir: "{{ cp2k_prefix }}/share/cp2k"

cp2k_executables:
- name: cp2k
executable: cp2k.ssmp
download: cp2k-{{ cp2k_version }}-Linux-x86_64.ssmp
folder: "{{ cp2k_bin_dir }}"
plugin: cp2k
version: "{{ cp2k_version }}"
- name: cp2k
executable: cp2k.ssmp
download: cp2k-{{ cp2k_version }}-Linux-x86_64.ssmp
folder: "{{ cp2k_bin_dir }}"
plugin: cp2k
version: "{{ cp2k_version }}"

# binary download
# cp2k_svn_url: "https://sourceforge.net/p/cp2k/code/HEAD/tree/branches/cp2k-6_1-branch/cp2k"
Expand Down
15 changes: 7 additions & 8 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
allow_duplicates: false

galaxy_info:
Expand All @@ -9,11 +8,11 @@ galaxy_info:
license: MIT
min_ansible_version: 2.7
platforms:
- name: Ubuntu
versions:
- xenial
- bionic
- name: Ubuntu
versions:
- xenial
- bionic
galaxy_tags:
- ubuntu
- application
- science
- ubuntu
- application
- science
15 changes: 7 additions & 8 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
---
- name: Converge
hosts: all

pre_tasks:
- name: Update apt cache.
become: true
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
- name: Update apt cache.
become: true
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'

vars:
- run_tests: true
- cloud_platform: docker
- run_tests: true
- cloud_platform: docker

roles:
- role: marvel-nccr.cp2k
- role: marvel-nccr.cp2k
32 changes: 20 additions & 12 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
---
dependency:
name: galaxy
# requirements_file: molecule/default/requirements.yml
driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint
platforms:
- name: instance
image: "${DOCKER_IMAGE:-marvelnccr/ubuntu-docker-base}:${DOCKER_IMAGE_VERSION:-latest}"
command: "${DOCKER_COMMAND:-sleep infinity}"
privileged: true
pre_build_image: true
- name: instance
image: "marvelnccr/docker-${MOLECULE_DISTRO:-ubuntu1804}-ansible:latest"
# by default the container will initialise with systemd as PID1
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
env:
LC_ALL: "en_US.UTF-8"
LANG: "en_US.UTF-8"
provisioner:
name: ansible
options:
v: true
# log: true # use for debugging
playbooks:
converge: converge.yml
config_options:
defaults:
# nicer stdout printing
stdout_callback: yaml
bin_ansible_callbacks: true
# add timing to tasks
callback_whitelist: profile_tasks
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
molecule~=3.0
docker
yamllint
ansible-lint
# for running
ansible~=2.10.0
# for testing
molecule[docker]~=3.1.0
docker~=4.2
17 changes: 8 additions & 9 deletions tasks/download_binary.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
---
- name: install required packages
become: true
apt:
name:
- bzip2
- bzip2

- name: make cp2k directories
become: true
file:
dest: "{{ item }}"
state: directory
with_items:
- "{{ cp2k_bin_dir }}"
- "{{ cp2k_data_dir }}"
- "{{ cp2k_bin_dir }}"
- "{{ cp2k_data_dir }}"

- name: download cp2k binary
become: true
Expand All @@ -37,18 +36,18 @@
# with the default timeout of 10s
timeout: 30
with_items:
- BASIS_MOLOPT
- POTENTIAL
- ALL_BASIS_SETS
- ALL_POTENTIALS
- BASIS_MOLOPT
- POTENTIAL
- ALL_BASIS_SETS
- ALL_POTENTIALS

- name: download copyright notice
become: true
get_url:
url: "{{ cp2k_git_url }}/{{ item }}"
dest: "{{ cp2k_data_dir }}"
with_items:
- COPYRIGHT
- COPYRIGHT

- name: "Add CP2K_DATA_DIR environment variable"
become: true
Expand Down
Loading

0 comments on commit 0a1a0e4

Please sign in to comment.