From 0773c6e9f3315b2ba25c0d7ab63c165fc5ac5d15 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 6 Dec 2019 16:49:30 +0100 Subject: [PATCH] Add github actions CI flow --- .github/workflows/.editorconfig | 2 + .github/workflows/ci.yml | 77 +++++++++++++++++++++++++++++++++ storage/sql/config_test.go | 25 +++++++++++ storage/sql/postgres_test.go | 13 ++++++ 4 files changed, 117 insertions(+) create mode 100644 .github/workflows/.editorconfig create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/.editorconfig b/.github/workflows/.editorconfig new file mode 100644 index 00000000..7bd3346f --- /dev/null +++ b/.github/workflows/.editorconfig @@ -0,0 +1,2 @@ +[*.yml] +indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..827b0214 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + build: + name: Build + runs-on: ubuntu-16.04 + env: + GOFLAGS: -mod=readonly + + services: + postgres: + image: postgres:10.8 + ports: + - 5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + etcd: + image: gcr.io/etcd-development/etcd:v3.2.9 + ports: + - 2379 + env: + ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379 + ETCD_ADVERTISE_CLIENT_URLS: http://0.0.0.0:2379 + options: --health-cmd "ETCDCTL_API=3 etcdctl --endpoints http://localhost:2379 endpoint health" --health-interval 10s --health-timeout 5s --health-retries 5 + + keystone: + image: openio/openstack-keystone:pike + ports: + - 5000 + - 35357 + options: --health-cmd "curl --fail http://localhost:5000/v3" --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.13 + + - name: Checkout code + uses: actions/checkout@v1 + + - name: Setup MySQL database + run: mysql -u root -proot -e 'CREATE DATABASE dex;' + + - name: Run tests + run: make testall + env: + DEX_MYSQL_DATABASE: dex + DEX_MYSQL_USER: root + DEX_MYSQL_PASSWORD: root + DEX_MYSQL_HOST: 127.0.0.1 + DEX_MYSQL_PORT: 3306 + DEX_POSTGRES_DATABASE: postgres + DEX_POSTGRES_USER: postgres + DEX_POSTGRES_PASSWORD: postgres + DEX_POSTGRES_HOST: localhost + DEX_POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} + DEX_ETCD_ENDPOINTS: http://localhost:${{ job.services.etcd.ports[2379] }} + # TODO: enable + DEX_LDAP_TESTS: 0 + DEX_KEYSTONE_URL: http://localhost:${{ job.services.keystone.ports[5000] }} + DEX_KEYSTONE_ADMIN_URL: http://localhost:${{ job.services.keystone.ports[35357] }} + DEX_KEYSTONE_ADMIN_USER: demo + DEX_KEYSTONE_ADMIN_PASS: DEMO_PASS + + #- name: Run Kubernetes tests + # run: ./scripts/test-k8s.sh + + # Ensure proto generation doesn't depend on external packages. + - name: Verify proto + run: make verify-proto diff --git a/storage/sql/config_test.go b/storage/sql/config_test.go index b71b2eef..b3694cc3 100644 --- a/storage/sql/config_test.go +++ b/storage/sql/config_test.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "runtime" + "strconv" "testing" "time" @@ -220,12 +221,24 @@ func TestPostgres(t *testing.T) { if host == "" { t.Skipf("test environment variable %q not set, skipping", testPostgresEnv) } + + port := uint64(5432) + if rawPort := os.Getenv("DEX_POSTGRES_PORT"); rawPort != "" { + var err error + + port, err = strconv.ParseUint(rawPort, 10, 32) + if err != nil { + t.Fatalf("invalid postgres port %q: %s", rawPort, err) + } + } + p := &Postgres{ NetworkDB: NetworkDB{ Database: getenv("DEX_POSTGRES_DATABASE", "postgres"), User: getenv("DEX_POSTGRES_USER", "postgres"), Password: getenv("DEX_POSTGRES_PASSWORD", "postgres"), Host: host, + Port: uint16(port), ConnectionTimeout: 5, }, SSL: SSL{ @@ -242,12 +255,24 @@ func TestMySQL(t *testing.T) { if host == "" { t.Skipf("test environment variable %q not set, skipping", testMySQLEnv) } + + port := uint64(3306) + if rawPort := os.Getenv("DEX_MYSQL_PORT"); rawPort != "" { + var err error + + port, err = strconv.ParseUint(rawPort, 10, 32) + if err != nil { + t.Fatalf("invalid mysql port %q: %s", rawPort, err) + } + } + s := &MySQL{ NetworkDB: NetworkDB{ Database: getenv("DEX_MYSQL_DATABASE", "mysql"), User: getenv("DEX_MYSQL_USER", "mysql"), Password: getenv("DEX_MYSQL_PASSWORD", ""), Host: host, + Port: uint16(port), ConnectionTimeout: 5, }, SSL: SSL{ diff --git a/storage/sql/postgres_test.go b/storage/sql/postgres_test.go index adf91927..8071dc29 100644 --- a/storage/sql/postgres_test.go +++ b/storage/sql/postgres_test.go @@ -4,6 +4,7 @@ package sql import ( "os" + "strconv" "testing" ) @@ -12,12 +13,24 @@ func TestPostgresTunables(t *testing.T) { if host == "" { t.Skipf("test environment variable %q not set, skipping", testPostgresEnv) } + + port := uint64(5432) + if rawPort := os.Getenv("DEX_POSTGRES_PORT"); rawPort != "" { + var err error + + port, err = strconv.ParseUint(rawPort, 10, 32) + if err != nil { + t.Fatalf("invalid postgres port %q: %s", rawPort, err) + } + } + baseCfg := &Postgres{ NetworkDB: NetworkDB{ Database: getenv("DEX_POSTGRES_DATABASE", "postgres"), User: getenv("DEX_POSTGRES_USER", "postgres"), Password: getenv("DEX_POSTGRES_PASSWORD", "postgres"), Host: host, + Port: uint16(port), }, SSL: SSL{ Mode: pgSSLDisable, // Postgres container doesn't support SSL.