ci: Use GitHub Actions to run tests

This commit is contained in:
Xavier Villaneau 2022-02-14 11:48:18 -05:00 committed by Xavier Villaneau
parent 8fe2bcc648
commit 5ea59b00fd
3 changed files with 87 additions and 33 deletions

41
.github/workflows/license.yml vendored Normal file
View File

@ -0,0 +1,41 @@
# Copyright 2022 DigitalOcean
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: License
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
check-file-licenses:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Download addlicense
run: go get -d github.com/google/addlicense
- name: Build addlicense
run: go build -o addlicense github.com/google/addlicense
- name: Check file licenses
run: ./addlicense -c DigitalOcean -l apache -y 2022 --check .

46
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,46 @@
# Copyright 2022 DigitalOcean
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
run-go-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Set up Ceph repository key
run: wget -q -O- 'https://download.ceph.com/keys/release.asc' | sudo apt-key add -
- name: Declare Ceph Nautilus repository
run: echo deb https://download.ceph.com/debian-nautilus/ $(lsb_release -sc) main | sudo tee /etc/apt/sources.list.d/ceph.list
- name: Install go-ceph dependencies
run: sudo apt update && sudo apt install -y librados-dev librbd-dev
- name: Go build
run: go build -v ./...
- name: Go test
run: go test -v ./...

View File

@ -1,33 +0,0 @@
os: linux
dist: bionic
language: go
go:
- 1.15.x
env:
- DOCKER_TAG=$TRAVIS_TAG
before_install:
- wget -q -O- 'https://download.ceph.com/keys/release.asc' | sudo apt-key add -
- echo deb https://download.ceph.com/debian-nautilus/ $(lsb_release -sc) main | sudo tee /etc/apt/sources.list.d/ceph.list
- sudo DEBIAN_FRONTEND=noninteractive apt-get update
- sudo DEBIAN_FRONTEND=noninteractive apt-get install -y librados-dev librbd-dev
install:
- go get github.com/modocache/gover
- go get github.com/mattn/goveralls
script:
- go test -tags nautilus -v -race -count=1 -coverprofile=collectors.coverprofile ./...
- $HOME/gopath/bin/gover
- $HOME/gopath/bin/goveralls -coverprofile=gover.coverprofile -service travis-ci
after_success:
- export DOCKER_REPO="digitalocean/ceph_exporter"
- if [ ! -z "$TRAVIS_TAG" ]; then
docker build -t $DOCKER_REPO:$DOCKER_TAG .;
docker tag $DOCKER_REPO:$DOCKER_TAG $DOCKER_REPO:latest;
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
docker push $DOCKER_REPO;
fi