Repository navigation
193 lines (168 loc) · 8.13 KB
/
Copy pathhypercerts-api.yml
File metadata and controls
193 lines (168 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: CI
on:
pull_request:
paths:
- "**"
- ".github/workflows/hypercerts-api.yml"
push:
branches: [main, dev]
paths:
- "**"
- ".github/workflows/hypercerts-api.yml"
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
checks:
name: API validation and build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: leafo/gh-actions-lua@6919171ccf181b826f44b9bca76307b577217377 # v13.0.0
with:
luaVersion: "5.4"
- name: Add Lua 5.4 executable alias
run: |
lua_bin="$(command -v lua)"
ln -s "$lua_bin" "${lua_bin%/*}/lua5.4"
lua5.4 -e 'assert(_VERSION == "Lua 5.4", "expected Lua 5.4")'
- uses: leafo/gh-actions-luarocks@35d062def313a7699a0d513e996bcf4352f05389 # v6.1.0
- name: Install Luacheck
run: luarocks install luacheck 1.2.0
# Reads the pnpm version from the packageManager field in package.json.
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install Node dependencies
run: pnpm install --frozen-lockfile
- name: Validate Changesets when present
if: github.event_name == 'pull_request'
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
changeset_files="$(git diff --name-only --diff-filter=ACMR "$BASE_SHA...$HEAD_SHA" -- '.changeset/*.md' ':!.changeset/README.md')"
if [ -n "$changeset_files" ]; then
pnpm exec changeset status --since "$BASE_SHA"
fi
- name: Check API and explorer tests
run: pnpm check
- name: Build API Lua bundles and explorer
run: pnpm build
- name: Check the packed @hypercerts-org/api in a clean consumer
run: pnpm --filter @hypercerts-org/api run check:package
runtime-contracts:
name: HTTP tests (HappyView + PostgreSQL)
runs-on: ubuntu-latest
timeout-minutes: 50
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: leafo/gh-actions-lua@6919171ccf181b826f44b9bca76307b577217377 # v13.0.0
with:
luaVersion: "5.4"
- name: Add Lua 5.4 executable alias
run: |
lua_bin="$(command -v lua)"
ln -s "$lua_bin" "${lua_bin%/*}/lua5.4"
lua5.4 -e 'assert(_VERSION == "Lua 5.4", "expected Lua 5.4")'
# Reads the pnpm version from the packageManager field in package.json.
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install Node dependencies
run: pnpm install --frozen-lockfile
- name: Install PostgreSQL client
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install --yes postgresql-client
psql_path="$(command -v psql)"
test -x "$psql_path"
printf 'PSQL_PATH=%s\n' "$psql_path" >> "$GITHUB_ENV"
- name: Pull pinned HTTP test images
timeout-minutes: 10
run: |
docker pull postgres:17.6-alpine@sha256:ef257d85f76e48da1c64832459b59fcaba1a4dac97bf5d7450c77753542eee94
docker pull ghcr.io/gamesgamesgamesgamesgames/happyview:2.13.0@sha256:df44f5c7275e16cd6755b75c37e089fb22b24361f7084d1dc66f07d9c5667e64
- name: Run task-isolated HTTP suites
timeout-minutes: 20
run: pnpm test:http
- name: Remove any remaining task-owned HTTP services
if: always()
timeout-minutes: 5
run: |
set -euo pipefail
project="${HYPERCERTS_HTTP_TEST_COMPOSE_PROJECT:-}"
env_file="${HYPERCERTS_HTTP_TEST_COMPOSE_ENV_FILE:-}"
if [[ -z "$project" || -z "$env_file" ]]; then
echo "No task-owned HTTP Compose project was registered."
exit 0
fi
if [[ ! "$project" =~ ^hypercerts-http-[0-9]+-[a-f0-9]+$ ]]; then
echo "Refusing cleanup for unexpected Compose project name: $project" >&2
exit 1
fi
if [[ ! -f "$env_file" || -L "$env_file" ]]; then
containers="$(docker ps --all --quiet --filter "label=com.docker.compose.project=$project")"
networks="$(docker network ls --quiet --filter "label=com.docker.compose.project=$project")"
volumes="$(docker volume ls --quiet --filter "label=com.docker.compose.project=$project")"
if [[ -n "$containers$networks$volumes" ]]; then
printf 'Refusing cleanup because credentials are unavailable and project %s still has resources: containers=[%s] networks=[%s] volumes=[%s]\n' "$project" "${containers//$'\n'/ }" "${networks//$'\n'/ }" "${volumes//$'\n'/ }" >&2
exit 1
fi
echo "Task-owned Compose credentials are unavailable, but project $project has no labeled containers, networks, or volumes."
exit 0
fi
runner_temp="$(realpath "$RUNNER_TEMP")"
env_file="$(realpath "$env_file")"
case "$env_file" in
"$runner_temp"/hypercerts-http-*/compose.env) ;;
*) echo "Refusing cleanup for credentials outside RUNNER_TEMP: $env_file" >&2; exit 1 ;;
esac
compose_file="$(realpath "$GITHUB_WORKSPACE/happyview-modules/docker-compose.contracts.yml")"
compose=(docker compose --project-name "$project" --env-file "$env_file" --project-directory "$GITHUB_WORKSPACE/happyview-modules" -f "$compose_file")
container_ids="$("${compose[@]}" ps --all --quiet)"
while IFS= read -r id; do
[[ -n "$id" ]] || continue
project_label="$(docker inspect --format '{{ index .Config.Labels "com.docker.compose.project" }}' "$id")"
service_label="$(docker inspect --format '{{ index .Config.Labels "com.docker.compose.service" }}' "$id")"
config_files="$(docker inspect --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}' "$id")"
case ",$config_files," in *,"$compose_file",*) ;; *) echo "Refusing cleanup of container with unrelated Compose config: $id" >&2; exit 1 ;; esac
if [[ "$project_label" != "$project" || "$service_label" != postgres && "$service_label" != happyview ]]; then
echo "Refusing cleanup of container not owned by this HTTP test project: $id" >&2
exit 1
fi
done <<< "$container_ids"
network_ids="$(docker network ls --quiet --filter "label=com.docker.compose.project=$project")"
while IFS= read -r id; do
[[ -n "$id" ]] || continue
network_project="$(docker network inspect --format '{{ index .Labels "com.docker.compose.project" }}' "$id")"
[[ "$network_project" == "$project" ]] || { echo "Refusing cleanup of unrelated network: $id" >&2; exit 1; }
done <<< "$network_ids"
volume_ids="$(docker volume ls --quiet --filter "label=com.docker.compose.project=$project")"
while IFS= read -r id; do
[[ -n "$id" ]] || continue
volume_project="$(docker volume inspect --format '{{ index .Labels "com.docker.compose.project" }}' "$id")"
[[ "$volume_project" == "$project" ]] || { echo "Refusing cleanup of unrelated volume: $id" >&2; exit 1; }
done <<< "$volume_ids"
if [[ -n "$container_ids$network_ids$volume_ids" ]]; then
"${compose[@]}" down --volumes --timeout 10
fi
env_dir="${env_file%/compose.env}"
rm -f "$env_file"
rmdir "$env_dir"