Update CI and do not use github import path anymore

- use local self-hosted ci : drone instead of circle
- add go modules support
- update import path to be local : git.xdrm.io/go/nix-amer instead of
github.com/xdrm-brackets/nix-amer
This commit is contained in:
Adrien Marquès 2018-11-18 22:49:11 +01:00
parent b752906d15
commit 27ace57523
29 changed files with 87 additions and 100 deletions

11
.drone.yml Normal file
View File

@ -0,0 +1,11 @@
---
kind: pipeline
type: docker
name: default
steps:
- name: test
image: golang:1.13
commands:
- go get ./...
- go test -v -race -cover -coverprofile ./coverage.out ./...

View File

@ -2,10 +2,10 @@
[![Go version](https://img.shields.io/badge/go_version-1.11-blue.svg)](https://golang.org/doc/go1.11)
[![License: MIT](https://img.shields.io/github/license/xdrm-brackets/nix-amer.svg)](https://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/github.com/xdrm-brackets/nix-amer)](https://goreportcard.com/report/github.com/xdrm-brackets/nix-amer)
[![Go Report Card](https://goreportcard.com/badge/git.xdrm.io/go/nix-amer)](https://goreportcard.com/report/git.xdrm.io/go/nix-amer)
[![Coverage Status](https://img.shields.io/coveralls/github/xdrm-brackets/nix-amer/master.svg)](https://coveralls.io/github/xdrm-brackets/nix-amer?branch=master)
[![CircleCI Build Status](https://img.shields.io/circleci/project/github/xdrm-brackets/nix-amer/master.svg)](https://circleci.com/gh/xdrm-brackets/nix-amer)
[![Go doc](https://godoc.org/github.com/xdrm-brackets/nix-amer?status.svg)](https://godoc.org/github.com/xdrm-brackets/nix-amer)
[![Build Status](https://drone.xdrm.io/api/badges/xdrm-brackets/ci-test/status.svg)](https://drone.xdrm.io/xdrm-brackets/ci-test)
[![Go doc](https://godoc.org/git.xdrm.io/go/nix-amer?status.svg)](https://godoc.org/git.xdrm.io/go/nix-amer)
```yaml
name: nix-amer
@ -25,13 +25,14 @@ author: xdrm-brackets
* [1. Create build file](#1-create-build-file)
* [2. Run on the target](#2-run-on-the-target)
* [II. Commands](#ii-commands)
+ [1) Comments](#1-comments)
+ [2) Install/remove Packages](#2-installremove-packages)
+ [3) Setup configuration](#3-setup-configuration)
+ [4) Service management](#4-service-management)
+ [5) Custom scripts](#5-custom-scripts)
+ [6) Copy files](#6-copy-files)
+ [7) Aliases](#7-aliases)
+ [1) Sections](#1-sections)
+ [2) Comments](#2-comments)
+ [3) Install/remove Packages](#3-installremove-packages)
+ [4) Setup configuration](#4-setup-configuration)
+ [5) Service management](#5-service-management)
+ [6) Custom scripts](#6-custom-scripts)
+ [7) Copy files](#7-copy-files)
+ [8) Aliases](#8-aliases)
* [III. Path Expressions](#iii-path-expressions)
+ [1) Syntax](#1-syntax)
+ [2) File Formats](#2-file-formats)
@ -59,10 +60,10 @@ In order to install the `nix-amer` executable, you must have :
Simply launch the following command in any terminal
```bash
$ go get -u github.com/xdrm-brackets/nix-amer
$ go get -u git.xdrm.io/go/nix-amer
```
> For those who don't know, it will load the project sources into `$GOPATH/src/github.com/xdrm-brackets/nix-amer` and compile into the executable at `$GOPATH/bin/nix-amer`.
> For those who don't know, it will load the project sources into `$GOPATH/src/git.xdrm.io/go/nix-amer` and compile into the executable at `$GOPATH/bin/nix-amer`.
@ -70,7 +71,7 @@ $ go get -u github.com/xdrm-brackets/nix-amer
###### 1. Create build file
The first step is to write your build file according to the installation you want. While writing your build file you can check the syntax by using the `-dry-run` command-line argument as follows :
The first step is to write your build file according to the installation you want. While writing it you can check the syntax and validate instructions by using the `-dry-run` command-line argument as follows :
```bash
$ nix-amer -p apt-get -dry-run <path/to/build/file>
@ -82,7 +83,7 @@ $ nix-amer -p apt-get -dry-run <path/to/build/file>
###### 2. Run on the target
Once your build file is correct and fulfills your needs, you can log in to the target machine, install the nix-amer and run it with your build file. Nix-amer's rich and colorful command-line output will give you a good feedback to rapidly fix problems.
Once your build file is correct and fulfills your needs, you can log in to the target machine, install nix-amer and run it with your build file. The rich and colorful command-line output will give you a good feedback to rapidly fix problems.
@ -94,17 +95,23 @@ Once your build file is correct and fulfills your needs, you can log in to the t
### II. Commands
Your whole setup remains in 1 only build file. Each line contains one instruction, the list of instructions is listed below.
Your whole setup remains in only one file. Each line contains one instruction, the list of instructions is listed below.
#### 1) Comments
#### 1) Sections
Each line beginning with one of the following characters : `[`, `#` or `;` is considered a comment and is not interpreted.
Each instruction is enclosed in a section (_cf. ini file format_), a section definition stands on a line where the name of the section is surrounded by `[` and `]`. Each section is executed in parallel ; the special section named `pre` is executed before every other.
#### 2) Install/remove Packages
#### 2) Comments
Each line beginning with one of the following characters : `#` or `;` is considered a comment and is not interpreted.
#### 3) Install/remove Packages
These instructions allow you to interact with the package system available on your system.
@ -122,7 +129,7 @@ Remove the listed packages. If more than one, use spaces to separate package nam
#### 3) Setup configuration
#### 4) Setup configuration
This instruction allow you to set fields of configuration files without the need of an editor and in a developer-readable manner.
@ -134,7 +141,7 @@ Update a configuration file where \<expr\> is a dot-separated human-readable [pa
#### 4) Service management
#### 5) Service management
These instructions allow you to interact with the service system (_cf. [systemd](https://github.com/systemd/systemd)_).
@ -145,7 +152,7 @@ Perform the action on services. If more than one, use spaces to separate service
#### 5) Custom scripts
#### 6) Custom scripts
This instruction allows you to use custom scripts for complex operations.
@ -153,9 +160,9 @@ This instruction allows you to use custom scripts for complex operations.
run <script>
```
Execute the executable located at the path \<script\>. If script is an [alias](#7-aliases) it will resolve to its path
Execute the executable located at the path \<script\>. If script is an [alias](#8-aliases) it will resolve to its path
#### 6) Copy files
#### 7) Copy files
This instruction allows you to copy files.
@ -167,7 +174,7 @@ Try to copy the file \<src\> to the path \<dst\>.
#### 7) Aliases
#### 8) Aliases
The file format allows you to create aliases to file paths for more readability in the [path expression](#ii-path-expressions) or with the [`run` command](#5-custom-scripts).
@ -195,7 +202,7 @@ The syntax is pretty fast-forward, it uses 2 levels (file, fields) to find your
| Field | Description | Example |
| --------- | :----------------------------------- | -------------------------- |
| `location_or_alias` | Path to the configuration file to edit. The file will be created if not found. If the path is an [alias](#7-aliases) created before in the file, it will resolve to the alias value as a filename. | `/etc/nginx/nginx.conf`, `some-alias` |
| `location_or_alias` | Path to the configuration file to edit. The file will be created if not found. If the path is an [alias](#8-aliases) created before in the file, it will resolve to the alias value as a filename. | `/etc/nginx/nginx.conf`, `some-alias` |
| `fields` | Dot-separated chain of strings that match a configuration field. If the field does not point to a raw field but an existing field container, the \<value\> will replace the group with a text value. | `AllowGroups`, `http.gzip` |
> The `fields` is processed only for known file formats listed in this [section](#2-file-formats).
@ -212,8 +219,8 @@ Configuration files can be written according to some standards or application-sp
- [yaml](https://en.wikipedia.org/wiki/YAML) with [go-yaml/yaml](https://github.com/go-yaml/yaml).
- [ini](https://en.wikipedia.org/wiki/INI_file) with [go-ini/ini](https://github.com/go-ini/ini).
- [nginx configurations](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/) with [my own library](https://godoc.org/github.com/xdrm-brackets/nix-amer/internal/cnf/parser/nginx).
- [nginx configurations](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/) with [my own library](https://godoc.org/git.xdrm.io/go/nix-amer/internal/cnf/parser/nginx).
- [bash sourced configurations]() with [my own library](https://godoc.org/git.xdrm.io/go/nix-amer/internal/cnf/parser/bash) (_e.g. ~/.bashrc_).
- _and more to come..._

View File

@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/instruction"
"git.xdrm.io/go/nix-amer/internal/instruction"
)
// GetArgs manages cli arguments to build executionContext,

View File

@ -1,44 +0,0 @@
version: 2
jobs:
build: # runs not using Workflows must have a `build` job as entry point
docker:
- image: circleci/golang
environment: # environment variables for the build itself
GOPATH: /go
TEST_RESULTS: /tmp/test-results
COVER_PROFILE: /tmp/coverage.out
steps: # steps that comprise the `build` job
- checkout # check out source code to working directory
- run: mkdir -p $TEST_RESULTS # create the test results directory
- restore_cache: # restores saved cache if no changes are detected since last run
keys:
- v1-pkg-cache
- run:
name: Load dependencies
command: go get github.com/mattn/goveralls && go get github.com/go-ini/ini && go get gopkg.in/yaml.v2
- run:
name: Load nix-amer
command: go get github.com/xdrm-brackets/nix-amer
- run:
name: Unit tests
command: go test -v -cover -race -coverprofile=$COVER_PROFILE github.com/xdrm-brackets/nix-amer/... | tee $TEST_RESULTS/out
- run:
name: go fmt
command: go fmt github.com/xdrm-brackets/nix-amer/...
- run:
name: go vet
command: go vet github.com/xdrm-brackets/nix-amer/...
- run:
name: Update coveralls.io
command: /go/bin/goveralls -coverprofile=$COVER_PROFILE -service=circle-ci -repotoken=$COVERALLS_TOKEN
- store_artifacts: # Upload test summary for display in Artifacts
path: /tmp/test-results
destination: raw-test-output
- store_test_results: # Upload test results for display in Test Summary
path: /tmp/test-results

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module git.xdrm.io/go/nix-amer
go 1.12
require (
github.com/go-ini/ini v1.51.0
gopkg.in/yaml.v2 v2.2.5
)

5
go.sum Normal file
View File

@ -0,0 +1,5 @@
github.com/go-ini/ini v1.51.0 h1:VPJKXGzbKlyExUE8f41aV57yxkYx5R49yR6n7flp0M0=
github.com/go-ini/ini v1.51.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/clifmt"
"git.xdrm.io/go/nix-amer/internal/clifmt"
)
func help() {

View File

@ -2,7 +2,7 @@ package buildfile
import (
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/clifmt"
"git.xdrm.io/go/nix-amer/internal/clifmt"
)
// LineError wraps errors with a line index

View File

@ -4,8 +4,8 @@ import (
"bufio"
"errors"
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/clifmt"
"github.com/xdrm-brackets/nix-amer/internal/instruction"
"git.xdrm.io/go/nix-amer/internal/clifmt"
"git.xdrm.io/go/nix-amer/internal/instruction"
"io"
"regexp"
"strings"

View File

@ -2,7 +2,7 @@ package buildfile
import (
"bytes"
"github.com/xdrm-brackets/nix-amer/internal/instruction"
"git.xdrm.io/go/nix-amer/internal/instruction"
"testing"
)

View File

@ -1,7 +1,7 @@
package cnf
import (
lib "github.com/xdrm-brackets/nix-amer/internal/cnf/parser/bash"
lib "git.xdrm.io/go/nix-amer/internal/cnf/parser/bash"
"io"
"strings"
)

View File

@ -1,7 +1,7 @@
package cnf
import (
lib "github.com/xdrm-brackets/nix-amer/internal/cnf/parser/nginx"
lib "git.xdrm.io/go/nix-amer/internal/cnf/parser/nginx"
"io"
"strings"
)

View File

@ -2,7 +2,7 @@ package bash
import (
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/clifmt"
"git.xdrm.io/go/nix-amer/internal/clifmt"
)
// ErrNullReceiver is raised when a null receiver is provided

View File

@ -2,7 +2,7 @@ package nginx
import (
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/clifmt"
"git.xdrm.io/go/nix-amer/internal/clifmt"
)
// ErrNullReceiver is raised when a null receiver is provided

View File

@ -2,9 +2,9 @@ package instruction
import (
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/exec"
"github.com/xdrm-brackets/nix-amer/internal/pkg"
"github.com/xdrm-brackets/nix-amer/internal/ser"
"git.xdrm.io/go/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/pkg"
"git.xdrm.io/go/nix-amer/internal/ser"
)
// T is the instruction common interface

View File

@ -2,7 +2,7 @@ package instruction
import (
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/cnf"
"git.xdrm.io/go/nix-amer/internal/cnf"
"os"
"path/filepath"
"strings"

View File

@ -1,6 +1,6 @@
package pkg
import "github.com/xdrm-brackets/nix-amer/internal/exec"
import "git.xdrm.io/go/nix-amer/internal/exec"
type apk struct{ exec exec.Executor }

View File

@ -1,7 +1,7 @@
package pkg
import (
"github.com/xdrm-brackets/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/exec"
)
type aptGet struct{ exec exec.Executor }

View File

@ -1,7 +1,7 @@
package pkg
import (
"github.com/xdrm-brackets/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/exec"
)
// DefaultManager if not empty is the default package-manager to use when missing

View File

@ -1,6 +1,6 @@
package pkg
import "github.com/xdrm-brackets/nix-amer/internal/exec"
import "git.xdrm.io/go/nix-amer/internal/exec"
type dnf struct{ exec exec.Executor }

View File

@ -1,6 +1,6 @@
package pkg
import "github.com/xdrm-brackets/nix-amer/internal/exec"
import "git.xdrm.io/go/nix-amer/internal/exec"
type eopkg struct{ exec exec.Executor }

View File

@ -2,7 +2,7 @@ package pkg
import (
"errors"
"github.com/xdrm-brackets/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/exec"
)
// ErrUnknownManager is raised when the asked manager does not exist

View File

@ -1,7 +1,7 @@
package pkg
import (
"github.com/xdrm-brackets/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/exec"
"testing"
)

View File

@ -1,6 +1,6 @@
package pkg
import "github.com/xdrm-brackets/nix-amer/internal/exec"
import "git.xdrm.io/go/nix-amer/internal/exec"
type pacman struct{ exec exec.Executor }

View File

@ -1,6 +1,6 @@
package pkg
import "github.com/xdrm-brackets/nix-amer/internal/exec"
import "git.xdrm.io/go/nix-amer/internal/exec"
type yum struct{ exec exec.Executor }

View File

@ -1,7 +1,7 @@
package ser
import (
"github.com/xdrm-brackets/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/exec"
)
// DefaultManager if not empty is the default service-manager to use when missing

View File

@ -2,7 +2,7 @@ package ser
import (
"errors"
"github.com/xdrm-brackets/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/exec"
)
// ErrUnknownManager is raised when the asked manager does not exist

View File

@ -1,7 +1,7 @@
package ser
import (
"github.com/xdrm-brackets/nix-amer/internal/exec"
"git.xdrm.io/go/nix-amer/internal/exec"
)
type systemd struct{ exec exec.Executor }

View File

@ -2,8 +2,8 @@ package main
import (
"fmt"
"github.com/xdrm-brackets/nix-amer/internal/buildfile"
"github.com/xdrm-brackets/nix-amer/internal/clifmt"
"git.xdrm.io/go/nix-amer/internal/buildfile"
"git.xdrm.io/go/nix-amer/internal/clifmt"
"os"
"time"
)