From c14f0dd9a328267f610ec324343287dc9ad4ed23 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Mon, 9 Nov 2020 17:04:42 -0600 Subject: [PATCH] Fix lint issues and dump Travis CI. Try out GitHub Actions instead. --- .github/FUNDING.yml | 2 +- .github/workflows/ci.yml | 77 +++++++++++++++++++++++++++++++++++++ .yamllint | 10 +++++ README.md | 5 ++- default.config.yml | 34 ++++++++-------- tasks/ansible-setup.yml | 2 +- tasks/extra-packages.yml | 4 +- tasks/sudoers.yml | 2 +- tasks/terminal.yml | 2 +- tests/ansible.cfg | 3 ++ tests/config.yml | 1 + tests/inventory | 2 + tests/uninstall-homebrew.sh | 13 +++++++ 13 files changed, 133 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .yamllint create mode 100644 tests/ansible.cfg create mode 100644 tests/inventory create mode 100755 tests/uninstall-homebrew.sh diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index af7a1e0..96b4938 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,4 @@ # These are supported funding model platforms - +--- github: geerlingguy patreon: geerlingguy diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a86f458 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +--- +name: CI +'on': + pull_request: + push: + branches: + - master + schedule: + - cron: "0 5 * * 4" + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install yamllint ansible-lint + + - name: Lint code. + run: | + yamllint . + ansible-lint + + integration: + name: Integration + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - macos-10.15 + + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + + - name: Uninstall GitHub Actions' built-in Homebrew. + run: tests/uninstall-homebrew.sh + + - name: Uninstall GitHub Actions' built-in browser installs. + run: | + sudo rm -rf /Applications/Firefox.app + sudo rm -rf /Applications/Google\ Chrome.app + + - name: Install test dependencies. + run: sudo pip3 install ansible + + - name: Set up the test environment. + run: | + cp tests/ansible.cfg ./ansible.cfg + cp tests/inventory ./inventory + cp tests/config.yml ./config.yml + ansible-galaxy install -r requirements.yml -p ./roles + + - name: Test the playbook's syntax. + run: ansible-playbook tests/test.yml --syntax-check + + - name: Test the playbook. + run: ansible-playbook tests/test.yml + env: + ANSIBLE_FORCE_COLOR: '1' + + - name: Idempotence check. + run: | + idempotence=$(mktemp) + ansible-playbook tests/test.yml | tee -a ${idempotence} + tail ${idempotence} | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) + env: + ANSIBLE_FORCE_COLOR: '1' diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..84ecaec --- /dev/null +++ b/.yamllint @@ -0,0 +1,10 @@ +--- +extends: default + +rules: + line-length: + max: 180 + level: warning + +ignore: | + .github/stale.yml diff --git a/README.md b/README.md index 28499a6..b7d6eea 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Mac Development Ansible Playbook -[![Build Status](https://travis-ci.org/geerlingguy/mac-dev-playbook.svg?branch=master)](https://travis-ci.org/geerlingguy/mac-dev-playbook) +[![CI][badge-gh-actions]][link-gh-actions] This playbook installs and configures most of the software I use on my Mac for web and software development. Some things in macOS are slightly difficult to automate, so I still have some manual installation steps, but at least it's all documented here. @@ -177,3 +177,6 @@ Check out [Ansible for DevOps](https://www.ansiblefordevops.com/), which teaches ## Author [Jeff Geerling](https://www.jeffgeerling.com/), 2014 (originally inspired by [MWGriffin/ansible-playbooks](https://github.com/MWGriffin/ansible-playbooks)). + +[badge-gh-actions]: https://github.com/geerlingguy/mac-dev-playbook/workflows/CI/badge.svg?event=push +[link-gh-actions]: https://github.com/geerlingguy/mac-dev-playbook/actions?query=workflow%3ACI diff --git a/default.config.yml b/default.config.yml index f4768e4..38ff438 100644 --- a/default.config.yml +++ b/default.config.yml @@ -1,11 +1,11 @@ --- downloads: ~/.ansible-downloads/ -configure_dotfiles: yes -configure_terminal: yes -configure_osx: yes +configure_dotfiles: true +configure_terminal: true +configure_osx: true -configure_sudoers: no +configure_sudoers: false sudoers_custom_config: '' # Example: # sudoers_custom_config: | @@ -13,7 +13,7 @@ sudoers_custom_config: '' # %admin ALL=(ALL) NOPASSWD: ALL dotfiles_repo: https://github.com/geerlingguy/dotfiles.git -dotfiles_repo_accept_hostkey: yes +dotfiles_repo_accept_hostkey: true dotfiles_repo_local_destination: ~/Development/GitHub/dotfiles dotfiles_files: - .zshrc @@ -80,21 +80,21 @@ osx_script: "~/.osx --no-restart" # Note: You are responsible for making sure the required package managers are # installed, eg. through homebrew. composer_packages: [] - # - name: drush - # state: present # present/absent, default: present - # version: "^8.1" # default: N/A +# - name: drush +# state: present # present/absent, default: present +# version: "^8.1" # default: N/A gem_packages: [] - # - name: bundler - # state: present # present/absent/latest, default: present - # version: "~> 1.15.1" # default: N/A +# - name: bundler +# state: present # present/absent/latest, default: present +# version: "~> 1.15.1" # default: N/A npm_packages: [] - # - name: webpack - # state: present # present/absent/latest, default: present - # version: "^2.6" # default: N/A +# - name: webpack +# state: present # present/absent/latest, default: present +# version: "^2.6" # default: N/A pip_packages: [] - # - name: mkdocs - # state: present # present/absent/latest, default: present - # version: "0.16.3" # default: N/A +# - name: mkdocs +# state: present # present/absent/latest, default: present +# version: "0.16.3" # default: N/A # Glob pattern to ansible task files to run after all other tasks are finished. post_provision_tasks: [] diff --git a/tasks/ansible-setup.yml b/tasks/ansible-setup.yml index efa9508..d474b4a 100644 --- a/tasks/ansible-setup.yml +++ b/tasks/ansible-setup.yml @@ -8,7 +8,7 @@ file: path: /etc/ansible state: directory - become: yes + become: true - name: Symlink /usr/local/etc/ansible to /etc/ansible. file: diff --git a/tasks/extra-packages.yml b/tasks/extra-packages.yml index ee9254c..643cd41 100644 --- a/tasks/extra-packages.yml +++ b/tasks/extra-packages.yml @@ -12,7 +12,7 @@ name: "{{ item.name | default(item) }}" state: "{{ item.state | default('present') }}" version: "{{ item.version | default(omit) }}" - global: yes + global: true executable: "{{ item.executable | default(omit) }}" with_items: "{{ npm_packages }}" @@ -29,6 +29,6 @@ name: "{{ item.name | default(item) }}" state: "{{ item.state | default('present') }}" version: "{{ item.version | default(omit) }}" - user_install: no + user_install: false executable: "{{ item.executable | default(omit) }}" with_items: "{{ gem_packages }}" diff --git a/tasks/sudoers.yml b/tasks/sudoers.yml index 34894af..55cf05c 100644 --- a/tasks/sudoers.yml +++ b/tasks/sudoers.yml @@ -18,4 +18,4 @@ dest: /private/etc/sudoers.d/custom mode: 0440 validate: 'visudo -cf %s' - become: yes + become: true diff --git a/tasks/terminal.yml b/tasks/terminal.yml index 278450d..618faf6 100644 --- a/tasks/terminal.yml +++ b/tasks/terminal.yml @@ -4,7 +4,7 @@ shell: defaults read com.apple.terminal 'Default Window Settings' register: terminal_theme changed_when: false - check_mode: no + check_mode: false - name: Ensure custom Terminal profile is added. shell: open files/terminal/JJG-Term.terminal diff --git a/tests/ansible.cfg b/tests/ansible.cfg new file mode 100644 index 0000000..6c19e9a --- /dev/null +++ b/tests/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +inventory = inventory +roles_path = ../:../roles:./roles diff --git a/tests/config.yml b/tests/config.yml index fefa4b3..e95fb92 100644 --- a/tests/config.yml +++ b/tests/config.yml @@ -1,3 +1,4 @@ +--- homebrew_installed_packages: - autoconf - bash-completion diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..13cfabe --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +[local] +localhost ansible_connection=local diff --git a/tests/uninstall-homebrew.sh b/tests/uninstall-homebrew.sh new file mode 100755 index 0000000..d6d4c96 --- /dev/null +++ b/tests/uninstall-homebrew.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Uninstalls Homebrew using the official uninstall script. + +# Download and run the uninstall script. +curl -sLO https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh +chmod +x ./uninstall.sh +sudo ./uninstall.sh --force + +# Clean up Homebrew directories. +sudo rm -rf /usr/local/Homebrew +sudo rm -rf /usr/local/Caskroom +sudo rm -rf /usr/local/bin/brew