Skip to content

Commit

Permalink
chore: add yarn berry to ci check (#1865)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sweatybridge authored Jan 25, 2024
1 parent 2b145fc commit 586bb95
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 15 additions & 25 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -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 });

Expand All @@ -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 ||
Expand Down

0 comments on commit 586bb95

Please sign in to comment.