From 586bb9574190b5d0f3be0eb5dbb202da67bf69c9 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Thu, 25 Jan 2024 15:38:24 +0800 Subject: [PATCH] chore: add yarn berry to ci check (#1865) * chore: add yarn berry to ci check * fix: update bin link path for yarn berry * Update postinstall.js * Update postinstall.js * Update postinstall.js * Update install.yml * Update install.yml * Update install.yml * Update install.yml * Update install.yml * Update postinstall.js * Update install.yml * Update install.yml * Update install.yml * Update install.yml * Update install.yml * chore: print out binary path * chore: ls bin dir * chore: debug command * chore: copy symlink * chore: update package json for windows * chore: print updated json * chore: use exec * chore: use top level flag * chore: use path to bin * chore: test more * chore: test copy link * Update postinstall.js * Update postinstall.js * Update install.yml * Update install.yml * Update install.yml * chore: ci patches * chore: cleanup --- .github/workflows/install.yml | 25 ++++++++++++++++++++-- scripts/postinstall.js | 40 +++++++++++++---------------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 6b4682e33..aa5f72d9c 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -58,12 +58,33 @@ jobs: with: name: installer - # Berry fails to find executable on windows - # - run: yarn set version berry - run: yarn init -y - run: yarn add -D ./supabase-1.28.0.tgz - run: yarn supabase --version + yarn_berry: + needs: pack + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/download-artifact@v4 + with: + name: installer + + - run: yarn set version berry + # - run: yarn config set nodeLinker node-modules + - run: yarn init -y + - run: yarn add -D ./supabase-1.28.0.tgz + - if: ${{ matrix.os != 'windows-latest' }} + run: yarn supabase --version + # Workaround for running extensionless executable on windows + - if: ${{ matrix.os == 'windows-latest' }} + run: | + & "$(yarn bin supabase).exe" --version + pnpm: needs: pack strategy: diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 8c010f71b..bd4bb5702 100755 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -28,41 +28,21 @@ const PLATFORM_MAPPING = { }; const arch = ARCH_MAPPING[process.arch]; - const platform = PLATFORM_MAPPING[process.platform]; // TODO: import pkg from "../package.json" assert { type: "json" }; const readPackageJson = async () => { - const packageJsonPath = path.join(".", "package.json"); - const contents = await fs.promises.readFile(packageJsonPath); + const contents = await fs.promises.readFile("package.json"); return JSON.parse(contents); }; -const parsePackageJson = (packageJson) => { - if (!arch) { - throw Error( - "Installation is not supported for this architecture: " + process.arch - ); - } - - if (!platform) { - throw Error( - "Installation is not supported for this platform: " + process.platform - ); - } - - // Build the download url from package.json +// Build the download url from package.json +const getDownloadUrl = (packageJson) => { const pkgName = packageJson.name; const version = packageJson.version; const repo = packageJson.repository; const url = `https://github.com/${repo}/releases/download/v${version}/${pkgName}_${platform}_${arch}.tar.gz`; - - let binPath = path.join("bin", "supabase"); - if (platform == "windows") { - binPath += ".exe"; - } - - return { binPath, url }; + return url; }; const fetchAndParseCheckSumFile = async (packageJson, agent) => { @@ -98,6 +78,7 @@ const errGlobal = `Installing Supabase CLI as a global module is not supported. Please use one of the supported package managers: https://github.com/supabase/cli#install-the-cli `; const errChecksum = "Checksum mismatch. Downloaded data might be corrupted."; +const errUnsupported = `Installation is not supported for ${process.platform} ${process.arch}`; /** * Reads the configuration from application's package.json, @@ -113,9 +94,17 @@ async function main() { if (process.env.npm_config_global || yarnGlobal) { throw errGlobal; } + if (!arch || !platform) { + throw errUnsupported; + } const pkg = await readPackageJson(); - const { binPath, url } = parsePackageJson(pkg); + if (platform === "windows") { + // Update bin path in package.json + pkg.bin[pkg.name] += ".exe"; + } + + const binPath = pkg.bin[pkg.name]; const binDir = path.dirname(binPath); await fs.promises.mkdir(binDir, { recursive: true }); @@ -124,6 +113,7 @@ async function main() { const binName = path.basename(binPath); const untar = tar.x({ cwd: binDir }, [binName]); + const url = getDownloadUrl(pkg); console.info("Downloading", url); const proxyUrl = process.env.npm_config_https_proxy ||