Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ prelude.output.md

# Scratch files
*.u

# Developers can customize their own local development setup
/transcripts/fixtures/custom_projects.txt
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ reset_fixtures:
sleep 1; \
done;
@echo "Booting up share";
@( . ./local.env \
$(exe) 2>&1 & \
@( . ./local.env ; \
$(exe) & \
SERVER_PID=$$!; \
trap "kill $$SERVER_PID 2>/dev/null || true" EXIT INT TERM; \
echo "Loading fixtures"; \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ A [flake.nix](flake.nix) file is provided in this repo. It currently doesn't use
## Running Locally

The first time you run locally, start with `make reset_fixtures`, then on subsequent runs just use `make serve`.
`make reset_fixtures` will set up some basic test data in your local database, and will copy all projects from `./transcripts/fixtures/projects.txt` and `./transcripts/fixtures/custom_projects.txt` from Share into your local database.

Data changes in Postgres using `make serve` are persistent locally.
You can reset the database to a known state with `make reset_fixtures`.
Expand Down
90 changes: 46 additions & 44 deletions transcripts/fixtures/load-from-share.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
set -e
set -u

echo "This is not yet implemented"
exit 1

. "${SHARE_PROJECT_ROOT}/transcripts/transcript_functions.sh"

cache_dir="$HOME/.cache/share-api"
Expand All @@ -16,44 +13,49 @@ if [ ! -d "$cache_dir" ]; then
mkdir -p "$cache_dir"
fi

typeset -A projects
projects=(
base '@unison/base'
)

for project_name project_ref in "${(@kv)projects}"; do
echo "Downloading sync file for $project_ref"
output_file="$(mktemp)"
curl -X GET --location "https://api.unison-lang.org/ucm/v1/projects/project?name=${project_ref}" \
--header 'Content-Type: application/json' \
>"$output_file"

echo "Response for project $project_ref:"
cat "$output_file"

latest_release="$(jq -r '.payload."latest-release"' <"$output_file")"
projectId="$(jq -r '.payload."project-id"' <"$output_file")"
branch_ref="releases/${latest_release}"
project_branch_ref="${project_ref}/${branch_ref}"

curl -X GET --location "https://api.unison-lang.org/ucm/v1/projects/project-branch?projectId=${projectId}&branchName=releases/${latest_release}" \
--header 'Content-Type: application/json' \
>"$output_file"
branch_head="$(jq -r '.payload."branch-head"' <"$output_file")"

echo "Response for project branch $project_branch_ref:"
cat "$output_file"

sync_file="$cache_dir/${project_branch_ref}"

if [ -f "$sync_file" ]; then
echo "Sync file for $project_branch_ref already exists, skipping download."
continue
else
mkdir -p "$(dirname "$sync_file")"
echo "Downloading sync file for $project_branch_ref into $sync_file"
curl -X POST --location 'https://api.unison-lang.org/ucm/v2/sync/entities/download' \
--header 'Content-Type: application/json' \
--data-raw "{\"branchRef\": \"${project_branch_ref}\", \"causalHash\": \"${branch_head}\", \"knownHashes\":[]}" >"$cache_dir/${project_branch_ref}"
fi
done
main_project_list="${SHARE_PROJECT_ROOT}/transcripts/fixtures/projects.txt"
custom_project_list="${SHARE_PROJECT_ROOT}/transcripts/fixtures/custom_projects.txt"
# create the custom projects file if it doesn't exist
if [ ! -f "$custom_project_list" ]; then
touch "$custom_project_list"
fi

auth_transcript="$(mktemp).md"
pull_transcript="$(mktemp).md"
push_transcript="$(mktemp).md"

cat << EOF >"$auth_transcript"
\`\`\`ucm
scratch/main> auth.login
\`\`\`
EOF

while IFS= read -r line; do
read -r project_source project_dest <<< "$line"
# Annoyingly clone will fail if it's already been cloned, but succeed otherwise, so we just add a bad command to
# force the block to always fail so we can use the :error directive.
cat << EOF
\`\`\`ucm:error
scratch/main> clone ${project_source}
scratch/main> force-failure
\`\`\`

EOF
done < <(cat "$main_project_list" "$custom_project_list") >"$pull_transcript"

while IFS= read -r line; do
read -r project_source project_dest <<< "$line"
cat << EOF
\`\`\`ucm
${project_source}> push ${project_dest}
\`\`\`

EOF
done < <(cat "$main_project_list" "$custom_project_list") >"$push_transcript"

echo "📫 Downloading projects from Share"
UNISON_SHARE_HOST="https://api.unison-lang.org" ucm -C "${cache_dir}/code-cache" transcript.in-place "$pull_transcript"
echo "🔑 Authenticating with local server..."
UNISON_SHARE_HOST="http://localhost:5424" ucm -c "${cache_dir}/code-cache" transcript.in-place "$auth_transcript"
echo "📦 Pushing projects to local server..."
UNISON_SHARE_HOST="http://localhost:5424" ucm -c "${cache_dir}/code-cache" transcript.in-place "$push_transcript"
1 change: 1 addition & 0 deletions transcripts/fixtures/projects.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@unison/base/releases/4.8.0 @test/base/main
2 changes: 2 additions & 0 deletions transcripts/fixtures/run.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ source "${SHARE_PROJECT_ROOT}/transcripts/transcript_functions.sh"
# Set up database so helper scripts know it's a local db
pg_file "${SHARE_PROJECT_ROOT}/transcripts/sql/configure_local_database.sql"
pg_init_fixtures

source "${SHARE_PROJECT_ROOT}/transcripts/fixtures/load-from-share.sh"
Loading