topfreegames/khan

View on GitHub
.github/workflows/go.yml

Summary

Maintainability
Test Coverage
---
name: Khan
'on': push
jobs:
  tests:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:9.5
        env:
          POSTGRES_HOST_AUTH_METHOD: trust
          POSTGRES_USER: khan_test
          POSTGRES_DB: khan_test
        ports:
          - '5433:5432'
        options: '--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5'
      redis:
        image: redis:4
        options: '--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5'
        ports:
          - '50505:6379'
    steps:
      - id: go-cache-paths
        run: |
          echo "::set-output name=go-build::$(go env GOCACHE)"
          echo "::set-output name=go-mod::$(go env GOMODCACHE)"
      - name: Start MongoDB
        uses: supercharge/mongodb-github-action@1.3.0
        with:
          mongodb-version: 4.2.11
      - uses: getong/elasticsearch-action@v1.2
        with:
          elasticsearch version: 7.6.1
          host port: 9200
          container port: 9200
          host node port: 9300
          node port: 9300
          discovery type: single-node
      - uses: actions/checkout@v2
      - name: Go Build Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

      # Cache go mod cache, used to speedup builds
      - name: Go Mod Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-mod }}
          key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.2
      - name: Setup ci
        run: make setup-ci
      - name: Test
        run: make schema-update assets migrate-test run-test coverage
      - name: Install goveralls
        env:
          GO111MODULE: off
        run: go get github.com/mattn/goveralls
      - name: Send coverage
        env:
          COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: goveralls -coverprofile coverage-all.out -service=github
  performance:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:9.5
        env:
          POSTGRES_HOST_AUTH_METHOD: trust
          POSTGRES_USER: khan_perf
          POSTGRES_DB: khan_perf
        ports:
          - '5433:5432'
        options: '--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5'
      redis:
        image: redis:4
        options: '--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5'
        ports:
          - '50505:6379'
    steps:
      - id: go-cache-paths
        run: |
          echo "::set-output name=go-build::$(go env GOCACHE)"
          echo "::set-output name=go-mod::$(go env GOMODCACHE)"
      - uses: actions/checkout@v2
      - name: Go Build Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
      # Cache go mod cache, used to speedup builds
      - name: Go Mod Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-mod }}
          key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.2
      - name: Setup ci
        run: make setup-ci
      - name: Start MongoDB
        uses: supercharge/mongodb-github-action@1.3.0
        with:
          mongodb-version: 4.2.11
      - uses: getong/elasticsearch-action@v1.2
        with:
          elasticsearch version: 7.6.1
          host port: 9200
          container port: 9200
          host node port: 9300
          node port: 9300
          discovery type: single-node
      - name: Performance test
        run: make ci-perf
  build_and_deploy_khan:
    needs:
      - tests
      - performance
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    steps:
      - id: go-cache-paths
        run: |
          echo "::set-output name=go-build::$(go env GOCACHE)"
          echo "::set-output name=go-mod::$(go env GOMODCACHE)"
      - uses: actions/checkout@v2
      - name: Set env
        run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
      - name: Go Build Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
      # Cache go mod cache, used to speedup builds
      - name: Go Mod Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-mod }}
          key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.2
      - name: Generate executable
        run: make setup-ci cross
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
      - name: Build and push tag
        id: docker_build_tag
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile
          push: true
          tags: tfgco/khan:${{ env.VERSION }}
      - name: Build and push latest
        id: docker_build_latest
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile
          push: true
          tags: tfgco/khan:latest
  build_and_deploy_khan_dev:
    runs-on: ubuntu-latest
    needs:
      - tests
      - performance
    steps:
      - id: go-cache-paths
        run: |
          echo "::set-output name=go-build::$(go env GOCACHE)"
          echo "::set-output name=go-mod::$(go env GOMODCACHE)"
      - uses: actions/checkout@v2
      - name: Set env
        run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
      - name: Go Build Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
      # Cache go mod cache, used to speedup builds
      - name: Go Mod Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-mod }}
          key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.2
      - name: Generate executable
        run: make setup-ci cross
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Copy necessary files
        run: cp ./config/default.yaml ./dev
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
      - name: Build and push tag
        id: docker_build_tag
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile
          push: true
          tags: tfgco/khan-dev:${{ env.VERSION }}
      - name: Build and push latest
        id: docker_build_latest
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile
          push: true
          tags: tfgco/khan-dev:latest
  build_and_deploy_khan_prune:
    needs:
      - tests
      - performance
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    steps:
      - id: go-cache-paths
        run: |
          echo "::set-output name=go-build::$(go env GOCACHE)"
          echo "::set-output name=go-mod::$(go env GOMODCACHE)"
      - uses: actions/checkout@v2
      - name: Set env
        run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
      - name: Go Build Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
      # Cache go mod cache, used to speedup builds
      - name: Go Mod Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-mod }}
          key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.15.2
      - name: Generate executable
        run: make setup-ci cross
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
      - name: Build and push tag
        id: docker_build_tag
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./PruneDockerfile
          push: true
          tags: tfgco/khan-prune:${{ env.VERSION }}
      - name: Build and push latest
        id: docker_build_latest
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./PruneDockerfile
          push: true
          tags: tfgco/khan-prune:latest