|
| 1 | +# GitLab CI/CD — merge request checks |
| 2 | + |
| 3 | +workflow: |
| 4 | + rules: |
| 5 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 6 | + |
| 7 | +variables: |
| 8 | + GIT_DEPTH: "0" |
| 9 | + NODE_VERSION: "24" |
| 10 | + |
| 11 | +stages: |
| 12 | + - validate |
| 13 | + - lint |
| 14 | + - test |
| 15 | + - links |
| 16 | + |
| 17 | +default: |
| 18 | + interruptible: true |
| 19 | + |
| 20 | +.mr-only: |
| 21 | + rules: |
| 22 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 23 | + |
| 24 | +.node: |
| 25 | + image: node:${NODE_VERSION} |
| 26 | + extends: .mr-only |
| 27 | + cache: |
| 28 | + key: pnpm-root-${CI_COMMIT_REF_SLUG} |
| 29 | + paths: |
| 30 | + - node_modules/ |
| 31 | + - .pnpm-store/ |
| 32 | + before_script: |
| 33 | + - corepack enable |
| 34 | + - pnpm config set store-dir .pnpm-store |
| 35 | + - pnpm install --frozen-lockfile |
| 36 | + |
| 37 | +validate:mr-title: |
| 38 | + stage: validate |
| 39 | + image: alpine:3.20 |
| 40 | + extends: .mr-only |
| 41 | + script: |
| 42 | + - apk add --no-cache grep |
| 43 | + - | |
| 44 | + title="$CI_MERGE_REQUEST_TITLE" |
| 45 | + echo "Checking MR title: $title" |
| 46 | +
|
| 47 | + # Allow work-in-progress titles (matches amannn/action-semantic-pull-request wip: true) |
| 48 | + if echo "$title" | grep -qiE '^(wip:|\[wip\])'; then |
| 49 | + echo "WIP title — skipping validation" |
| 50 | + exit 0 |
| 51 | + fi |
| 52 | +
|
| 53 | + if ! echo "$title" | grep -qiE '^(feat|fix|docs|chore|test|refactor|ci)(\([^)]+\))?: .+'; then |
| 54 | + echo "Title must use Conventional Commits format:" |
| 55 | + echo " feat|fix|docs|chore|test|refactor|ci: description" |
| 56 | + echo " feat(scope): description" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + subject=$(echo "$title" | sed -E 's/^[^:]+: //') |
| 61 | + if echo "$subject" | grep -qE '^[A-Z]'; then |
| 62 | + echo "Subject must not start with an uppercase letter" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +
|
| 66 | +lint:eslint: |
| 67 | + stage: lint |
| 68 | + extends: .node |
| 69 | + script: |
| 70 | + - pnpm run lint:check --max-warnings=0 |
| 71 | + |
| 72 | +lint:typecheck: |
| 73 | + stage: lint |
| 74 | + extends: .node |
| 75 | + script: |
| 76 | + - pnpm run typecheck |
| 77 | + |
| 78 | +lint:format: |
| 79 | + stage: lint |
| 80 | + extends: .node |
| 81 | + script: |
| 82 | + - pnpm run format:check |
| 83 | + |
| 84 | +lint:build: |
| 85 | + stage: lint |
| 86 | + extends: .node |
| 87 | + script: |
| 88 | + - pnpm run build |
| 89 | + |
| 90 | +lint:sentence-newline: |
| 91 | + stage: lint |
| 92 | + extends: .node |
| 93 | + rules: |
| 94 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 95 | + changes: |
| 96 | + - docs/**/*.md |
| 97 | + - docs/**/*.mdx |
| 98 | + - .gitlab-ci.yml |
| 99 | + script: |
| 100 | + - | |
| 101 | + CHANGED=$(git diff --name-only --diff-filter=ACMR \ |
| 102 | + "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" "${CI_COMMIT_SHA}" \ |
| 103 | + -- 'docs/**/*.md' 'docs/**/*.mdx' || true) |
| 104 | +
|
| 105 | + if [ -z "$CHANGED" ]; then |
| 106 | + echo "No changed markdown files under docs/" |
| 107 | + exit 0 |
| 108 | + fi |
| 109 | +
|
| 110 | + echo "Linting changed files:" |
| 111 | + echo "$CHANGED" |
| 112 | + pnpm exec textlint --config .textlintrc.json $CHANGED |
| 113 | +
|
| 114 | +spell-check: |
| 115 | + stage: lint |
| 116 | + image: alpine:3.20 |
| 117 | + rules: |
| 118 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 119 | + changes: |
| 120 | + - "**/*.md" |
| 121 | + - "**/*.mdx" |
| 122 | + - .gitlab-ci.yml |
| 123 | + before_script: |
| 124 | + - apk add --no-cache curl git jq |
| 125 | + - | |
| 126 | + ARCH=$(uname -m) |
| 127 | + case "$ARCH" in |
| 128 | + x86_64) TYPOS_ARCH=x86_64 ;; |
| 129 | + aarch64) TYPOS_ARCH=aarch64 ;; |
| 130 | + *) |
| 131 | + echo "Unsupported architecture: $ARCH" |
| 132 | + exit 1 |
| 133 | + ;; |
| 134 | + esac |
| 135 | + TAG=$(curl -fsSL https://api.github.com/repos/crate-ci/typos/releases/latest | jq -r .tag_name) |
| 136 | + ASSET="typos-${TAG}-${TYPOS_ARCH}-unknown-linux-musl.tar.gz" |
| 137 | + URL=$(curl -fsSL https://api.github.com/repos/crate-ci/typos/releases/latest \ |
| 138 | + | jq -r --arg asset "$ASSET" '.assets[] | select(.name == $asset) | .browser_download_url') |
| 139 | + if [ -z "$URL" ] || [ "$URL" = "null" ]; then |
| 140 | + echo "Could not find typos release asset: $ASSET" |
| 141 | + exit 1 |
| 142 | + fi |
| 143 | + curl -fsSL "$URL" | tar -xz -C /usr/local/bin |
| 144 | + script: |
| 145 | + - | |
| 146 | + CHANGED=$(git diff --name-only --diff-filter=ACMR \ |
| 147 | + "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" "${CI_COMMIT_SHA}" \ |
| 148 | + -- '**/*.md' '**/*.mdx' || true) |
| 149 | +
|
| 150 | + if [ -z "$CHANGED" ]; then |
| 151 | + echo "No changed markdown files" |
| 152 | + exit 0 |
| 153 | + fi |
| 154 | +
|
| 155 | + echo "Spell-checking changed files:" |
| 156 | + echo "$CHANGED" |
| 157 | + typos --config ./.github/config/typos.toml $CHANGED |
| 158 | +
|
| 159 | +check:external-links: |
| 160 | + stage: links |
| 161 | + image: alpine:3.20 |
| 162 | + extends: .mr-only |
| 163 | + rules: |
| 164 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 165 | + changes: |
| 166 | + - docs/**/* |
| 167 | + - .gitlab-ci.yml |
| 168 | + cache: |
| 169 | + key: lychee-${CI_COMMIT_REF_SLUG} |
| 170 | + paths: |
| 171 | + - .lycheecache |
| 172 | + before_script: |
| 173 | + - apk add --no-cache curl git |
| 174 | + - | |
| 175 | + ARCH=$(uname -m) |
| 176 | + case "$ARCH" in |
| 177 | + x86_64) LYCHEE_ARCH=x86_64 ;; |
| 178 | + aarch64) LYCHEE_ARCH=aarch64 ;; |
| 179 | + *) |
| 180 | + echo "Unsupported architecture: $ARCH" |
| 181 | + exit 1 |
| 182 | + ;; |
| 183 | + esac |
| 184 | + LYCHEE_ASSET_DIR="lychee-${LYCHEE_ARCH}-unknown-linux-musl" |
| 185 | + curl -fsSL "https://github.com/lycheeverse/lychee/releases/latest/download/${LYCHEE_ASSET_DIR}.tar.gz" \ |
| 186 | + | tar -xz -C /usr/local/bin --strip-components=1 "${LYCHEE_ASSET_DIR}/lychee" |
| 187 | + script: |
| 188 | + - | |
| 189 | + set +e |
| 190 | + lychee --config lychee.toml docs |
| 191 | + status=$? |
| 192 | + set -e |
| 193 | +
|
| 194 | + if [ "$status" -ne 0 ]; then |
| 195 | + if [ -f lychee/out.md ]; then |
| 196 | + echo "Broken links:" |
| 197 | + cat lychee/out.md |
| 198 | + else |
| 199 | + echo "Lychee detected broken links but no report file was generated" |
| 200 | + fi |
| 201 | + exit "$status" |
| 202 | + fi |
| 203 | +
|
| 204 | +test:python-examples: |
| 205 | + stage: test |
| 206 | + image: python:3.12 |
| 207 | + rules: |
| 208 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 209 | + changes: |
| 210 | + - examples/developer-hub-python/**/* |
| 211 | + - .gitlab-ci.yml |
| 212 | + cache: |
| 213 | + key: uv-python-${CI_COMMIT_REF_SLUG} |
| 214 | + paths: |
| 215 | + - examples/developer-hub-python/.venv/ |
| 216 | + before_script: |
| 217 | + - pip install uv |
| 218 | + - cd examples/developer-hub-python |
| 219 | + - uv sync --frozen --all-extras --dev |
| 220 | + script: |
| 221 | + - uv run ruff format --diff |
| 222 | + - uv run ruff check --diff |
| 223 | + - uv run pytest -v |
| 224 | + |
| 225 | +test:javascript-examples: |
| 226 | + stage: test |
| 227 | + image: node:${NODE_VERSION} |
| 228 | + rules: |
| 229 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 230 | + changes: |
| 231 | + - examples/developer-hub-javascript/**/* |
| 232 | + - .gitlab-ci.yml |
| 233 | + cache: |
| 234 | + key: pnpm-js-${CI_COMMIT_REF_SLUG} |
| 235 | + paths: |
| 236 | + - node_modules/ |
| 237 | + - .pnpm-store/ |
| 238 | + before_script: |
| 239 | + - corepack enable |
| 240 | + - pnpm config set store-dir .pnpm-store |
| 241 | + - pnpm install --frozen-lockfile |
| 242 | + script: |
| 243 | + - pnpm --filter ./examples/developer-hub-javascript run format:check |
| 244 | + - pnpm --filter ./examples/developer-hub-javascript run lint:check |
| 245 | + - pnpm --filter ./examples/developer-hub-javascript run test |
| 246 | + |
| 247 | +test:go-examples: |
| 248 | + stage: test |
| 249 | + image: golang:1.24 |
| 250 | + rules: |
| 251 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 252 | + changes: |
| 253 | + - examples/developer-hub-go/**/* |
| 254 | + - .gitlab-ci.yml |
| 255 | + cache: |
| 256 | + key: go-${CI_COMMIT_REF_SLUG} |
| 257 | + paths: |
| 258 | + - /go/pkg/mod/ |
| 259 | + before_script: |
| 260 | + - cd examples/developer-hub-go |
| 261 | + - go mod download |
| 262 | + script: |
| 263 | + - go vet ./... |
| 264 | + - go test ./coston2 -v |
| 265 | + - go test ./flare -v |
| 266 | + |
| 267 | +test:rust-examples: |
| 268 | + stage: test |
| 269 | + image: rust:latest |
| 270 | + rules: |
| 271 | + - if: $CI_PIPELINE_SOURCE == "merge_request_event" |
| 272 | + changes: |
| 273 | + - examples/developer-hub-rust/**/* |
| 274 | + - .gitlab-ci.yml |
| 275 | + cache: |
| 276 | + key: rust-${CI_COMMIT_REF_SLUG} |
| 277 | + paths: |
| 278 | + - examples/developer-hub-rust/target/ |
| 279 | + before_script: |
| 280 | + - rustup component add rustfmt clippy |
| 281 | + - cd examples/developer-hub-rust |
| 282 | + script: |
| 283 | + - cargo fmt -- --check |
| 284 | + - cargo clippy --bins -- -D warnings |
| 285 | + - cargo build --bins --locked |
| 286 | + - ./test.sh |
0 commit comments