#!/usr/bin/env bash # Usage: scripts/check-git-install.sh # scripts/check-git-install.sh --self-test (the lockfile check only) # # Proves the layer's distribution end to end: a scratch app installs # vue-journal-layer from git+https://git.golem15.com/golem15/vue-journal-layer.git# # anonymously, the lockfile pins the tag's commit, `nuxt build` of the layer's # playground config succeeds, and the built server passes # testing/expect-acme.txt against the fixture API. # Nothing outside a temporary directory is touched. set -euo pipefail REPO_URL="https://git.golem15.com/golem15/vue-journal-layer.git" die() { echo "check-git-install: $*" >&2; exit 1; } # lock_commits FILE prints the commits FILE pins for vue-journal-layer, one # per line: the # of its git+https entries and the commit of a # resolution whose repo is the layer's. Other git dependencies are ignored. lock_commits() { { grep -oE 'vue-journal-layer\.git#[0-9a-f]{40}' "$1" | cut -d'#' -f2 grep -oE 'commit: [0-9a-f]{40}, repo: [^,}]*/vue-journal-layer\.git' "$1" | grep -oE '[0-9a-f]{40}' } | sort -u } if [[ "${1:-}" == "--self-test" ]]; then lock="$(mktemp)" trap 'rm -f "$lock"' EXIT j=1111111111111111111111111111111111111111 s=2222222222222222222222222222222222222222 cat >"$lock" <" for tool in git pnpm node; do command -v "$tool" >/dev/null 2>&1 || die "$tool is not installed" done WORK="$(mktemp -d "${TMPDIR:-/tmp}/journal-git-install.XXXXXX")" # Nuxt applies its auto-import transform to any path with a # /vue-journal-layer/ segment (how it finds a layer inside node_modules), so a # scratch app below such a directory would transform every dependency. case "$WORK/" in */vue-journal-layer/*) rm -rf "$WORK"; die "TMPDIR must not be inside a directory named vue-journal-layer" ;; esac cleanup() { rm -rf "$WORK"; } trap cleanup EXIT # The commit the tag points at (peeled when annotated). REMOTE_REFS="$(GIT_TERMINAL_PROMPT=0 git ls-remote "$REPO_URL" "refs/tags/$TAG" "refs/tags/$TAG^{}")" \ || die "git ls-remote $REPO_URL failed" TAG_SHA="$(awk -v ref="refs/tags/$TAG^{}" '$2 == ref { print $1 }' <<<"$REMOTE_REFS")" [[ -n "$TAG_SHA" ]] || TAG_SHA="$(awk -v ref="refs/tags/$TAG" '$2 == ref { print $1 }' <<<"$REMOTE_REFS")" [[ -n "$TAG_SHA" ]] || die "tag $TAG not found on $REPO_URL" cd "$WORK" cat >package.json <pnpm-workspace.yaml <<'YAML' allowBuilds: '@parcel/watcher': true esbuild: true vue-demi: true YAML GIT_TERMINAL_PROMPT=0 pnpm install || die "pnpm install failed" # The lockfile must pin the tag's commit, not a branch. Only the # vue-journal-layer entries count: the layer's own git dependencies # (vue-seo-layer) are pinned in the same file. LOCK_SHA="$(lock_commits pnpm-lock.yaml)" [[ -n "$LOCK_SHA" ]] || die "pnpm-lock.yaml records no commit for vue-journal-layer" [[ "$(wc -l <<<"$LOCK_SHA")" -eq 1 ]] || die "pnpm-lock.yaml records more than one vue-journal-layer commit: $LOCK_SHA" [[ "$LOCK_SHA" == "$TAG_SHA" ]] || die "pnpm-lock.yaml pins $LOCK_SHA, tag $TAG is $TAG_SHA" # The scratch app is the layer's playground (its journal options, such as # the search route and one post per category page, and its app.vue with the # search box and the layout trail), which testing/expect-acme.txt is # written against, extending the installed layer instead of '..'. PLAYGROUND=node_modules/vue-journal-layer/.playground [[ -f "$PLAYGROUND/nuxt.config.ts" && -f "$PLAYGROUND/app/app.vue" ]] \ || die "the installed layer has no .playground/nuxt.config.ts and .playground/app/app.vue" sed "s#extends: \['\.\.'\]#extends: ['vue-journal-layer']#" "$PLAYGROUND/nuxt.config.ts" >nuxt.config.ts grep -q "extends: \['vue-journal-layer'\]" nuxt.config.ts || die "the playground's nuxt.config.ts does not extend '..'" mkdir -p app cp "$PLAYGROUND/app/app.vue" app/app.vue pnpm exec nuxt build || die "nuxt build failed" node node_modules/vue-journal-layer/testing/smoke-ssr.mjs \ --output .output \ --fixtures node_modules/vue-journal-layer/testing/fixtures/acme \ --expect node_modules/vue-journal-layer/testing/expect-acme.txt \ || die "SSR smoke failed" echo "check-git-install: ok $TAG $TAG_SHA"