Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Use isomorphic-git instead of tiged when cloning examples #998

Closed
wants to merge 17 commits into from
Closed
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
2 changes: 0 additions & 2 deletions .github/workflows/reusable-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ jobs:
- name: Test
run: pnpm test:user
env:
LAYERZERO_EXAMPLES_REPOSITORY_URL: https://github.com/${{ github.repository }}.git
LAYERZERO_EXAMPLES_REPOSITORY_REF: ${{ github.ref }}
# We'll use the prebuilt base image
DEVTOOLS_BASE_IMAGE: ghcr.io/layerzero-labs/devtools-dev-base:main
# And the prebuilt hardhat EVM node image
Expand Down
51 changes: 50 additions & 1 deletion docker-compose.registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,48 @@ services:
# This step can remain after the above step has been removed and the cloning logic updated
pnpm release:version
pnpm release:publish

# Now we commit changes to a local git repository
#
# First we setup the git user
git config --global user.email "[email protected]"
git config --global user.name "Devtools Bot"

# Since we don't want to be bringing the repository state (i.e. the .git directory)
# to this image, we'll initialize a repository in the container
git init -b main

# And finally we commit the results
git add -A
git commit --allow-empty -q -m "🚀 Version packages"
volumes:
# We'll need to provide the changeset files for this step
- ./.changeset:/app/.changeset
# We'll also bring the .gitignore in since we don't want to be committing the files we normally ignore
- ./.gitignore:/app/.gitignore
# We'll provide a volume for examples so that we can share them
# with the tests
#
# This is done because the dependencies in examples might change
# after we apply the changesets & publish the local packages
- repository:/app

# ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~
#
# Serves local git repository
#
# .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.
github:
image: rockstorm/git-server:2.45
depends_on:
publish:
condition: service_completed_successfully
ports:
- "2222:22"
environment:
GIT_PASSWORD: devtools
volumes:
- repository:/srv/git/devtools

# ~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~
#
Expand All @@ -98,6 +137,8 @@ services:
args:
BASE_IMAGE: ${DEVTOOLS_BASE_IMAGE:-base}
depends_on:
github:
condition: service_started
publish:
condition: service_completed_successfully
# create-lz-oapp allows us to specify the repository/ref we pull the examples from
Expand All @@ -108,7 +149,7 @@ services:
# If these are not provided, for example if running on a local machine,
# we'll default them to our repository and empty ref
environment:
- LAYERZERO_EXAMPLES_REPOSITORY_URL=${LAYERZERO_EXAMPLES_REPOSITORY_URL}
- LAYERZERO_EXAMPLES_REPOSITORY_URL=${LAYERZERO_EXAMPLES_REPOSITORY_URL:-ssh://git@localhost:2222/srv/git/devtools.git}
- LAYERZERO_EXAMPLES_REPOSITORY_REF=${LAYERZERO_EXAMPLES_REPOSITORY_REF}
working_dir: /app
command:
Expand All @@ -125,13 +166,21 @@ services:
echo "create-lz-oapp:repository $${LAYERZERO_EXAMPLES_REPOSITORY_URL}"
echo "create-lz-oapp:ref $${LAYERZERO_EXAMPLES_REPOSITORY_REF}"

# Now we need to authenticate to the local repository
# FIXME We gott pass the password using sshpass
# ssh git@github -p 2222 -y

# Now we run the user tests
/app/tests-user/lib/bats-core/bin/bats --verbose-run --recursive ./tests-user/tests
volumes:
- repository:/srv/repository
# If we want to clone from github.com, we'll need its public keys added to our SSH config
# otherwise git clone would trigger an interactive prompt asking us to add a server fingerprint
#
# See more here https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
- ./tests-user/ssh/known_hosts:/root/.ssh/known_hosts
# The testing library and test suites
- ./tests-user:/app/tests-user

volumes:
repository:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"registry:logs": "docker compose -f docker-compose.registry.yaml logs -f",
"registry:publish": "docker compose -f docker-compose.registry.yaml run --build --rm $DOCKER_COMPOSE_ARGS publish",
"registry:start": "docker compose -f docker-compose.registry.yaml up npm-registry --wait $DOCKER_COMPOSE_ARGS",
"registry:stop": "docker compose -f docker-compose.registry.yaml down",
"registry:stop": "docker compose -f docker-compose.registry.yaml down --volumes",
"release:publish": "$npm_execpath changeset publish",
"release:version": "$npm_execpath changeset version && $npm_execpath install --lockfile-only --prefer-offline --ignore-scripts",
"start": "docker compose -f docker-compose.yaml -f docker-compose.local.yaml up network-britney network-vengaboys network-tango network-ton --wait $DOCKER_COMPOSE_ARGS",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-lz-oapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lint": "$npm_execpath eslint '**/*.{js,ts,json}'",
"lint:fix": "eslint --fix '**/*.{js,ts,json}'",
"start": "./cli.js",
"test": "jest --ci"
"test": "jest --ci --passWithNoTests"
},
"dependencies": {
"yoga-layout-prebuilt": "^1.10.0"
Expand All @@ -48,10 +48,10 @@
"ink-select-input": "^4.2.2",
"ink-spinner": "^4.0.3",
"ink-text-input": "^4.0.3",
"isomorphic-git": "~1.27.1",
"jest": "^29.7.0",
"prompts": "^2.4.2",
"react": "^17.0.2",
"tiged": "^2.12.6",
"ts-node": "^10.9.2",
"tsup": "~8.0.1",
"typescript": "^5.4.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-lz-oapp/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isPackageManagerAvailable } from './utilities/installation'
* To enable example development in a custom repository
* we open the repository URL field to be taken from the environment
*/
const repository = process.env['LAYERZERO_EXAMPLES_REPOSITORY_URL'] || 'https://github.com/LayerZero-Labs/devtools.git'
const repository = process.env.LAYERZERO_EXAMPLES_REPOSITORY_URL || 'https://github.com/LayerZero-Labs/devtools.git'

/**
* To enable example development in a custom branch,
Expand All @@ -14,7 +14,7 @@ const repository = process.env['LAYERZERO_EXAMPLES_REPOSITORY_URL'] || 'https://
* `LAYERZERO_EXAMPLES_REPOSITORY_REF` can then be set to something like `#develop` or `#my-custom-branch`
* to take the examples from a tag, a branch or a commit hash
*/
const ref = process.env['LAYERZERO_EXAMPLES_REPOSITORY_REF'] || ''
const ref = process.env.LAYERZERO_EXAMPLES_REPOSITORY_REF || ''

export const EXAMPLES: Example[] = [
{
Expand Down
73 changes: 40 additions & 33 deletions packages/create-lz-oapp/src/utilities/cloning.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
import { Config, Example } from '@/types'
import { Config } from '@/types'
import { createModuleLogger } from '@layerzerolabs/io-devtools'
import { rm } from 'fs/promises'
import { resolve } from 'path'
import tiged from 'tiged'

/**
* Helper function to satisfy the `tiged` repository URL specification
*
* @param example `Example`
* @returns `string` Repository URL compatible with `tiged`
*/
export const createExampleGitURL = (example: Example): string => {
return [
example.repository,
example.directory ? '/' + example.directory.replace(/^\//, '') : undefined,
example.ref ? '#' + example.ref.replace(/^#/, '') : undefined,
]
.filter(Boolean)
.join('')
}
import { mkdtemp, rm } from 'fs/promises'
import { join, resolve } from 'path'
import { clone } from 'isomorphic-git'
import http from 'isomorphic-git/http/node'
import fs from 'fs/promises'

export const cloneExample = async ({ example, destination }: Config) => {
const logger = createModuleLogger('cloning')
logger.verbose(`Cloning example ${example.label} from ${example.repository} to ${destination}`)

const url = createExampleGitURL(example)
logger.verbose(`Cloning example from ${url} to ${destination}`)

const emitter = tiged(url, {
disableCache: true,
mode: 'git',
verbose: true,
})
logger.verbose(`Creating temporary directory for cloning`)
const dir = await mkdtemp('devtools-')
logger.verbose(`Created temporary directory for cloning in ${dir}`)

try {
// First we clone the whole proejct
await emitter.clone(destination)
logger.verbose(`Cloning ${example.repository} to temporary directory ${dir}`)

// First we clone the whole thing into a temporary directory
await clone({
url: example.repository,
ref: example.ref,
dir,
fs,
http,
depth: 1,
})

const exampleDir = example.directory ? join(dir, example.directory) : dir
logger.verbose(`Copying example code from ${exampleDir} to ${destination}`)

// Then we copy the example subdirectory into the destination
await fs.rename(exampleDir, resolve(destination))

logger.verbose(`Copied example code from ${exampleDir} to ${destination}`)

logger.verbose(`Cloned example from ${url} to ${destination}`)
logger.verbose(`Cleaning up`)

// Then we cleanup what we don't want to be included
Expand All @@ -45,8 +43,10 @@ export const cloneExample = async ({ example, destination }: Config) => {
try {
// Let's make sure to clean up after us
await rm(destination, { recursive: true, force: true })
} catch {
// If the cleanup fails let's just do nothing for now
} catch (error) {
logger.warn(
`Failed to clean up destination directory ${destination} after a failed cloning attempt: ${error}`
)
}

if (error instanceof Error && 'code' in error) {
Expand All @@ -73,6 +73,13 @@ export const cloneExample = async ({ example, destination }: Config) => {
}

throw new CloningError(`Unknown error: ${error}`)
} finally {
try {
// We need to clean up the temporary directory
rm(dir, { recursive: true, force: true })
} catch (error) {
logger.verbose(`Failed to clean up temporary directory ${dir}: ${error}`)
}
}
}

Expand Down
47 changes: 0 additions & 47 deletions packages/create-lz-oapp/test/utilities/cloning.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/create-lz-oapp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": "dist",
"declaration": false,
"declarationMap": false,
"jsx": "react",
"lib": ["dom", "dom.Iterable", "es2022"],
"resolveJsonModule": true,
Expand All @@ -11,6 +12,5 @@
"@/*": ["./src/*"]
}
},
"files": ["./types/tiged.d.ts"],
"include": ["src", "test", "types"]
}
20 changes: 0 additions & 20 deletions packages/create-lz-oapp/types/tiged.d.ts

This file was deleted.

Loading