Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: remove circle ci, split build and unit test, add lint and codespell #122

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 0 additions & 54 deletions .circleci/config.yml

This file was deleted.

88 changes: 88 additions & 0 deletions .github/workflows/build.yaml
@@ -0,0 +1,88 @@
# every push to a branch: build binary
name: Build
on:
push:
branches:
jobs:
build_binary:
name: Build shell-operator binary
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.12
uses: actions/setup-go@v1
with:
go-version: 1.12
id: go

- name: Check out shell-operator code
uses: actions/checkout@v1

# Restore go_modules.tar.gz from cache or download and pack them, upload archive as artifact for other jobs.
# NOTE: cache action is limited to 400Mb artifacts and has a 2Gb space.
# As of December 2019, go_modules.tar.gz is 281Mb
- name: Cache go modules archive
id: go-modules-cache
uses: actions/cache@v1
with:
path: gomod
key: ${{ runner.os }}-gomod-${{ hashFiles('go.mod') }}
restore-keys: |
${{ runner.os }}-gomod-

- name: Download and pack Go modules
if: steps.go-modules-cache.outputs.cache-hit != 'true'
run: |
mkdir -p gomod
go mod download
tar -czf gomod/go_modules.tar.gz -C $HOME/go/pkg/mod .
echo -n "Unpacked size is: " && du -sh $HOME/go/pkg/mod
echo -n "Packed size is: " && du -sh gomod/go_modules.tar.gz

- name: Unpack go modules
if: steps.go-modules-cache.outputs.cache-hit == 'true'
run: |
mkdir -p $HOME/go/pkg/mod && tar -xzf gomod/go_modules.tar.gz -C $HOME/go/pkg/mod

# Restore libjq-go-build directory from cache or build it, upload it as artifact for other jobs.
- name: Extract libjq-go.lock from go.mod
run: |
grep 'flant/libjq-go' go.mod > libjq-go.lock
cat libjq-go.lock

- name: Cache libjq libraries
id: libjq-cache
uses: actions/cache@v1
with:
path: libjq
key: ${{ runner.os }}-libjq-${{ hashFiles('libjq-go.lock') }}

- name: Build libjq libraries
if: steps.libjq-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y git ca-certificates tree

git clone https://github.com/flant/libjq-go libjq-go
cd libjq-go
git submodule update --init
sudo ./scripts/install-libjq-dependencies-ubuntu.sh

./scripts/build-libjq-static.sh ${GITHUB_WORKSPACE}/libjq-go ${GITHUB_WORKSPACE}/libjq

tree ${GITHUB_WORKSPACE}/libjq

- name: Prepare environment
run: |
echo ::set-env name=CGO_ENABLED::1

CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/build/jq/include"
echo ::set-env name=CGO_CFLAGS::${CGO_CFLAGS}

CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/build/onig/lib -L$GITHUB_WORKSPACE/libjq/build/jq/lib"
echo ::set-env name=CGO_LDFLAGS::${CGO_LDFLAGS}

echo ::set-env name=GOOS::linux

- name: Build binary
run: |
go build ./cmd/shell-operator
37 changes: 37 additions & 0 deletions .github/workflows/code-checks.yaml
@@ -0,0 +1,37 @@
# every push to a branch:
# - check grammar
# - go fmt
name: Code checks
on:
push:
branches:
jobs:
code_stle:
name: Go code style
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.12
uses: actions/setup-go@v1
with:
go-version: 1.12

- uses: actions/checkout@v1

- name: code style
run: |
gofmt -d $(find . -type f -iname '*.go')

codespell:
name: codespell
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
with:
python-version: 3.7

- uses: actions/checkout@v1

- name: codespell
run: |
pip install codespell
codespell --skip=".git,go.mod,go.sum,*.log,*.gif,*.png" -L witht,eventtypes,uint,uptodate
93 changes: 93 additions & 0 deletions .github/workflows/lint.yaml
@@ -0,0 +1,93 @@
# every push to a branch:
# - run linter
name: Lint
on:
push:
branches:
jobs:
run_linter:
name: Run linter
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.12
uses: actions/setup-go@v1
with:
go-version: 1.12
id: go

- name: Check out shell-operator code
uses: actions/checkout@v1

# Restore go_modules.tar.gz from cache or download and pack them, upload archive as artifact for other jobs.
# NOTE: cache action is limited to 400Mb artifacts and has a 2Gb space.
# As of December 2019, go_modules.tar.gz is 281Mb
- name: Cache go modules archive
id: go-modules-cache
uses: actions/cache@v1
with:
path: gomod
key: ${{ runner.os }}-gomod-${{ hashFiles('go.mod') }}
restore-keys: |
${{ runner.os }}-gomod-

- name: Download and pack Go modules
if: steps.go-modules-cache.outputs.cache-hit != 'true'
run: |
mkdir -p gomod
go mod download
tar -czf gomod/go_modules.tar.gz -C $HOME/go/pkg/mod .
echo -n "Unpacked size is: " && du -sh $HOME/go/pkg/mod
echo -n "Packed size is: " && du -sh gomod/go_modules.tar.gz

- name: Unpack go modules
if: steps.go-modules-cache.outputs.cache-hit == 'true'
run: |
mkdir -p $HOME/go/pkg/mod && tar -xzf gomod/go_modules.tar.gz -C $HOME/go/pkg/mod

# Restore libjq-go-build directory from cache or build it, upload it as artifact for other jobs.
- name: Extract libjq-go.lock from go.mod
run: |
grep 'flant/libjq-go' go.mod > libjq-go.lock
cat libjq-go.lock

- name: Cache libjq libraries
id: libjq-cache
uses: actions/cache@v1
with:
path: libjq
key: ${{ runner.os }}-libjq-${{ hashFiles('libjq-go.lock') }}

- name: Build libjq libraries
if: steps.libjq-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y git ca-certificates tree

git clone https://github.com/flant/libjq-go libjq-go
cd libjq-go
git submodule update --init
sudo ./scripts/install-libjq-dependencies-ubuntu.sh

./scripts/build-libjq-static.sh ${GITHUB_WORKSPACE}/libjq-go ${GITHUB_WORKSPACE}/libjq

tree ${GITHUB_WORKSPACE}/libjq

- name: Prepare environment
run: |
echo ::set-env name=CGO_ENABLED::1

CGO_CFLAGS="-I$GITHUB_WORKSPACE/libjq/build/jq/include"
echo ::set-env name=CGO_CFLAGS::${CGO_CFLAGS}

CGO_LDFLAGS="-L$GITHUB_WORKSPACE/libjq/build/onig/lib -L$GITHUB_WORKSPACE/libjq/build/jq/lib"
echo ::set-env name=CGO_LDFLAGS::${CGO_LDFLAGS}

echo ::set-env name=GOOS::linux

- name: Run golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.17.1
echo
./golangci-lint --version
echo
GL_DEBUG=linters_output GOPACKAGESPRINTGOLISTERRORS=1 ./golangci-lint run -v
8 changes: 2 additions & 6 deletions .github/workflows/tests.yaml
@@ -1,5 +1,5 @@
# every push to fix_, and feat_* : build binary and run unit tests
# push to master or label: build binary, run all tests and upload coverage.
# every push to a branch : run unit tests.
# push to master or label: run all tests and upload a coverage report.
name: Tests
on:
push:
Expand Down Expand Up @@ -113,10 +113,6 @@ jobs:

echo ::set-env name=GOOS::linux

- name: Build binary
run: |
go build ./cmd/shell-operator

- name: Run unit tests
run: |
go test \
Expand Down