github.com/crowdsecurity/crowdsec@v1.6.1/.github/workflows/go-tests.yml (about)

     1  ---
     2  # This workflow is actually running
     3  # tests (with localstack) but the
     4  # name is used for the badge in README.md
     5  
     6  name: Build
     7  
     8  on:
     9    push:
    10      branches:
    11        - master
    12        - releases/**
    13      paths-ignore:
    14        - 'README.md'
    15    pull_request:
    16      branches:
    17        - master
    18        - releases/**
    19      paths-ignore:
    20        - 'README.md'
    21  
    22  # these env variables are for localstack, so we can emulate aws services
    23  env:
    24    RICHGO_FORCE_COLOR: 1
    25    AWS_HOST: localstack
    26    # these are to mimic aws config
    27    AWS_ACCESS_KEY_ID: test
    28    AWS_SECRET_ACCESS_KEY: test
    29    AWS_REGION: us-east-1
    30    CROWDSEC_FEATURE_DISABLE_HTTP_RETRY_BACKOFF: true
    31  
    32  jobs:
    33    build:
    34      name: "Build + tests"
    35      runs-on: ubuntu-latest
    36      services:
    37        localstack:
    38          image: localstack/localstack:3.0
    39          ports:
    40          - 4566:4566  # Localstack exposes all services on the same port
    41          env:
    42            DEBUG: ""
    43            LAMBDA_EXECUTOR: ""
    44            KINESIS_ERROR_PROBABILITY: ""
    45            DOCKER_HOST: unix:///var/run/docker.sock
    46            KINESIS_INITIALIZE_STREAMS: ${{ env.KINESIS_INITIALIZE_STREAMS }}
    47            LOCALSTACK_HOST: ${{ env.AWS_HOST }}  # Required so that resource urls are provided properly
    48            # e.g sqs url will get localhost if we don't set this env to map our service
    49          options: >-
    50            --name=localstack
    51            --health-cmd="curl -sS 127.0.0.1:4566 || exit 1"
    52            --health-interval=10s
    53            --health-timeout=5s
    54            --health-retries=3
    55        zoo1:
    56          image: confluentinc/cp-zookeeper:7.4.3
    57          ports:
    58            - "2181:2181"
    59          env:
    60            ZOOKEEPER_CLIENT_PORT: 2181
    61            ZOOKEEPER_SERVER_ID: 1
    62            ZOOKEEPER_SERVERS: zoo1:2888:3888
    63          options: >-
    64            --name=zoo1
    65            --health-cmd "jps -l | grep zookeeper"
    66            --health-interval 10s
    67            --health-timeout 5s
    68            --health-retries 5
    69  
    70        kafka1:
    71          image: crowdsecurity/kafka-ssl
    72          ports:
    73            - "9093:9093"
    74            - "9092:9092"
    75            - "9999:9999"
    76          env:
    77            KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://127.0.0.1:19092,LISTENER_DOCKER_EXTERNAL://127.0.0.1:9092,LISTENER_DOCKER_EXTERNAL_SSL://127.0.0.1:9093
    78            KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL_SSL:SSL
    79            KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
    80            KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
    81            KAFKA_BROKER_ID: 1
    82            KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
    83            KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
    84            KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
    85            KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
    86            KAFKA_JMX_PORT: 9999
    87            KAFKA_JMX_HOSTNAME: "127.0.0.1"
    88            KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer
    89            KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
    90            KAFKA_SSL_KEYSTORE_FILENAME: kafka.kafka1.keystore.jks
    91            KAFKA_SSL_KEYSTORE_CREDENTIALS: kafka1_keystore_creds
    92            KAFKA_SSL_KEY_CREDENTIALS: kafka1_sslkey_creds
    93            KAFKA_SSL_TRUSTSTORE_FILENAME: kafka.kafka1.truststore.jks
    94            KAFKA_SSL_TRUSTSTORE_CREDENTIALS: kafka1_truststore_creds
    95            KAFKA_SSL_ENABLED_PROTOCOLS: TLSv1.2
    96            KAFKA_SSL_PROTOCOL: TLSv1.2
    97            KAFKA_SSL_CLIENT_AUTH: none
    98            KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
    99          options: >-
   100            --name=kafka1
   101            --health-cmd "kafka-broker-api-versions --version"
   102            --health-interval 10s
   103            --health-timeout 10s
   104            --health-retries 5
   105  
   106        loki:
   107          image: grafana/loki:2.9.1
   108          ports:
   109            - "3100:3100"
   110          options: >-
   111            --name=loki1
   112            --health-cmd "wget -q -O - http://localhost:3100/ready | grep 'ready'"
   113            --health-interval 30s
   114            --health-timeout 10s
   115            --health-retries 5
   116            --health-start-period 30s
   117  
   118      steps:
   119  
   120      - name: Check out CrowdSec repository
   121        uses: actions/checkout@v4
   122        with:
   123          fetch-depth: 0
   124          submodules: false
   125  
   126      - name: "Set up Go"
   127        uses: actions/setup-go@v5
   128        with:
   129          go-version: "1.21.9"
   130  
   131      - name: Create localstack streams
   132        run: |
   133            aws --endpoint-url=http://127.0.0.1:4566 --region us-east-1 kinesis create-stream --stream-name stream-1-shard --shard-count 1
   134            aws --endpoint-url=http://127.0.0.1:4566 --region us-east-1 kinesis create-stream --stream-name stream-2-shards --shard-count 2
   135  
   136      - name: Build and run tests, static
   137        run: |
   138          sudo apt -qq -y -o=Dpkg::Use-Pty=0 install build-essential libre2-dev
   139          go install github.com/ory/go-acc@v0.2.8
   140          go install github.com/kyoh86/richgo@v0.3.10
   141          set -o pipefail
   142          make build BUILD_STATIC=1
   143          make go-acc | sed 's/ *coverage:.*of statements in.*//' | richgo testfilter
   144  
   145      - name: Run tests again, dynamic
   146        run: |
   147          make clean build
   148          set -o pipefail
   149          make go-acc | sed 's/ *coverage:.*of statements in.*//' | richgo testfilter
   150  
   151      - name: Upload unit coverage to Codecov
   152        uses: codecov/codecov-action@v4
   153        with:
   154          files: coverage.out
   155          flags: unit-linux
   156  
   157      - name: golangci-lint
   158        uses: golangci/golangci-lint-action@v4
   159        with:
   160          version: v1.57
   161          args: --issues-exit-code=1 --timeout 10m
   162          only-new-issues: false
   163          # the cache is already managed above, enabling it here
   164          # gives errors when extracting
   165          skip-pkg-cache: true
   166          skip-build-cache: true