Skip to content

Commit

Permalink
Merge pull request #37 from noelmcloughlin/cleanup
Browse files Browse the repository at this point in the history
feat(macos): add homebrew support & tidyup stuff
  • Loading branch information
noelmcloughlin authored Jun 3, 2020
2 parents 5aa5afb + 074072c commit e926a71
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 188 deletions.
63 changes: 26 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ stages:
- name: 'release'
if: 'branch = master AND type != pull_request'
jobs:
allow_failures:
- env: Lint_rubocop
fast_finish: true
include:
## Define the test stage that runs the linters (and testing matrix, if applicable)

# Run all of the linters in a single job (except `rubocop`)
# Run all of the linters in a single job
- language: 'node_js'
node_js: 'lts/*'
env: 'Lint'
name: 'Lint: salt-lint, yamllint, shellcheck & commitlint'
name: 'Lint: salt-lint, yamllint, rubocop, shellcheck & commitlint'
before_install: 'skip'
script:
# Install and run `salt-lint`
Expand All @@ -46,6 +43,9 @@ jobs:
# 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'
Expand All @@ -54,50 +54,39 @@ jobs:
- npm i -D @commitlint/config-conventional
@commitlint/travis-cli
- commitlint-travis
# Run the `rubocop` linter in a separate job that is allowed to fail
# Once these lint errors are fixed, this can be merged into a single job
- language: node_js
node_js: lts/*
env: Lint_rubocop
name: 'Lint: rubocop'
before_install: skip
script:
# Install and run `rubocop`
- gem install rubocop
- rubocop -d

## 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-1804-master-py3
# - env: INSTANCE=default-centos-8-master-py3
# - env: INSTANCE=default-fedora-31-master-py3
# - env: INSTANCE=default-opensuse-leap-151-master-py3
- env: INSTANCE=default-centos-8-master-py3
- env: INSTANCE=default-fedora-31-master-py3
- env: INSTANCE=default-opensuse-leap-151-master-py3
# - env: INSTANCE=default-amazonlinux-2-master-py3
# - env: INSTANCE=default-debian-10-3000-2-py3
# - env: INSTANCE=default-debian-9-3000-2-py3
# - env: INSTANCE=default-ubuntu-1804-3000-2-py3
# - env: INSTANCE=default-centos-8-3000-2-py3
# - env: INSTANCE=default-centos-7-3000-2-py3
# - env: INSTANCE=default-fedora-31-3000-2-py3
# - env: INSTANCE=default-opensuse-leap-151-3000-2-py3
# - env: INSTANCE=default-amazonlinux-2-3000-2-py3
# - env: INSTANCE=default-ubuntu-1804-3000-2-py2
# - env: INSTANCE=default-ubuntu-1604-3000-2-py2
# - env: INSTANCE=arch-arch-base-latest-3000-2-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-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-151-2019-2-py3
# - env: INSTANCE=default-centos-7-2019-2-py2
- env: INSTANCE=default-amazonlinux-2-2019-2-py3
# - env: INSTANCE=default-arch-base-latest-2019-2-py2
- env: INSTANCE=default-fedora-30-2018-3-py3
- env: INSTANCE=default-debian-9-2018-3-py2
# - env: INSTANCE=default-ubuntu-1604-2018-3-py2
# - env: INSTANCE=default-centos-7-2018-3-py2
# - env: INSTANCE=default-opensuse-leap-151-2018-3-py2
# - env: INSTANCE=default-amazonlinux-1-2018-3-py2
# - env: INSTANCE=default-arch-base-latest-2018-3-py2
# - env: INSTANCE=default-debian-8-2017-7-py2
# - env: INSTANCE=default-ubuntu-1604-2017-7-py2
- env: INSTANCE=default-centos-6-2017-7-py2
# - env: INSTANCE=default-fedora-30-2017-7-py2
# - env: INSTANCE=default-opensuse-leap-151-2017-7-py2
# - env: INSTANCE=default-amazonlinux-1-2017-7-py2
# - env: INSTANCE=default-arch-base-latest-2017-7-py2
# - 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=arch-arch-base-latest-2019-2-py2

## Define the release stage that runs `semantic-release`
- stage: 'release'
Expand Down
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ignore: |
node_modules/
test/**/states/**/*.sls
.kitchen/
golang/osfamilymap.yaml
yaml-files:
# Default settings
Expand Down
6 changes: 1 addition & 5 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners

# SECTION: Owner(s) for everything in the repo, unless a later match takes precedence
# **************************************************************************
# *** NO GLOBAL OWNER(S) SPECIFIED ***
# *** Ideally this will be defined for a healthy, well-maintained repo ***
# **************************************************************************
# FILE PATTERN OWNER(S)
* @NONE
* @noelmcloughlin

# SECTION: Owner(s) for specific directories
# FILE PATTERN OWNER(S)
Expand Down
6 changes: 3 additions & 3 deletions FORMULA
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: golang
os: Debian, Ubuntu, Raspbian, RedHat, Fedora, CentOS, Suse, openSUSE, Gentoo, Funtoo, Arch, Manjaro, Alpine, FreeBSD, OpenBSD, Solaris, SmartOS, Windows, MacOS
os: Debian, Ubuntu, Raspbian, RedHat, Fedora, CentOS, Amazon, Suse, openSUSE, Gentoo, Funtoo, Arch, Manjaro, Alpine, FreeBSD, OpenBSD, Solaris, SmartOS, Windows, MacOS
os_family: Debian, RedHat, Suse, Gentoo, Arch, Alpine, FreeBSD, OpenBSD, Solaris, Windows, MacOS
version: 0.6.5
release: 1
minimum_version: 2016.11
minimum_version: 2019.2
summary: golang formula
description: Formula for golang
description: Formula to install golang and configure it
top_level_dir: golang
5 changes: 3 additions & 2 deletions golang/archive/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
golang-cli-package-archive-clean-file-absent:
file.absent:
- names:
- {{ golang.pkg.archive.name }}/go
- {{ golang.pkg.archive.name }}
- /usr/local/go
{%- if golang.kernel == 'linux' %}
- {{ golang.linux.base_dir }}
- {{ golang.path }}
{%- endif %}
17 changes: 12 additions & 5 deletions golang/archive/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ golang-package-archive-install-file-directory:
golang-package-archive-install-archive-extracted:
archive.extracted:
{{- format_kwargs(golang.pkg.archive) }}
- retry:
attempts: 3
until: True
interval: 60
splay: 10
- retry: {{ golang.retry_option }}
- user: {{ golang.rootuser }}
- group: {{ golang.rootgroup }}
{%- if golang.linux.altpriority|int == 0 or grains.os_family in ('Arch', 'MacOS',) %}
golang-archive-install-file-symlink-golang:
file.symlink:
- name: /usr/local/bin/go
- target: {{ golang.path }}/{{ golang.command }}
- force: True
- onlyif: test -f {{ golang.path }}/{{ golang.command }}
{%- endif %}
4 changes: 2 additions & 2 deletions golang/config/alternatives/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include:
golang-package-archive-remove-home-alternative-remove:
alternatives.remove:
- name: golang-home
- path: {{ golang.linux.base_dir }}/go
- path: {{ golang.path }}/go
- onlyif: update-alternatives --get-selections |grep ^golang-home
- require:
- sls: {{ sls_archive_clean if golang.pkg.use_upstream_archive else sls_package_clean }}
Expand All @@ -25,7 +25,7 @@ golang-package-archive-remove-home-alternative-remove:
golang-package-archive-remove-{{ i }}-alternative-remove:
alternatives.remove:
- name: link-{{ i }}
- path: {{ golang.linux.base_dir }}/go/bin/{{ i }}
- path: {{ golang.path }}/go/bin/{{ i }}
- onlyif: update-alternatives --get-selections |grep ^link-{{ i }}
- require:
- sls: {{ sls_archive_clean if golang.pkg.use_upstream_archive else sls_package_clean }}
Expand Down
12 changes: 6 additions & 6 deletions golang/config/alternatives/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include:
golang-package-archive-install-home-alternative-install:
cmd.run:
- name: update-alternatives --install {{ golang.linux.dir }} golang-home {{ golang.linux.base_dir }}/go {{ golang.linux.altpriority }}
- name: update-alternatives --install {{ golang.linux.dir }} golang-home {{ golang.path }}/go {{ golang.linux.altpriority }}
- watch:
- archive: golang-package-archive-install-archive-extracted
- require:
Expand All @@ -24,7 +24,7 @@ golang-package-archive-install-home-alternative-install:
alternatives.install:
- name: golang-home
- link: {{ golang.linux.dir }}
- path: {{ golang.linux.base_dir }}/go
- path: {{ golang.path }}/go
- priority: {{ golang.linux.altpriority }}
- order: 10
- watch:
Expand All @@ -36,7 +36,7 @@ golang-package-archive-install-home-alternative-install:
golang-package-archive-install-home-alternative-set:
alternatives.set:
- name: golang-home
- path: {{ golang.linux.base_dir }}/go
- path: {{ golang.path }}/go
- require:
- alternatives: golang-package-archive-install-home-alternative-install
- unless: {{ grains.os_family in ('Suse',) }}
Expand All @@ -45,14 +45,14 @@ golang-package-archive-install-home-alternative-set:
golang-package-archive-install-{{ i }}-alternative-install:
cmd.run:
- name: update-alternatives --install /usr/bin/{{ i }} link-{{ i }} {{ golang.linux.base_dir }}/go/bin/{{ i }} {{ golang.linux.altpriority }}
- name: update-alternatives --install /usr/bin/{{ i }} link-{{ i }} {{ golang.path }}/go/bin/{{ i }} {{ golang.linux.altpriority }}
- require:
- cmd: golang-package-archive-install-home-alternative-install
- onlyif: {{ grains.os_family in ('Suse',) }}
alternatives.install:
- name: link-{{ i }}
- link: /usr/bin/{{ i }}
- path: {{ golang.linux.base_dir }}/go/bin/{{ i }}
- path: {{ golang.path }}/go/bin/{{ i }}
- priority: {{ golang.linux.altpriority }}
- order: 10
- require:
Expand All @@ -62,7 +62,7 @@ golang-package-archive-install-{{ i }}-alternative-install:
golang-package-archive-install-{{ i }}-alternative-set:
alternatives.set:
- name: link-{{ i }}
- path: {{ golang.linux.base_dir }}/go/bin/{{ i }}
- path: {{ golang.path }}/go/bin/{{ i }}
- require:
- alternatives: golang-package-archive-install-{{ i }}-alternative-install
- unless: {{ grains.os_family in ('Suse',) }}
Expand Down
4 changes: 2 additions & 2 deletions golang/config/environ.sls
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ golang-config-file-managed-environ_file:
golang-config-file-symlink-{{ i }}-golang-binary:
file.symlink:
- name: /usr/local/bin/{{ i }}
- target: {{ golang.linux.base_dir }}/ {{ i }}
- target: {{ golang.path }}/ {{ i }}
- mode: '0755'
- force: True
- onlyif:
- {{ grains.os_family in ('Arch', 'FreeBSD', 'MacOS') }}
- test -x {{ golang.linux.base_dir }}/ {{ i }}
- test -x {{ golang.path }}/ {{ i }}
{%- endfor %}
8 changes: 8 additions & 0 deletions golang/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ golang:
go_path: /usr/local/golang/packages # non-default GOPATH
rootuser: root
rootgroup: root
command: go/bin/go
pkg:
name: go
use_upstream_repo: false
Expand Down Expand Up @@ -42,3 +43,10 @@ golang:
cmd:
goget: []
clean: []

retry_option:
# https://docs.saltstack.com/en/latest/ref/states/requisites.html#retrying-states
attempts: 2
until: true
interval: 10
splay: 10
2 changes: 1 addition & 1 deletion golang/files/default/golang.sh.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
##portable shell syntax

[ -n "${GOROOT}" ] && export GOROOT=${GOROOT}
[ -n "{{ golang.linux.base_dir }}" ] && export GOROOT={{ golang.linux.base_dir }}
[ -n "{{ golang.path }}" ] && export GOROOT={{ golang.path }}

[ -n "${GOPATH}" ] && export GOPATH=${GOPATH}
[ -n "{{ golang.go_path }}" ] && export GOPATH={{ golang.go_path }}
Expand Down
9 changes: 2 additions & 7 deletions golang/map.jinja
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{#- Start imports as #}
{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %}
{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %}
{%- import_yaml tplroot ~ "/osmap.yaml" as osmap %}
{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %}
{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %}

{#- Retrieve the config dict only once #}
{%- set _config = salt['config.get'](tplroot, default={}) %}

{%- set defaults = salt['grains.filter_by'](
Expand Down Expand Up @@ -47,7 +44,6 @@
%}
{%- set golang = config %}

{#- Post-processing for specific non-YAML customisations #}
{%- do golang.update({'kernel': grains.kernel | lower}) %}
{%- if grains.os == 'MacOS' %}
{%- set macos_user = salt['cmd.run']("stat -f '%Su' /dev/console") %}
Expand All @@ -58,7 +54,6 @@
}) %}
{%- endif %}

{#- archive jinja #}
{%- if golang.pkg.use_upstream_archive %}
{%- set name = 'go%s.%s-%s'|format(golang.version, golang.kernel, golang.arch) %}
{%- set uri = golang.pkg.archive.uri + '/' + name %}
Expand All @@ -68,11 +63,11 @@
'source_hash': uri + '.' + golang.pkg.archive.archive_suffix + '.sha256',
'archive_format': golang.pkg.archive.archive_format
}) %}
{%- do golang.linux.update({'base_dir': golang.pkg.archive.name}) %}
{%- do golang.update({'path': golang.pkg.archive.name}) %}
{%- do golang.environ.append('export PATH=${PATH}:%s/go/bin'|format(golang.pkg.archive.name)) %}
{%- endif %}

{#- Post-processing for specific YAML keys depreciated in a major releases #}
{#- Depreciated parameter 'golang.dir' #}
{%- if 'dir' in golang and golang.dir and golang.kernel == 'linux' %}
{%- do golang.linux.update({'dir': golang.dir}) %}
{%- endif %}
24 changes: 17 additions & 7 deletions golang/package/clean.sls
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_config_clean = tplroot ~ '.config.clean' %}
{%- set sls_repo_clean = '.repo.clean' %}
{%- from tplroot ~ "/map.jinja" import golang with context %}
include:
- {{ sls_config_clean }}
{%- if grains.kernel|lower == 'linux' %}
- {{ sls_repo_clean }}
{%- if golang.pkg.use_upstream_repo %}
include:
- .repo.clean
{%- endif %}
golang-package-clean-pkg-removed:
golang-package-clean-pkg-cleaned:
pkg.removed:
- name: {{ golang.pkg.name }}
- require:
- sls: {{ sls_config_clean }}
- sls: {{ sls_repo_clean }}
{%- elif grains.os_family == 'MacOS' %}
golang-package-clean-cmd-run-brew:
cmd.run:
- name: brew uninstall --force {{ golang.pkg.name }}
- runas: {{ golang.rootuser }}
- onlyif: test -x /usr/local/bin/brew
- require:
- sls: {{ sls_config_clean }}
{%- endif %}
Loading

0 comments on commit e926a71

Please sign in to comment.