130 lines
4.2 KiB
YAML
130 lines
4.2 KiB
YAML
# Reusable Node service CI — install, migrate, test against job sidecars.
|
|
#
|
|
# Do NOT use workflow services: for RabbitMQ on this runner — the broker fails
|
|
# health before steps run. Sidecars via start-job-sidecars.sh (Docker socket).
|
|
# See CICD/platform/observed-state.md.
|
|
#
|
|
# Caller (after this file is tagged in infra/ci-workflows@v1):
|
|
# jobs:
|
|
# api-service:
|
|
# uses: infra/ci-workflows/.gitea/workflows/node-service-ci.yml@v1
|
|
# with:
|
|
# working_directory: api-service
|
|
# migrate_command: npm run migrate
|
|
# test_command: npm test -- --runInBand --forceExit
|
|
# sidecars_script: scripts/start-job-sidecars.sh
|
|
name: node-service-ci
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
runs_on:
|
|
type: string
|
|
default: ubuntu-latest
|
|
working_directory:
|
|
description: "Directory holding package.json, relative to the repo root."
|
|
type: string
|
|
required: true
|
|
node_version:
|
|
# Matches node-ci.yml. Pin this explicitly in every caller — a shared
|
|
# default that moves is a silent toolchain change across projects.
|
|
type: string
|
|
default: "22"
|
|
package_manager:
|
|
type: string
|
|
default: npm
|
|
lock_file:
|
|
type: string
|
|
default: package-lock.json
|
|
install_command:
|
|
type: string
|
|
default: ""
|
|
migrate_command:
|
|
description: "Shell run after sidecars are up (working_directory)."
|
|
type: string
|
|
default: ""
|
|
test_command:
|
|
description: "Shell run after migrate (working_directory)."
|
|
type: string
|
|
default: "npm test -- --runInBand --forceExit"
|
|
sidecars_script:
|
|
description: "Path from repo root to start-job-sidecars.sh (copy from the CICD kit)."
|
|
type: string
|
|
default: "scripts/start-job-sidecars.sh"
|
|
database_url_var:
|
|
description: "Env var name for the Postgres URL written by the sidecar script."
|
|
type: string
|
|
default: DATABASE_URL
|
|
amqp_url_var:
|
|
type: string
|
|
default: AMQP_URL
|
|
redis_url_var:
|
|
type: string
|
|
default: REDIS_URL
|
|
postgres_db:
|
|
type: string
|
|
default: app_test
|
|
test_env:
|
|
description: "Optional KEY=VALUE lines exported for migrate and test."
|
|
type: string
|
|
default: ""
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ${{ inputs.runs_on }}
|
|
steps:
|
|
- uses: builtin:checkout
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ inputs.node_version }}
|
|
cache: ${{ inputs.package_manager }}
|
|
cache-dependency-path: ${{ inputs.working_directory }}/${{ inputs.lock_file }}
|
|
|
|
- name: Start job sidecars
|
|
env:
|
|
CI_PG_DB: ${{ inputs.postgres_db }}
|
|
CI_DATABASE_URL_VAR: ${{ inputs.database_url_var }}
|
|
CI_AMQP_URL_VAR: ${{ inputs.amqp_url_var }}
|
|
CI_REDIS_URL_VAR: ${{ inputs.redis_url_var }}
|
|
run: bash ${{ inputs.sidecars_script }}
|
|
|
|
- name: Install
|
|
working-directory: ${{ inputs.working_directory }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -n "${{ inputs.install_command }}" ]; then
|
|
${{ inputs.install_command }}
|
|
elif [ "${{ inputs.package_manager }}" = "pnpm" ]; then
|
|
corepack enable && pnpm install --frozen-lockfile
|
|
else
|
|
npm ci
|
|
fi
|
|
|
|
- name: Migrate
|
|
if: inputs.migrate_command != ''
|
|
working-directory: ${{ inputs.working_directory }}
|
|
run: |
|
|
set -euo pipefail
|
|
while IFS= read -r line; do
|
|
[ -n "$line" ] || continue
|
|
export "${line?}"
|
|
done <<< "${{ inputs.test_env }}"
|
|
${{ inputs.migrate_command }}
|
|
|
|
- name: Test
|
|
working-directory: ${{ inputs.working_directory }}
|
|
run: |
|
|
set -euo pipefail
|
|
while IFS= read -r line; do
|
|
[ -n "$line" ] || continue
|
|
export "${line?}"
|
|
done <<< "${{ inputs.test_env }}"
|
|
${{ inputs.test_command }}
|
|
|
|
- name: Stop job sidecars
|
|
if: always()
|
|
run: |
|
|
docker rm -f "${CI_PG_NAME:-}" "${CI_RMQ_NAME:-}" "${CI_REDIS_NAME:-}" 2>/dev/null || true
|