github.com/oinume/lekcije@v0.0.0-20231017100347-5b4c5eb6ab24/.circleci/config.yml (about)

     1  version: 2
     2  
     3  gitconfig: &gitconfig
     4    name: "Set .gitconfig"
     5    command: |
     6      echo "" > ~/.gitconfig
     7      git config --global url."https://github.com".insteadOf git://github.com
     8      git config --global http.https://gopkg.in.followRedirects true
     9  
    10  node_modules_cache_key: &node_modules_cache_key
    11    key: node_modules-{{ checksum ".circleci/cache_version.txt" }}-{{ checksum "package.json" }}
    12  
    13  install_npm_packages: &install_npm_packages
    14    name: "Install npm packages"
    15    command: |
    16      if [ ! -e "/go/src/github.com/oinume/lekcije/node_modules" ]; then
    17        set -eu
    18        npm install
    19      fi
    20  
    21  jobs:
    22    server:
    23      working_directory: /go/src/github.com/oinume/lekcije
    24      docker:
    25        - image: golang:1.21-bullseye
    26          environment:
    27            ENABLE_TRACE: "false"
    28            GO111MODULE: "on"
    29            MYSQL_ALLOW_EMPTY_PASSWORD: true
    30            MYSQL_USER: "lekcije"
    31            MYSQL_PASSWORD: "lekcije"
    32            MYSQL_HOST: "127.0.0.1"
    33            MYSQL_PORT: "3306"
    34            MYSQL_DATABASE: "lekcije_test"
    35            MYSQL_DATABASE_TEST: "lekcije_test"
    36            E2E_WEB_DRIVER: "PhantomJS"
    37            VERSION_HASH: "_version_"
    38            NODE_ENV: "test"
    39            LEKCIJE_ENV: "test"
    40        - image: circleci/mysql:8.0
    41          command: "--default-authentication-plugin=mysql_native_password"
    42          environment:
    43            MYSQL_ALLOW_EMPTY_PASSWORD=true
    44      steps:
    45        - checkout
    46        - run:
    47            <<: *gitconfig
    48        - run:
    49            name: "Install packages"
    50            command: |
    51              set -eu
    52              apt-get update -qq
    53              apt-get install -y default-mysql-client net-tools
    54        - run:
    55            name: "Wait MySQL is up"
    56            command: |
    57              set -u
    58              timeout 10 bash -c "while ! mysqladmin ping -u ${MYSQL_USER} -h ${MYSQL_HOST} --silent; do sleep 0.5; done"
    59        - run:
    60            name: "Setup database"
    61            command: |
    62              set -eu
    63              mysql -uroot -h ${MYSQL_HOST} -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'"
    64              mysql -uroot -h ${MYSQL_HOST} -e "CREATE USER IF NOT EXISTS 'lekcije'@'%' identified by 'lekcije'"
    65              mysql -uroot -h ${MYSQL_HOST} -e "CREATE DATABASE IF NOT EXISTS lekcije_test DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci"
    66              mysql -uroot -h ${MYSQL_HOST} -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON \`lekcije\\_test%\`.* TO 'lekcije'@'%'"
    67        - run:
    68            name: "Sync go.mod"
    69            command: |
    70              cd backend
    71              make sync-go-mod-from-root
    72        - restore_cache:
    73            key: go-mod-{{ checksum ".circleci/cache_version.txt" }}-{{ checksum "go.sum" }}
    74        - save_cache:
    75            key: go-mod-{{ checksum ".circleci/cache_version.txt" }}-{{ checksum "go.sum" }}
    76            paths:
    77              - "/go/pkg/mod/cache"
    78        - restore_cache:
    79            key: go-commands-{{ checksum ".circleci/cache_version.txt" }}-{{ checksum "go.sum" }}
    80        - run:
    81            name: "Install commands"
    82            command: |
    83              cd backend
    84              if [ ! -e "/go/bin/*" ]; then
    85                make install-tools
    86              fi
    87        - save_cache:
    88            key: go-commands-{{ checksum ".circleci/cache_version.txt" }}-{{ checksum "go.sum" }}
    89            paths:
    90              - "/go/bin"
    91        - run:
    92            name: "Apply database migrations"
    93            command: |
    94              cd backend
    95              export PATH=${PATH}:/go/bin:`pwd`/tools/bin
    96              make test/db/goose/up
    97        - run:
    98            name: "Run go-test"
    99            command: |
   100              export MYSQL_USER=lekcije
   101              cd backend
   102              make go/test GO_TEST="go test -v -race -coverprofile=coverage.txt -covermode=atomic -p=1"
   103  
   104  workflows:
   105    version: 2
   106    build-workflow:
   107      jobs:
   108        - server:
   109            filters:
   110              branches:
   111                only: /.*/