Skip to content

Commit 49dc3c8

Browse files
committed
Stash Supabase schema migration log file on GitHub workflow
1 parent 95770b7 commit 49dc3c8

1 file changed

Lines changed: 26 additions & 47 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -189,79 +189,58 @@ jobs:
189189
echo "::endgroup::"
190190
191191
echo "::group::Supabase schema snapshot"
192-
FORCE_COLOR=1 npx dotenv-cli -e test/containers/.env -- bash -c 'npx supabase db dump --local --schema "public,graphql_public,storage" --workdir suprabase' > /tmp/supabase-schema.sql
193-
head -n 200 /tmp/supabase-schema.sql || true
194-
echo "(full schema saved to /tmp/supabase-schema.sql)"
192+
schema_dir="artifacts/supabase"
193+
schema_path="${schema_dir}/schema.sql"
194+
mkdir -p "${schema_dir}"
195+
196+
FORCE_COLOR=1 npx dotenv-cli -e test/containers/.env -- bash -c 'npx supabase db dump --local --schema "public,graphql_public,storage" --workdir suprabase' > "${schema_path}"
197+
head -n 200 "${schema_path}" || true
198+
echo "(full schema saved to ${schema_path})"
195199
echo "::endgroup::"
196200
197201
echo "::group::Restart Supabase REST container"
198202
bash <<'BASH'
199203
set -euo pipefail
200204
201-
project_id=$(grep -m1 '^project_id' suprabase/config.toml | awk -F'"' '{print $2}')
202-
if [ -z "${project_id}" ]; then
203-
echo "Unable to determine Supabase project_id" >&2
204-
exit 1
205-
fi
206-
207-
sanitize() {
208-
echo "$1" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g'
209-
}
210-
211-
rest_container=""
212-
for candidate in "${project_id}" "$(sanitize "${project_id}")"; do
213-
rest_container=$(docker ps --filter "label=com.docker.compose.project=${candidate}" --format '{{.ID}} {{.Names}}' | grep -E 'rest' | head -n 1 || true)
214-
if [ -n "${rest_container}" ]; then
215-
container_id=$(echo "${rest_container}" | awk '{print $1}')
216-
container_name=$(echo "${rest_container}" | awk '{print $2}')
217-
echo "Restarting ${container_name} (${container_id}) to refresh schema cache"
218-
docker restart "${container_id}"
219-
break
220-
fi
221-
done
222-
223-
if [ -z "${rest_container}" ]; then
205+
rest_container_line=$(docker ps --format '{{.ID}} {{.Names}} {{.Image}}' | awk '$3 ~ /postgrest/ {print $1" "$2; exit}')
206+
if [ -z "${rest_container_line}" ]; then
224207
echo "Supabase REST container not found; skipping restart" >&2
208+
exit 0
225209
fi
210+
211+
container_id=$(echo "${rest_container_line}" | awk '{print $1}')
212+
container_name=$(echo "${rest_container_line}" | awk '{print $2}')
213+
echo "Restarting ${container_name} (${container_id}) to refresh schema cache"
214+
docker restart "${container_id}"
226215
BASH
227216
echo "::endgroup::"
228217
229218
echo "::group::Supabase container logs (last 200 lines)"
230219
bash <<'BASH'
231220
set -euo pipefail
232221
233-
project_id=$(grep -m1 '^project_id' suprabase/config.toml | awk -F'"' '{print $2}')
234-
if [ -z "${project_id}" ]; then
235-
echo "Unable to determine Supabase project_id" >&2
236-
exit 1
237-
fi
238-
239-
sanitize() {
240-
echo "$1" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g'
241-
}
242-
243-
containers=""
244-
for candidate in "${project_id}" "$(sanitize "${project_id}")"; do
245-
containers=$(docker ps --filter "label=com.docker.compose.project=${candidate}" --format '{{.ID}} {{.Names}}' || true)
246-
if [ -n "${containers}" ]; then
247-
break
248-
fi
249-
done
250-
222+
containers=$(docker ps --format '{{.ID}} {{.Names}} {{.Image}}' | awk '$3 ~ /supabase\// {print $1" "$2}')
251223
if [ -z "${containers}" ]; then
252224
echo "No Supabase containers found" >&2
253225
exit 0
254226
fi
255227
256-
echo "Capturing logs for project ${project_id}"
257-
echo "${containers}" | while read -r container_id container_name; do
228+
while read -r container_id container_name; do
258229
[ -z "${container_id}" ] && continue
259230
echo "--- ${container_name} (tail -n 200) ---"
260231
docker logs --tail 200 "${container_id}" || true
261-
done
232+
done <<< "${containers}"
262233
BASH
263234
echo "::endgroup::"
264235
236+
- name: Upload Supabase schema snapshot
237+
if: ${{ always() && hashFiles('artifacts/supabase/schema.sql') != '' }}
238+
uses: actions/upload-artifact@v4
239+
with:
240+
name: supabase-schema
241+
path: artifacts/supabase/schema.sql
242+
retention-days: 14
243+
265244
- name: Start Astro dev server
266245
run: |
267246
npm run dev -- --host 0.0.0.0 > /tmp/astro-dev.log 2>&1 &

0 commit comments

Comments
 (0)