Skip to content

Commit

Permalink
[CCXDEV-12101] Move from Travis CI to GH Actions (#1877)
Browse files Browse the repository at this point in the history
* move from Travis CI to GH Actions

* remove go1.17 for CI checks

* don't run the checks twice

* fix syntax

* fix syntax again

* fix syntax again

* run postgres for bdd tests

* fix postgres password

* fix wrong envs

* fix wrong user

* try different password

* typo

* change postgres image

* fix unit tests

* fix unit tests for latest postgres

* fix assert

* use go1.18 in bdd tests
  • Loading branch information
juandspy authored Oct 26, 2023
1 parent 7d0f24f commit 3af12a6
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 71 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/bdd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: BDD tests

on:
push:
branches:
- master
pull_request:

jobs:
bdd:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version:
- "1.18"
name: BDD for Go ${{ matrix.go-version}}
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Build project
run: make build
- name: Retrieve Docker compose file
run: wget -O docker-compose.yml https://raw.githubusercontent.com/RedHatInsights/insights-behavioral-spec/main/docker-compose.yml
- name: Retrieve BDD runner
run: wget -O bdd_runner.sh https://raw.githubusercontent.com/RedHatInsights/insights-behavioral-spec/main/run_in_docker.sh && chmod +x bdd_runner.sh
- name: Run BDD
run: ./bdd_runner.sh aggregator-tests .
47 changes: 47 additions & 0 deletions .github/workflows/gotests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Go tests

on:
push:
branches:
- master
pull_request:

jobs:
gotests:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version:
- "1.18"
- "1.19"
- "1.20"
- "1.21"
name: Tests for Go ${{ matrix.go-version}}
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Print env vars
run: env
- name: Unit tests
run: make test
- name: Check code coverage
run: ./check_coverage.sh
- name: Display code coverage
run: make coverage
29 changes: 29 additions & 0 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Go linters

on:
push:
branches:
- master
pull_request:

jobs:
golint:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version:
- "1.18"
- "1.19"
- "1.20"
- "1.21"
name: Linters for Go ${{ matrix.go-version}}
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Build project
run: go build
- name: Style linters
run: make style
15 changes: 15 additions & 0 deletions .github/workflows/shellcheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Shell check

on:
push:
branches:
- master
pull_request:

jobs:
shellcheck:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Shell check
run: ./shellcheck.sh
65 changes: 0 additions & 65 deletions .travis.yml

This file was deleted.

5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ services:
ports:
- 5432:5432
image: registry.redhat.io/rhscl/postgresql-10-rhel7
platform: linux/x86_64
environment:
- POSTGRESQL_USER=user
- POSTGRESQL_PASSWORD=password
- POSTGRESQL_ADMIN_PASSWORD=admin
- POSTGRESQL_DATABASE=aggregator
- POSTGRESQL_ADMIN_PASSWORD=postgres
- POSTGRESQL_DATABASE=aggregator
2 changes: 1 addition & 1 deletion storage/storage_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func TestDBStorageVoteOnRuleDBExecError(t *testing.T) {
err = mockStorage.VoteOnRule("non int", testdata.Rule1ID, testdata.ErrorKey1, testdata.OrgID, testdata.UserID, types.UserVoteNone, "")
assert.Error(t, err)
const sqliteErrMessage = "CHECK constraint failed: cluster_rule_user_feedback"
const postgresErrMessage = "pq: invalid input syntax for integer: \"non int\""
const postgresErrMessage = "pq: invalid input syntax for type integer: \"non int\""
if err.Error() != sqliteErrMessage && !strings.HasPrefix(err.Error(), postgresErrMessage) {
t.Fatalf("expected one of: \n%v\n%v\ngot:\n%v", sqliteErrMessage, postgresErrMessage, err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func TestDBStorageWriteReportForClusterExecError(t *testing.T) {
assert.Error(t, err)

const sqliteErrMessage = "CHECK constraint failed: report"
const postgresErrMessage = "pq: invalid input syntax for integer"
const postgresErrMessage = "pq: invalid input syntax for type integer"
if err.Error() != sqliteErrMessage && !strings.HasPrefix(err.Error(), postgresErrMessage) {
t.Fatalf("expected on of: \n%v\n%v\ngot:\n%v", sqliteErrMessage, postgresErrMessage, err.Error())
}
Expand Down Expand Up @@ -614,7 +614,7 @@ func TestDBStorageNewPostgresqlError(t *testing.T) {
})

err := s.Init()
assert.Contains(t, err.Error(), "no such host")
assert.Contains(t, err.Error(), "non-existing-host")
}

func mustWriteReport(
Expand Down
2 changes: 1 addition & 1 deletion unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fi
path_to_config=$(pwd)/config-devel.toml
export INSIGHTS_RESULTS_AGGREGATOR_CONFIG_FILE="$path_to_config"
export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB="postgres"
export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB_ADMIN_PASS="admin"
export INSIGHTS_RESULTS_AGGREGATOR__TESTS_DB_ADMIN_PASS="postgres"
run_unit_tests

if [ -z "$CI" ]; then
Expand Down

0 comments on commit 3af12a6

Please sign in to comment.