Replace CIs by Github Actions (#294)

This commit is contained in:
Thomas Pelletier
2019-09-09 19:44:45 -07:00
committed by GitHub
parent 4d5afd743f
commit b40204d36a
11 changed files with 231 additions and 295 deletions
-174
View File
@@ -1,174 +0,0 @@
version: 2.1
executors:
golang:
parameters:
version:
type: string
docker:
- image: circleci/golang:<< parameters.version >>
commands:
get_deps:
description: "Get go dependencies"
steps:
- run: go get github.com/jstemmer/go-junit-report
run_test:
description: "Run unit tests for a go module"
parameters:
test_name:
type: string
module:
type: string
coverage:
default: false
type: boolean
allow_fail:
type: boolean
default: false
steps:
- run:
name: "Run tests for <<parameters.test_name>>"
command: |
TEST_DIR="/tmp/test-results/<<parameters.test_name>>"
mkdir -p ${TEST_DIR}
trap "go-junit-report </tmp/test-results/go-test.out > ${TEST_DIR}/go-test-report.xml" EXIT
go test <<parameters.module>> -race -v \
<<# parameters.coverage >>-coverprofile=/tmp/workspace/coverage.txt -covermode=atomic<</ parameters.coverage >> \
| tee /tmp/test-results/go-test.out <<# parameters.allow_fail >>|| true<</ parameters.allow_fail >>
jobs:
go:
parameters:
version:
type: string
allow_fail:
type: boolean
default: false
executor:
name: golang
version: "<<parameters.version>>"
working_directory: /go/src/github.com/pelletier/go-toml
environment:
GO111MODULE: "on"
steps:
- checkout
- run: mkdir -p /tmp/workspace
- run: go fmt ./... <<# parameters.allow_fail >>|| true<</ parameters.allow_fail >>
- get_deps
- run_test:
test_name: "go-toml"
module: "github.com/pelletier/go-toml"
coverage: true
allow_fail: <<parameters.allow_fail>>
- run_test:
test_name: "tomljson"
module: "github.com/pelletier/go-toml/cmd/tomljson"
allow_fail: <<parameters.allow_fail>>
- run_test:
test_name: "jsontoml"
module: "github.com/pelletier/go-toml/cmd/jsontoml"
allow_fail: <<parameters.allow_fail>>
- run_test:
test_name: "tomll"
module: "github.com/pelletier/go-toml/cmd/tomll"
allow_fail: <<parameters.allow_fail>>
- run_test:
test_name: "query"
module: "github.com/pelletier/go-toml/query"
allow_fail: <<parameters.allow_fail>>
- store_test_results:
path: /tmp/test-results
codecov:
docker:
- image: "circleci/golang:1.12"
steps:
- attach_workspace:
at: /tmp/workspace
- run:
name: "upload to codecov"
working_directory: /tmp/workspace
command: |
curl https://codecov.io/bash > codecov.sh
bash codecov.sh -v
docker:
docker:
- image: "circleci/golang:1.12"
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run: docker build -t pelletier/go-toml:$CIRCLE_SHA1 .
- run:
name: "Publish docker image"
command: |
if [ "${CIRCLE_PR_REPONAME}" == "" ]; then
IMAGE_NAME="pelletier/go-toml"
IMAGE_SHA_TAG="${IMAGE_NAME}:$CIRCLE_SHA1"
if [ "${CIRCLE_BRANCH}" = "master" ]; then
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker tag ${IMAGE_SHA_TAG} ${IMAGE_NAME}:latest
docker push ${IMAGE_NAME}:latest
fi
if [ "${CIRCLE_TAG}" != "" ]; then
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker tag ${IMAGE_SHA_TAG} ${IMAGE_NAME}:${CIRCLE_TAG}
docker push ${IMAGE_NAME}:${CIRCLE_TAG}
fi
else
echo "not pushing docker image for forked repo"
fi
workflows:
version: 2.1
build:
jobs:
- go:
name: "go1_11"
version: "1.11"
- go:
name: "go1_12"
version: "1.12"
post-steps:
- run: go tool cover -html=/tmp/workspace/coverage.txt -o coverage.html
- store_artifacts:
path: /tmp/workspace/coverage.txt
- store_artifacts:
path: coverage.html
- persist_to_workspace:
root: /tmp/workspace
paths:
- coverage.txt
- go:
name: "gotip"
version: "1.12" # use as base
allow_fail: true
pre-steps:
- restore_cache:
keys:
- go-tip-source
- run:
name: "Compile go tip"
command: |
if [ ! -d "/tmp/go" ]; then
git clone https://go.googlesource.com/go /tmp/go
fi
cd /tmp/go
git checkout master
git pull
cd src
./make.bash
echo 'export PATH="/tmp/go/bin:$PATH"' >> $BASH_ENV
- run: go version
- save_cache:
key: go-tip-source
paths:
- "/tmp/go"
- codecov:
requires:
- go1_11
- go1_12
- docker:
requires:
- codecov
+17
View File
@@ -0,0 +1,17 @@
name: Fuzzit
on:
push:
branches:
- master
jobs:
fuzzing:
name: Run fuzzing
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.13'
- uses: actions/checkout@v1
- run: ./fuzzit.sh
env:
TYPE: fuzzing
+80
View File
@@ -0,0 +1,80 @@
name: Go
on: [push]
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
go: ['1.12', '1.13']
runs-on: ${{ matrix.os }}
name: Test Go ${{ matrix.go }} on ${{ matrix.os }}
steps:
- uses: pelletier/setup-go@v1.0.2-patch
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v1
- run: go test ./...
coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- uses: pelletier/setup-go@v1.0.2-patch
with:
go-version: '1.12'
- uses: actions/checkout@v1
- run: go test -race -coverprofile=coverage.txt -covermode=atomic
- run: bash <(curl -s https://codecov.io/bash)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
fmt:
name: Go fmt
runs-on: ubuntu-latest
steps:
- uses: pelletier/setup-go@v1.0.2-patch
- uses: actions/checkout@v1
- run: go fmt ./...
benchmark:
name: Run benchmark
runs-on: ubuntu-latest
steps:
- uses: pelletier/setup-go@v1.0.2-patch
with:
go-version: '1.13'
- uses: actions/checkout@v1
- run: ./benchmark.sh master https://github.com/$GITHUB_REPOSITORY.git
fuzzing:
name: Run fuzzing
runs-on: ubuntu-latest
steps:
- uses: pelletier/setup-go@v1.0.2-patch
with:
go-version: '1.13'
- uses: actions/checkout@v1
- run: mkdir -p /home/runner/go/src/github.com/pelletier/go-toml
| cp -R . /home/runner/go/src/github.com/pelletier/go-toml
- run: ./fuzzit.sh
env:
TYPE: local-regression
docker:
name: Build Docker image
runs-on: ubuntu-latest
needs: [test, fuzzing, fmt]
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.13'
- uses: actions/checkout@v1
- run: docker build -t toml .
- uses: actions/docker/tag@master
with:
args: toml pelletier/go-toml
- run: docker tag pelletier/go-toml pelletier/go-toml:latest
if: github.ref == 'heads/refs/master'
- name: Docker login
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- run: docker push pelletier/go-toml
-29
View File
@@ -1,29 +0,0 @@
dist: bionic
language: go
services:
- docker
matrix:
allow_failures:
- go: tip
fast_finish: true
include:
- go: 1.11.x
- go: 1.12.x
env: WITH_FUZZ=true
- go: tip
env:
- GO111MODULE=on
- secure: "hhoCl77LhP25e+dLzmKphjdj+ep6jRfqON1JoxdvRXYjQqmhtxWSTJFqPyMLz2fNGSN8HUcyZZKTrOG6HkrapiIR5kjrnvm6Fzjp+IfClPoPu8xQUIbKd8E3BrDwvvF1JkkLImozxZbrbJhksJqN+QgG/Lv2vs6wkAfQjvGcRTQ="
script:
- if [ -n "$(go fmt ./...)" ]; then exit 1; fi
- go test github.com/pelletier/go-toml -race -coverprofile=coverage.txt -covermode=atomic
- go test github.com/pelletier/go-toml/cmd/tomljson
- go test github.com/pelletier/go-toml/cmd/jsontoml
- go test github.com/pelletier/go-toml/cmd/tomll
- go test github.com/pelletier/go-toml/query
- ./benchmark.sh $TRAVIS_BRANCH https://github.com/$TRAVIS_REPO_SLUG.git
- ./fuzzit.sh
after_success:
- bash <(curl -s https://codecov.io/bash)
-35
View File
@@ -1,35 +0,0 @@
version: "{build}"
# Source Config
clone_folder: c:\gopath\src\github.com\pelletier\go-toml
# Build host
environment:
GOPATH: c:\gopath
DEPTESTBYPASS501: 1
GOVERSION: 1.12
GO111MODULE: on
init:
- git config --global core.autocrlf input
# Build
install:
# Install the specific Go version.
- rmdir c:\go /s /q
- appveyor DownloadFile https://storage.googleapis.com/golang/go%GOVERSION%.windows-amd64.msi
- msiexec /i go%GOVERSION%.windows-amd64.msi /q
- choco install bzr
- set Path=c:\go\bin;c:\gopath\bin;C:\Program Files (x86)\Bazaar\;C:\Program Files\Mercurial\%Path%
- go version
- go env
build: false
deploy: false
test_script:
- go test github.com/pelletier/go-toml
- go test github.com/pelletier/go-toml/cmd/tomljson
- go test github.com/pelletier/go-toml/cmd/jsontoml
- go test github.com/pelletier/go-toml/cmd/tomll
- go test github.com/pelletier/go-toml/query
+2 -2
View File
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
set -ex
reference_ref=${1:-master}
reference_git=${2:-.}
@@ -29,4 +29,4 @@ go test -bench=. -benchmem | tee ${local_benchmark}
echo ""
echo "=== diff"
benchstat -delta-test=none ${ref_benchmark} ${local_benchmark}
benchstat -delta-test=none ${ref_benchmark} ${local_benchmark}
+4 -3
View File
@@ -37,6 +37,7 @@ func processMain(files []string, defaultInput io.Reader, output io.Writer, error
file, err := os.Open(files[0])
if err != nil {
printError(err, errorOutput)
return -1
}
inputReader = file
defer file.Close()
@@ -60,9 +61,9 @@ func reader(r io.Reader) (string, error) {
if err != nil {
return "", err
}
error := json.Unmarshal(jsonBytes, &jsonMap)
if error != nil {
return "", error
err = json.Unmarshal(jsonBytes, &jsonMap)
if err != nil {
return "", err
}
tree, err := toml.TreeFromMap(jsonMap)
-1
View File
@@ -85,7 +85,6 @@ func TestProcessMainReadFromMissingFile(t *testing.T) {
`
} else {
expectedError = `open /this/file/does/not/exist: no such file or directory
invalid argument
`
}
-14
View File
@@ -1,12 +1,6 @@
#!/bin/bash
set -xe
# fuzz only in one configuration
# there's no benefit to fuzzing with different go versions
if [ -z ${WITH_FUZZ} ]; then
exit 0
fi
# go-fuzz doesn't support modules yet, so ensure we do everything
# in the old style GOPATH way
export GO111MODULE="off"
@@ -28,13 +22,5 @@ clang -fsanitize=fuzzer ${TARGET}.a -o ${TARGET}
wget -q -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/v2.4.23/fuzzit_Linux_x86_64
chmod a+x fuzzit
# upload fuzz target for long fuzz testing on fuzzit.dev server
# or run locally for regression, depending on --type
if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
TYPE=fuzzing
else
TYPE=local-regression
fi
# TODO: change kkowalczyk to go-toml and create toml-fuzzer target there
./fuzzit create job --type $TYPE go-toml/${TARGET} ${TARGET}
-17
View File
@@ -1,17 +0,0 @@
title = "TOML Marshal Testing"
[basic_map]
one = "one"
two = "two"
[long_map]
a7 = "1"
b3 = "2"
c8 = "3"
d4 = "4"
e6 = "5"
f5 = "6"
g10 = "7"
h1 = "8"
i2 = "9"
j9 = "10"
+128 -20
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
@@ -55,6 +56,107 @@ Ystrlist = ["Howdy","Hey There"]
String2 = "Three"
`)
var marshalTestToml = []byte(`title = "TOML Marshal Testing"
[basic]
bool = true
date = 1979-05-27T07:32:00Z
float = 123.4
float64 = 123.456782132399
int = 5000
string = "Bite me"
uint = 5001
[basic_lists]
bools = [true,false,true]
dates = [1979-05-27T07:32:00Z,1980-05-27T07:32:00Z]
floats = [12.3,45.6,78.9]
ints = [8001,8001,8002]
strings = ["One","Two","Three"]
uints = [5002,5003]
[basic_map]
one = "one"
two = "two"
[subdoc]
[subdoc.first]
name = "First"
[subdoc.second]
name = "Second"
[[subdoclist]]
name = "List.First"
[[subdoclist]]
name = "List.Second"
[[subdocptrs]]
name = "Second"
`)
var marshalOrderPreserveToml = []byte(`title = "TOML Marshal Testing"
[basic_lists]
floats = [12.3,45.6,78.9]
bools = [true,false,true]
dates = [1979-05-27T07:32:00Z,1980-05-27T07:32:00Z]
ints = [8001,8001,8002]
uints = [5002,5003]
strings = ["One","Two","Three"]
[[subdocptrs]]
name = "Second"
[basic_map]
one = "one"
two = "two"
[subdoc]
[subdoc.second]
name = "Second"
[subdoc.first]
name = "First"
[basic]
uint = 5001
bool = true
float = 123.4
float64 = 123.456782132399
int = 5000
string = "Bite me"
date = 1979-05-27T07:32:00Z
[[subdoclist]]
name = "List.First"
[[subdoclist]]
name = "List.Second"
`)
var mashalOrderPreserveMapToml = []byte(`title = "TOML Marshal Testing"
[basic_map]
one = "one"
two = "two"
[long_map]
a7 = "1"
b3 = "2"
c8 = "3"
d4 = "4"
e6 = "5"
f5 = "6"
g10 = "7"
h1 = "8"
i2 = "9"
j9 = "10"
`)
func TestBasicMarshal(t *testing.T) {
result, err := Marshal(basicTestData)
if err != nil {
@@ -233,9 +335,8 @@ func TestDocMarshal(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile("marshal_test.toml")
if !bytes.Equal(result, expected) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result)
if !bytes.Equal(result, marshalTestToml) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", marshalTestToml, result)
}
}
@@ -245,9 +346,8 @@ func TestDocMarshalOrdered(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile("marshal_OrderPreserve_test.toml")
if !bytes.Equal(result.Bytes(), expected) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result.Bytes())
if !bytes.Equal(result.Bytes(), marshalOrderPreserveToml) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", marshalOrderPreserveToml, result.Bytes())
}
}
@@ -256,9 +356,8 @@ func TestDocMarshalMaps(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile("marshal_OrderPreserve_Map_test.toml")
if !bytes.Equal(result, expected) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result)
if !bytes.Equal(result, mashalOrderPreserveMapToml) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", mashalOrderPreserveMapToml, result)
}
}
@@ -268,9 +367,8 @@ func TestDocMarshalOrderedMaps(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile("marshal_OrderPreserve_Map_test.toml")
if !bytes.Equal(result.Bytes(), expected) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result.Bytes())
if !bytes.Equal(result.Bytes(), mashalOrderPreserveMapToml) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", mashalOrderPreserveMapToml, result.Bytes())
}
}
@@ -279,16 +377,15 @@ func TestDocMarshalPointer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expected, _ := ioutil.ReadFile("marshal_test.toml")
if !bytes.Equal(result, expected) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", expected, result)
if !bytes.Equal(result, marshalTestToml) {
t.Errorf("Bad marshal: expected\n-----\n%s\n-----\ngot\n-----\n%s\n-----\n", marshalTestToml, result)
}
}
func TestDocUnmarshal(t *testing.T) {
result := testDoc{}
tomlData, _ := ioutil.ReadFile("marshal_test.toml")
err := Unmarshal(tomlData, &result)
err := Unmarshal(marshalTestToml, &result)
expected := docData
if err != nil {
t.Fatal(err)
@@ -301,11 +398,22 @@ func TestDocUnmarshal(t *testing.T) {
}
func TestDocPartialUnmarshal(t *testing.T) {
result := testDocSubs{}
file, err := ioutil.TempFile("", "test-*.toml")
if err != nil {
t.Fatal(err)
}
defer os.Remove(file.Name())
tree, _ := LoadFile("marshal_test.toml")
err = ioutil.WriteFile(file.Name(), marshalTestToml, 0)
if err != nil {
t.Fatal(err)
}
tree, _ := LoadFile(file.Name())
subTree := tree.Get("subdoc").(*Tree)
err := subTree.Unmarshal(&result)
result := testDocSubs{}
err = subTree.Unmarshal(&result)
expected := docData.Subdocs
if err != nil {
t.Fatal(err)