|
| 1 | +name: Merrymaker Go CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - "services/merrymaker-go/**" |
| 7 | + - ".github/workflows/merrymaker-go.yml" |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - "services/merrymaker-go/**" |
| 11 | + - ".github/workflows/merrymaker-go.yml" |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: mmk-go-${{ github.event.pull_request.number || github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +env: |
| 21 | + GOFLAGS: -buildvcs=false |
| 22 | + |
| 23 | +jobs: |
| 24 | + lint: |
| 25 | + name: GolangCI-Lint |
| 26 | + runs-on: ubuntu-latest |
| 27 | + defaults: |
| 28 | + run: |
| 29 | + working-directory: services/merrymaker-go |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Setup Go |
| 35 | + uses: actions/setup-go@v5 |
| 36 | + with: |
| 37 | + go-version-file: services/merrymaker-go/go.mod |
| 38 | + check-latest: true |
| 39 | + cache: true |
| 40 | + cache-dependency-path: services/merrymaker-go/go.sum |
| 41 | + |
| 42 | + - name: Run golangci-lint |
| 43 | + uses: golangci/golangci-lint-action@v6 |
| 44 | + with: |
| 45 | + version: v1.61.0 |
| 46 | + working-directory: services/merrymaker-go |
| 47 | + args: --timeout=5m |
| 48 | + |
| 49 | + gosec: |
| 50 | + name: GoSec |
| 51 | + runs-on: ubuntu-latest |
| 52 | + defaults: |
| 53 | + run: |
| 54 | + working-directory: services/merrymaker-go |
| 55 | + steps: |
| 56 | + - name: Checkout |
| 57 | + uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Setup Go |
| 60 | + uses: actions/setup-go@v5 |
| 61 | + with: |
| 62 | + go-version-file: services/merrymaker-go/go.mod |
| 63 | + check-latest: true |
| 64 | + cache: true |
| 65 | + cache-dependency-path: services/merrymaker-go/go.sum |
| 66 | + |
| 67 | + - name: Install gosec |
| 68 | + run: go install github.com/securego/gosec/v2/cmd/gosec@latest |
| 69 | + |
| 70 | + - name: Run gosec |
| 71 | + run: gosec ./... |
| 72 | + |
| 73 | + test: |
| 74 | + name: Go Tests (integration) |
| 75 | + runs-on: ubuntu-latest |
| 76 | + defaults: |
| 77 | + run: |
| 78 | + working-directory: services/merrymaker-go |
| 79 | + services: |
| 80 | + postgres: |
| 81 | + image: postgres:15 |
| 82 | + env: |
| 83 | + POSTGRES_DB: merrymaker |
| 84 | + POSTGRES_USER: merrymaker |
| 85 | + POSTGRES_PASSWORD: merrymaker |
| 86 | + ports: |
| 87 | + - 5432:5432 |
| 88 | + options: >- |
| 89 | + --health-cmd "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB" |
| 90 | + --health-interval 5s |
| 91 | + --health-timeout 5s |
| 92 | + --health-retries 10 |
| 93 | + redis: |
| 94 | + image: redis:7-alpine |
| 95 | + ports: |
| 96 | + - 6379:6379 |
| 97 | + options: >- |
| 98 | + --health-cmd "redis-cli ping" |
| 99 | + --health-interval 5s |
| 100 | + --health-timeout 5s |
| 101 | + --health-retries 10 |
| 102 | + steps: |
| 103 | + - name: Checkout |
| 104 | + uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Setup Go |
| 107 | + uses: actions/setup-go@v5 |
| 108 | + with: |
| 109 | + go-version-file: services/merrymaker-go/go.mod |
| 110 | + check-latest: true |
| 111 | + cache: true |
| 112 | + cache-dependency-path: services/merrymaker-go/go.sum |
| 113 | + |
| 114 | + - name: Install DB clients |
| 115 | + run: sudo apt-get update && sudo apt-get install -y postgresql-client redis-tools |
| 116 | + |
| 117 | + - name: Wait for Postgres |
| 118 | + run: | |
| 119 | + for i in {1..30}; do |
| 120 | + if pg_isready -h 127.0.0.1 -p 5432 -U merrymaker >/dev/null 2>&1; then |
| 121 | + exit 0 |
| 122 | + fi |
| 123 | + sleep 2 |
| 124 | + done |
| 125 | + echo "Postgres did not become ready in time" >&2 |
| 126 | + exit 1 |
| 127 | +
|
| 128 | + - name: Wait for Redis |
| 129 | + run: | |
| 130 | + for i in {1..30}; do |
| 131 | + if redis-cli -h 127.0.0.1 -p 6379 ping >/dev/null 2>&1; then |
| 132 | + exit 0 |
| 133 | + fi |
| 134 | + sleep 2 |
| 135 | + done |
| 136 | + echo "Redis did not become ready in time" >&2 |
| 137 | + exit 1 |
| 138 | +
|
| 139 | + - name: Run Go tests |
| 140 | + env: |
| 141 | + TEST_DB_HOST: 127.0.0.1 |
| 142 | + TEST_DB_PORT: "5432" |
| 143 | + TEST_DB_USER: merrymaker |
| 144 | + TEST_DB_PASSWORD: merrymaker |
| 145 | + TEST_DB_NAME: merrymaker |
| 146 | + TEST_DB_EPHEMERAL: "1" |
| 147 | + DB_SSL_MODE: disable |
| 148 | + TEST_REQUIRE_INFRA: "1" |
| 149 | + REDIS_ADDR: 127.0.0.1:6379 |
| 150 | + run: go test ./... |
| 151 | + |
| 152 | + frontend: |
| 153 | + name: Frontend Lint & Test |
| 154 | + runs-on: ubuntu-latest |
| 155 | + defaults: |
| 156 | + run: |
| 157 | + working-directory: services/merrymaker-go/frontend |
| 158 | + steps: |
| 159 | + - name: Checkout |
| 160 | + uses: actions/checkout@v4 |
| 161 | + |
| 162 | + - name: Setup Bun |
| 163 | + uses: oven-sh/setup-bun@v1 |
| 164 | + with: |
| 165 | + bun-version: "1.2.2" |
| 166 | + |
| 167 | + - name: Install dependencies |
| 168 | + run: bun install --frozen-lockfile |
| 169 | + |
| 170 | + - name: Lint frontend |
| 171 | + run: bun run lint |
| 172 | + |
| 173 | + - name: Test frontend |
| 174 | + run: bun run test |
0 commit comments